• mission idea "Climbing Route"

Question related to mission Climbing Route

 

I love grid-mission. Perhaps you would as well :)

I prepared a new mission "Climbing Route".

description :

The map is given as a list of strings.

  • 0 : plain
  • 1-9 : hill (number is elevation)
  • "mountain" is adjacent hill group.

Start is top-left. Goal is bottom-right. You have to cross all mountain peaks. You can move vertical and horizontal. But you can only move to 1 elevation difference. You should look for the shortest route. (return Number of steps)

Precondition :

mountain peak means only the highest one.

code & test :

def climbing_route(terrain):
    return min-steps

if __name__ == '__main__':
    assert climbing_route([
        '0000',
        '0210',
        '0000']) == 7, 'basic'
    assert climbing_route([
        '00000',
        '03440',
        '03650',
        '02210',
        '00000']) == 26, 'spiral'
    assert climbing_route([
        '000000001',
        '222232222',
        '100000000']) == 26, 'bridge'
    assert climbing_route([
        '000000001210',
        '011100002320',
        '012100001210',
        '011100000000']) == 16, 'two top'
    assert climbing_route([
        '00000000000000',
        '01212321234320',
        '00000000000000']) == 21, 'one top'
    assert climbing_route([
        '00000000000000000000000000',
        '00000000000111111100000000',
        '00000000000122222100000000',
        '00000000000123332100000000',
        '00000000000123432100000000',
        '00000000000123332100000000',
        '00000000000122222100000000',
        '00000000000111111100000000',
        '00000000000000000000000000',
        '00000111110000000000000000',
        '00000122210000000000000000',
        '00000123210000000000000000',
        '00000122210000000011223110',
        '00000111110000000000000000',
        '01110000000000000000000000',
        '01210000000000000000000000',
        '01110000000000000000000000',
        '00000000000000000000000000']) == 70, 'pyramids'