Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading