The status of an alarm is shown in this array.
Time format is as follows HH:MM:SS
[["red", "00:00:00"],
["orange", "00:00:02"],
["green", "00:00:05"],
["red", "00:00:07"],
["green", "00:00:27"],
["red", "00:00:28"],
["green", "00:00:29"]]
I would like to count the number of times "red" is followed by "green" within a time period of 10 seconds.
Step 1: Look for red
Step 2: IF Not last item
Compare with next item on array
ELSE Go to Step 4
Step 3: IF green,
time_difference = green_time - red_time
IF time_difference <= 10 seconds
count = count + 1
Go to Step 1
ELSE Go to Step 1
ELSE Go to Step 2
Step 4: Print Count
The count should be 2
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…