Crossing the road blindly

  • 8
Let's say that we are certain that at the beginning of every hour our traffic light is green for 3 minutes, yellow for a minute, and then red for another minute. Then the sequence repeats. Our program must determine what light is on now (where "now" is a real number that indicates the number of minutes that have elapsed since the beginning of the hour).
You can't complete this task, because you're not signed in.
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Cz FerenczLevel 7 , Bucharest
25 November 2019, 20:41
After almost 2 hours of work in, i made it. :) With a bit of help from the help comments. Good luck to everyone. :)
Shoaib UmerLevel 18 , Bristol
17 November 2019, 23:18
Ny solution is working as per given conditions but not accepted. Plz point out my mistake.
RomanLevel 41
18 November 2019, 06:21
Please use the Help section for questions relating to tasks.
MecoSLevel 12
19 September 2019, 17:22
My solution is a bit verbouse but run and response the correct light.. I didn't understand why is not accepted. Sorry for my english...
RomanLevel 41
15 October 2019, 05:32
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at
Carlos CortázarLevel 14 , Madrid
23 August 2019, 15:34
My program Solution runs for all the cases, but when i press Verify the program says not verified. Anyone can figure out why?
AlexLevel 41
24 August 2019, 13:15
Please check this in the Help section. Don't forget to attach your code with the question.
Michael BreyLevel 6 , Dresden
13 October 2019, 18:03
Hello Carlos, your solution is absolutely smart and perfect. I did not find any better way to do the task, especially with such a concise and transparent logic. Thank you!! On the other hand, I also do not understand, why the code does not validate. :-(
MBCLevel 13 , Apeldoorn
13 June 2019, 17:51
Does anyone know why we have to declare the variable t with 5.0 as a modulus operation? I have looked the modulus operator up online and understand that it gives the remainder, but I do not get how that relates to the hour and minutes passing from t?
GCPixLevel 15 , Glasgow
17 June 2019, 11:49
It doesn't have anything to do with hours. The lights cycle in a 5 minute block, the first 3 minutes are green, minute 4 is yellow and minute 5 is red. At that point it goes back to the start. Because this adds to 5, and the time runs 0-1 minutes, 1-2, 2-3,3-4,4-5 then modulus 5 will always reduce the numbers to the same sequence. If that makes any sense?
MBCLevel 13 , Apeldoorn
17 June 2019, 13:54
Yes it does make sense now, I think I didn't identify the 5 minute cycle for all of the lights, that's why.
Nitin rajLevel 12 , Mumbai
11 June 2019, 16:09
#guyzz help me out . #above code gives task condition not met
RomanLevel 41
12 June 2019, 05:31
Please submit your code for review in the Help section.
SajanaLevel 8 , Dearborn
11 June 2019, 04:56
Consider only the integer portion of the 'Double' value while performing MOD.
AhmedLevel 20 , Amsterdam
13 May 2019, 09:19
Guys, don't overthink the problem. You don't have to right all the numbers! Just study the (remainder or Modulus Operator in Java) and you will fix this problem really easily!
KIN SOCHEATLevel 19 , Phnom Penh
13 May 2019, 07:23
Thanks resolved
Deji OlarinoyeLevel 12 , Lagos
11 May 2019, 20:08
Modulo Arithmetic -Best solved using recursion.