Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating time from numbers

Tags:

java

algorithm

I have numbers as x,y,z, and w. I am trying to create max possible time in 24 hours format. Example:

My approach is to sort the all numbers. Then for hours check the number less than equal 2, then for next digit in hour, check number less then equal to 4, and so on for minutes also. (0-60 minutes)

Is any other efficient approach than bruteforce solution?

like image 892
User007 Avatar asked Jan 25 '17 21:01

User007


People also ask

What is a time generator?

A time base generator (also timebase or time base) is a special type of function generator, an electronic circuit that generates a varying voltage to produce a particular waveform.

How do I generate a random time between ranges in Excel?

Type this formula: =TEXT(RAND()*(8:45-7)/24+6/24,"HH:MM:SS") into a blank cell, and drag the fill handle over to the range that you want to insert the time.

How does Srand time work?

The srand(x) function sets the seed of the random number generator algorithm used by the function rand( ). A seed value of 1 is the default setting yielding the same sequence of values as if srand(x) were not used. Any other value for the seed produces a different sequence. srand(time(NULL));


1 Answers

Simple approach would be to create all possible combinations of all the number from four digits. Then sort and pick out all the values less than 2359 (Max time allowed). After this you start with the max number and just validate if it is a correct time if not check the next biggest number.

like image 196
StackFlowed Avatar answered Sep 30 '22 10:09

StackFlowed