I don't understand what t % 5 actually does and why this seems to then mean the higher numbers are then covered.
Daniel Whyte
Level 17
t % 5
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Dinesh
8 January 2021, 12:06useful
% modulus operator return remainder
5%2 = 1
3%2 = 1
12 %2 = 0
and
1 hours = 60 minutes
as the condition says the traffic light works on hourly basis that will be
GREEN for first 3 minutes
YELLOW for next 1 minute.
and RED for next 1 minute.
This cycle will move on up to 60 minutes.
here t = time of the task that is from (1 to 60 minutes) .
Now moving to Second part of your question
why this seems to then mean the higher numbers are then covered?
Before answering that
Try one thing yourself as I suggest
try to find out modulus of each minute from (1to 60) minutes by 5 as follows
1%5
2%5
3%5
4%5
5%5
.........and so on move upto 55%5, 56%5,....60%5
and observe the output.
See if you can get the answer of your second part. Just Try at least once.
+1