Re:Google Blockly - a visual programming language
by grakic on Thursday May 31, 2012 @05:40PM
(#4050521)
Can this program be made any shorter? http://www.dodaj.rs/f/1K/vW/2gLz63rl/blockly.png
[ Parent
| on HN ]
Re:Google Blockly - a visual programming language
by xarien on Friday June 01, 2012 @02:04AM
(#4052185)
http://imgur.com/Nvy8u
Here's one with same amount of code and optimal logic (for this map) without hard coding. It also ensures that there is a forward step in every iteration of the while loop.
Basically it's just an order of preference:
Turn right > turn left > go straight
Re:Google Blockly - a visual programming language
by JoshTriplett on Thursday May 31, 2012 @05:52PM
(#4050587)
An "else" would help; you can add one by hitting the + symbol on the if. With the else, you can get the shortest program that'll solve the maze (transcribing using approximate notation in lieu of a screenshot):
while True:
if wall(AHEAD):
turn(LEFT)
else:
move(FORWARD)
turn(RIGHT)
However, the addition of one more if makes the solution much faster and look more sensible, by not turning to the right and immediately back to the left: while True:
if wall(AHEAD):
turn(LEFT)
else:
move(FORWARD)
if not wall(RIGHT):
turn(RIGHT)
Re:Google Blockly - a visual programming language
by bockris on Thursday May 31, 2012 @06:03PM
(#4050635)
You can add an 'else' clause to the 'if' block by clicking the '+' which launches a sub-editor.
Re:Google Blockly - a visual programming language
by WiseWeasel on Thursday May 31, 2012 @07:21PM
(#4050968)
Here's one that runs the fastest through this particular maze (I noticed there's always a wall on the right side when we need to make a left turn):
Re:Google Blockly - a visual programming language
by WiseWeasel on Thursday May 31, 2012 @08:29PM
(#4051218)
And a much shorter and dumber version that does the same thing:
Re:Google Blockly - a visual programming language
by jules on Thursday May 31, 2012 @06:10PM
(#4050669)
http://i.imgur.com/HTvOx.png
Edit: I didn't know that an else was possible, so I had to do it this way.
Re:Google Blockly - a visual programming language
by radarsat1 on Thursday May 31, 2012 @06:15PM
(#4050687)
Weird, that looks like you're manipulating blocks of text with the mouse. How is that a "visual programming language"? It just seems to be a fancy text editor.
Re:Google Blockly - a visual programming language
by eigenbom on Thursday May 31, 2012 @06:25PM
(#4050734)
It visually represents the grammar of the language with the jigsaw patterns of the keywords, and prohibits connecting bad sequences, etc.
Re:Google Blockly - a visual programming language
by true_religion on Thursday May 31, 2012 @08:42PM
(#4051267)
Not the fastest but its just about as short as yours (counting all blocks as one): http://cdn-images.9cloud.us/716/best-solution-kay_1568014138...
Re:Google Blockly - a visual programming language
by _sentient on Thursday May 31, 2012 @09:38PM
(#4051454)
I would blur out those browser favorites, if I were you.
Re:Google Blockly - a visual programming language
by tinyjoe on Friday June 01, 2012 @01:31AM
(#4052116)
indeed
Re:Google Blockly - a visual programming language
by ZeroGravitas on Thursday May 31, 2012 @07:08PM
(#4050917)
Looping left, forward, right, forward works for this particular maze, though it can get caught in potential corners types.
Re:Google Blockly - a visual programming language
by emp_ on Thursday May 31, 2012 @05:54PM
(#4050596)
http://i.imgur.com/ct17R.png it takes a while, but gets there.
Re:Google Blockly - a visual programming language
by cnlwsu on Thursday May 31, 2012 @06:15PM
(#4050683)
takes awhile... hard to tell whats "shorter"
while !wall(AHEAD):
move forward
turn left
while wall(AHEAD):
turn right
Re:Google Blockly - a visual programming language
by saurik on Friday June 01, 2012 @03:22AM
(#4052371)
If you started off facing a wall your code would just not do anything. You can both simplify it and fix this bug by reorganizing the loop.
while true:
turn left
while wall(AHEAD):
turn right
move forward
However, while this algorithm happens to work on this maze, it will not work against other mazes (if you care).Imagine a 5x5 square race track, with spokes coming from the outside of the wheel to the center, where there was a flag. Your algorithm (and my modified one) would just spin clockwise around the track without ever realizing it should take a right towards the center.