There is a helicopter flying 500 meters from the ground. It can fly up 100 meters, which takes 1.0 secs. Or if it doesn't fly up it will fall 200 meters, which also takes 1.0 secs - This means if the instruction is anything other than "Fly" the helicopter falls. Build a program that takes input of a list of instructions, telling the helicopter when to fly and when not to. When the helicopter falls it should output the time counter.
INPUT:
Fly Dance Fly Golf Fly Fly
OUTPUT:
8.5 secs
Walkthrough:
1) Fly == Fly so +100 = 600m
2) Dance != Fly so -200 = 400m
3) Fly == Fly so +100 = 500m
4) Golf != Fly so -200m = 300m
5) Fly == Fly so +100 = 400m
6) Fly == Fly so +100 = 500m
7) NO INSTRUCTIONS so -200 = 300m
8) NO INSTRUCTIONS so -200 = 100m
9) NO INSTRUCTIONS so -100 = 0m (This takes 0.5 seconds)
Each instruction should be separated by a space, and if the instuction isn't fly, then automatically fall. When the program runs out of instructions automatically fall. Your program must output in (float)secs, and if it takes => 60.0 seconds display in mins and seconds eg. 1 mins 32.0 secs
Seconds are float decimal values, minutes are whole interger values. Also note capitalization does not matter your program should work for capitals or no capitals.
This is code-golf so the least NO bytes wins!
if it dosen't fly up, it will fall 200m
does that mean heli can crash and after crashing it should not fly anymore which means rest of the instructions should be ignored? Example : please tell me output if the input is this :fly fall fall fall fall fly fly fly fly
\$\endgroup\$ – Mukul Kumar Nov 15 '16 at 19:26"M min S secs"
specifically, or are normal output formats like a list of[M,S]
and other reasonable formats like"M:S"
OK? If specifically, then can less than one minute output"0 min S secs"
? \$\endgroup\$ – Jonathan Allan Nov 15 '16 at 19:53