Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)


You can add an 'else' clause to the 'if' block by clicking the '+' which launches a sub-editor.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: