How to reduce steps / line of code for this puzzle in python?

Question:

Puzzle
Video Puzzle

Current Code:

for i in range(4):
    Dev.step(i+4)
    for a in range(3):
        Dev.step(i+2) 
        Dev.turnLeft()
    Dev.step(i+2)       

From the puzzle it has to be 5 line of code. Currently I’am at 6 line of code. How do I make the code simpler ?.

The objective is to get all the Item (blue cylinder).

Asked By: rfl

||

Answers:

If you can’t use semicolons, you can combine the Dev.step(i+4) and Dev.step(i+2) into a single line and changing the sequence of Dev.turnleft() and Dev.step() in the inner loop, so your resulting 5 line solution would something like –

for i in range(4):
    Dev.step(2*i+6)
    for a in range(3):
        Dev.turnLeft()
        Dev.step(i+2)
Answered By: Jay
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.