Crossing the road blindly

  • 3
  • unavailable
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.
Comments(34)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Shoaib UmerLevel 4 , Bristol
day before yesterday, 23:18
Ny solution is working as per given conditions but not accepted. Plz point out my mistake.
RomanLevel 41
yesterday, 06:21
Please use the Help section for questions relating to tasks.
MecoSLevel 7
19 September, 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, 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 codegym.cc/help.
Carlos CortázarLevel 13 , Madrid
23 August, 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, 13:15
Please check this in the Help section. Don't forget to attach your code with the question.
Michael BreyLevel 5 , Dresden
13 October, 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, 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 14 , Glasgow
17 June, 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, 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, 16:09
#guyzz help me out . #above code gives task condition not met
RomanLevel 41
12 June, 05:31
Please submit your code for review in the Help section.
SajanaLevel 8 , Dearborn
11 June, 04:56
Consider only the integer portion of the 'Double' value while performing MOD.
AhmedLevel 19 , Amsterdam
13 May, 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, 07:23
Thanks resolved
Deji OlarinoyeLevel 12 , Lagos
11 May, 20:08
Modulo Arithmetic -Best solved using recursion.
KIN SOCHEATLevel 19 , Phnom Penh
11 May, 13:09
I test this code the result is ok. but it still not pass. someone can tell why? BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String slight = reader.readLine(); double t = Double.parseDouble(slight); if (0 <t && t<=60){ if (t == 4 || t == 8 || t == 12 || t == 16 | t == 20 || t == 24 || t == 28 || t == 32 || t == 36 || t == 40 || t == 44 || t == 48 || t == 52 || t == 56 || t == 60){ System.out.println("red"); }else if (t == 3 || t == 7 || t == 11 || t == 15 || t == 19 || t == 23 || t == 27 || t== 31 || t == 35 || t == 39 || t == 43 || t == 47 || t == 51 || t == 55 || t == 59){ System.out.println("yellow"); } else System.out.println("green"); }else System.out.println("not Correct number"); } }
RomanLevel 41
13 May, 06:04
Please submit your code for review in the Help section. p.s. t can be more than 60 ...