Show HN: Parachuting robots – a programming puzzle
david-peter.de
david-peter.de
start: left
skipNext
goto start
fast: left
goto fast
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.Using inefficiency to solve problems, I'm not surprised.
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.
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.
:)
The best set for making it as fast as possible within the bounds of the javascript parser.
Also great implementation and beautiful site.
Though, IMHO there could be a button named "parse & run", my eyes have missed a "parse" button, and I thought that something was broken.
I see, the disabled play button in the beginning is not optimal. Replacing "parse" with "parse & run" is an interesting option. I'm not sure yet, how it would affect the other buttons, though. I somehow like the debugging-style "Step" feature. Would it be better to have the example program parsed already such that "Play" is enabled on page load?
Also somehow I am used to "build" (instead of "parse") terminology, so my eyes just have not caught "parse" keyword. Though, I guess here nothing is built, only parsed. ;)
All in all some information, about parsing before running would add extra points to the UX.
Spoiler!
start: left
skipNext
goto start
speedup: left
goto speedupThis is one case where I am glad that I did not read HN comments before solving. My solution is the same as moftz and other left leaners. :) First iteration I made the speed be four times the slow robot but of course double speed is fine.
2 labels, and 5 statements
Also "loop" is not a good label. They are both loops.
Took me ages to realise the twist though, because I was somehow set on making them oscillate further on every iteration and couldn't understand how I was to remember how far I went without a stack.
Basically what I wanted to do was: x left, if its not there, return. Next time x * 2 left, return to base if its not there, ...
Much appreciated entertainment on a lazy friday at work :)
start: left left right skipNext goto start continue: left goto continue
start: left skipNext goto start continue: left goto continue
might not gain any appreciable speedup.Suggestion: Add ability to share the code.
(and even that could be done in two as well as I see now)
I guess my interview wouldn't go that well :)
[0] https://gist.github.com/kanche/92c92c5e926ebc66da68
To watch them run around is so cool! Cool puzzle. Nicely created site. I am trying to give them a pendulum like swing instruction right now, make them dance :P
edit: had two unnecessary instruction in the gist (because each instruction takes same amount of time to execute), and, the robots disappointed me- they can't dance
The solution with a "speeding label" is the only solution I see. I also recognize the parallel with infinite loop detection now, like sugarcube commented already: https://news.ycombinator.com/item?id=10477109
left
left
left
left
left
left
left
r: right
skipNext
goto rEdit: randomize button. I see. It also makes this no solution because they could start anywhere.
left x 6 # but that should probably be 7? as maxRange in the randomize routine is 8.
scan: skipNext
right
goto scan
Which works but only because the unit test is deficient!That's as far as I got in 5 mins [but I'm not a coder].
walk:right
skipNext
goto walk
run:right
goto runClue - You will need to use both "left" and "right" movement.
hell:left left goto hell
Then you should get something that is equivalent to boolfuck (1-bit brainfuck) which is Turing complete.