Re:Show HN: Parachuting robots – a programming puzzle
by moftz on Friday October 30, 2015 @07:35AM
(#10477210)
Here's my best implementation:
Red and Blue must take three cycles to move one space until Blue hits Red's parachute. Then, Red take three cycles to move one space while Blue takes two cycles to move one space where Blue then catches Red shortly after.
[ Parent
| on HN ]
Re:Show HN: Parachuting robots – a programming puzzle
by nyan4 on Friday October 30, 2015 @08:10AM
(#10477318)
"It seems to originate from a Microsoft interview question."
Using inefficiency to solve problems, I'm not surprised.
Re:Show HN: Parachuting robots – a programming puzzle
by iconjack on Friday October 30, 2015 @11:47AM
(#10478513)
This problem was posed to me for real in a Microsoft interview in the late 90s. At first I was like "How hard could this be?" but quickly discovered that it wasn't so obvious. If I hadn't already seen the famous circular-list detection method, there's no way I would've gotten it, not during the interview at least.
Re:Show HN: Parachuting robots – a programming puzzle
by nothis on Friday October 30, 2015 @08:54AM
(#10477475)
Ha! That's what I thought. It's a duct-taping solution.
Re:Show HN: Parachuting robots – a programming puzzle
by verroq on Friday October 30, 2015 @08:57AM
(#10477486)
Here is how I did it
start: left
skipNext
goto start
goto double
double: left
left
goto double
The idea comes from the "find a loop in a singlely linked list in O(1) space" problem.One pointer moves twice as fast the as the other one.
Re:Show HN: Parachuting robots – a programming puzzle
by kanche on Friday October 30, 2015 @09:24AM
(#10477597)
You don't need the 'goto double' line, execution is anyway going skip to 'double: left' making the line redundant
Also say each step takes one unit of time, so one 'start' loop requires 3 units to go one unit of distance, whereas 'double' takes 3 units to go 2 units of distance, even if you use one left statement in the 'double' loop, robot will still move faster than the other as it will require only two units of time to go one unit of distance.
:)
Re:Show HN: Parachuting robots – a programming puzzle
by jack9 on Friday October 30, 2015 @04:55PM
(#10480495)
slow: left
skipNext
goto slow
fast: left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
left
goto fast
The best set for making it as fast as possible within the bounds of the javascript parser.