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

Time:11-25

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).

CodePudding user response:

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)
  • Related