ICode国际青少年编程竞赛- Python-6级训练场-多重递归

ICode国际青少年编程竞赛- Python-6级训练场-多重递归

1、

在这里插入图片描述

def move(a, b):
    if a > 12:
        return
    Dev.step(a)
    Dev.turnRight()
    if b < 4:
        move(a, b+1)
    else:
        move(a+2, 1)
move(2, 1)

2、

在这里插入图片描述

def move(a, b):
    if a < 2:
        return
    if b == 1: Spaceship.step(2)
    Dev.step(a)
    Dev.turnRight()
    Dev.step(a)
    if b < 4:
        move(a, b+1)
    else:
        move(a-2, 1)
move(6, 1)

3、
在这里插入图片描述

def move(a, b):
    if b == 0:
        return
    Dev.step(a)
    if a > 0:
        Dev.turnRight()
    elif a != 0:
        Dev.turnLeft()
    Dev.step(a)
    if a > 1:
        Dev.turnLeft()
    elif a != 0 and a != 1: 
        Dev.turnRight()
    if a > b: 
        move(a-1, b)
    else:
        move(-a-1, b+1)
move(4, -4)

4、
在这里插入图片描述

def move(a, b):
    if b < 3: return
    if a > 0:
        if a == b: 
            Dev.step(a)
        Dev.step(a)
        if a > 1: 
            Dev.turnRight()
        move(a-1, b)
    elif a < 1 and a > -b:
        Dev.step(a-1)
        Dev.turnLeft()
        move(a-1, b)
    else:
        Dev.step(a-1)
        Dev.turnRight()
        a = b - 1
        b = a
        move(a, b)
move(5, 5)

5、

在这里插入图片描述

def move(a, b):
    if b > 4:
        return
    if a == 5: 
        Dev.step(b)
    if a >= 2:
        Dev.step(a)
        if a > 2: 
            Dev.turnRight()
        if a == 2: 
            a = -1
        move(a-1, b)
    elif a >= -5:
        Dev.step(a)
        if a != -5: 
            Dev.turnLeft()
        move(a-1, b)
    else:
        Dev.step(-b)
        Dev.turnLeft()
        move(5, b+1)
move(5, 1)

6、
在这里插入图片描述

def move(a):
    Dev.step(a)
    Dev.turnLeft()
    Dev.step(a-1)
    Dev.step(1-a)
    Dev.turnRight()
    Dev.step(-a)
    Spaceship.step()
    Spaceship.turnLeft()
    Spaceship.step()
    Spaceship.turnRight()
    Spaceship.step()
    if a < 5: 
        move(a+1)
Dev.step()
move(2)

7、
在这里插入图片描述

def move(a, b):
    if b == 0: 
        Dev.step(5)
    Dev.step(a)
    Dev.turnRight()
    if b < 2: 
        move(a, b+1)
    if b == 2:
        Dev.step(a-5)
        Dev.turnRight()
        if a < 4: 
            move(a+1, 0)
move(2, 0)

8、
在这里插入图片描述

def move(a, b):
    if a == 0:
        Spaceship.step(4)
        Spaceship.turnRight()
        Dev.step()
    Dev.step(2)
    Dev.turnRight()
    
    if a < 3: 
        move(a+1, b)
    
    if a == 3:
        Dev.step(-1)
        Spaceship.step(4)
        Spaceship.turnLeft()
        if b < 2: 
            move(0, b+1)

Dev.turnLeft()
move(0, 0)

9、

在这里插入图片描述

def move(a, b):
    if b == 0:
        Spaceship.step(5)
        Spaceship.turnRight()
        Spaceship.step()
        Dev.turnRight()
        Dev.step()
    Dev.step(3)
    Dev.turnRight()
    if b < 3: 
        move(a, b+1)
    if b == 3:
        Dev.step(-1)
        Spaceship.turnRight()
        Spaceship.turnRight()
        Spaceship.step()
        Spaceship.turnLeft()
        Spaceship.step(5)
        Spaceship.turnLeft()
        if a < 3: 
            move(a+1, 0)
move(0, 0)

10、

在这里插入图片描述

def move(a, b, c):
    if (b-a) == 2: 
    	Dev.step(a)
    Dev.step(b)
    if c == 0: 
    	Dev.turnRight()
    if c == 1 and b < a + 1: 
    	Dev.turnLeft()
    if c == 0 and b > 1: 
    	move(a, b-1, 0)
    if c == 1 and b < a + 1: 
    	move(a, b+1, 1)
    if c == 0 and b == 1:
        Dev.turnRight()
        move(a, b, 1)
    if c == 1 and b == a + 1 and a > 0:
        move(a-1, b, 0)
move(4, 6, 0)

11、
在这里插入图片描述

def move(a, b, c):
    if a == 0: 
    	Dev.step(2)
    Dev.step(b)
    if b == 2: 
    	Dev.turnLeft()
    if b == 4: 
    	Dev.turnRight()
    if b < 4 and a < 2: 
    	move(0, b+2, 0)
    if b < 4 and a == 2: 
    	move(0, b+2, 1)
    if a < 2: 
    	move(a+1, b, c)
    if c == 0 and a == 2 and b == 4:
        Dev.step(b)
        Dev.turnLeft()
        Dev.step(2)
    if c == 1 and a == 2 and b == 4: 
    	Dev.step(b-1)
move(0, 2, 0)

12、

在这里插入图片描述

def move(a, b, c):
    if a == 0: Dev.step(-3)
    Dev.step(-b)
    Dev.turnLeft()
    if b > 2 and a < 2: 
    	move(0, b-2, 0)
    if b > 2 and a == 2: 
    	move(0, b-2, 1)
    if a < 2: 
    	move(a+1, b, c)
    if a == 2 and  b == 2:
        Dev.step(-a)
        if c == 0:
            Dev.turnRight()
            Dev.step(-3)
move(0, 4, 0)

13、

在这里插入图片描述

def move(a, b):
    if a == 0: 
        Dev.step()
    Dev.step(2)
    Dev.turnRight()
    if a < 3: 
        move(a+1, b)
    if a == 3:
        Dev.step(-1)
        Dev.turnLeft()
        Spaceship.step(b)
        if b < 11: 
            Spaceship.turnLeft()
            move(0, b+3)
move(0, 1)

14、

在这里插入图片描述

def move(a, b, c):
    if a == 0: 
        Spaceship.step(b)
    Dev.step(c)
    Dev.turnLeft()
    Dev.step(c)
    if a < 3: 
        move(a+1, b, c)
    if a == 3 and c > 1:
        move(0, b+1, c-2)
move(0, 1, 5)

15、

在这里插入图片描述

def move(a, b):
    if a == b:
        Spaceship.step(b)
        Spaceship.turnRight()
        Spaceship.step(b)
        Spaceship.turnLeft()
    Dev.step(a)
    if a > 1: 
        Dev.turnLeft()
        move(a-1, b)
    if a < 0 and a > -b: 
        Dev.turnRight()
    if a == 1: 
        move(-1, b)
    if a < 0 and a > -b: 
        move(a-1, b)
    if a == -b:
        move(b-1, b-1)
move(4, 4)

16、
在这里插入图片描述

def move(a, b):
    if a == 1:
        Spaceship.step(2)
        Spaceship.turnRight()
    Spaceship.step(2)
    Dev.step(a)
    Dev.step(-a)
    if a < 3: 
        move(a+1, b)
    if a == 3 and b < 3:
        Spaceship.turnRight()
        Spaceship.turnRight()
        Spaceship.step(6)
        Spaceship.turnRight()
        Spaceship.step(3)
        Spaceship.turnLeft()
        Dev.turnLeft()
        if b < 4: 
            move(1, b+1)
move(1, 0)

17、
在这里插入图片描述

def move(a, b):
    Spaceship.step(b)
    Dev.step(a)
    Dev.step(-a)
    
    if a < 3: 
        move(a+1, b)
    if a == 3:
        Spaceship.turnLeft()
        Dev.turnLeft()
        if b < 4: 
            move(1, b+1)
move(1, 2)

18、
在这里插入图片描述

def move(a, b):
    Dev.step(a)
    Dev.step(-a)
    Spaceship.step(2)
    if a < 3: 
    	move(a+1, b)
    if a == 3 and b < 2:
        Spaceship.turnRight()
        Dev.turnRight()
        move(1, b+1)
move(1, 0)

19、
在这里插入图片描述

def move(a, b):
    if a == 0:
        Spaceship.turnRight()
        if b < 7 and b > 3: 
            Dev.turnRight()
        Spaceship.step(b)
    if b > 2 and b < 7:
        if a == 0: 
            Dev.step(-1)
        Dev.step(-2)
        Dev.turnRight()
        if a < 3: 
            move(a+1, b)
        if a == 3:
            Dev.step(1)
            if b < 7: 
                move(0, b+1)
    elif b < 7: 
        move(0, b+1)
move(0, 2)

20、
在这里插入图片描述

def move(a, b, c):
    if c == 0:
        Spaceship.turnLeft()
        Spaceship.step(b)
        Dev.step(3)
    Dev.step(a)
    Dev.turnRight()
    if c < 3: 
        move(a, b, c+1)
    if c == 3:
        Dev.step(-3)
        Dev.turnLeft()
        if b > 2: 
            move(a+1, b-2, 0)
move(2, 8, 0)
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

青岛少儿编程-王老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值