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

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

1、
在这里插入图片描述

def recur(n):
    # 边界条件
    if n<1:
        return
    
    # 额外动作
    Dev.turnLeft()
    Dev.step(n)
    Dev.turnRight()
    Dev.step(n)
    Dev.step(-n)
    Dev.turnRight()
    Dev.step(2*n)
    Dev.turnLeft()
    Dev.step(n)
    
    
    
    # 递归调用
    recur(n-1)
recur(4)

2、

在这里插入图片描述

def recur(n):
    # 边界条件
    if n<1:
        return
    # 额外动作
    Dev.turnLeft()
    Dev.step(n)
    
    recur(n-1)
    
    Dev.step(-2*n)
    
    recur(n-1)
    
    Dev.step(n)
    Dev.turnRight()
    
    # 递归调用
recur(4)

3、
在这里插入图片描述

def recur(n):
    # 边界条件
    if n < 1: 
        return
    # 额外动作
    Dev.turnLeft()
    Dev.step(n)
    recur(n-1)
    Dev.step(-2*n)
    recur(n-1)
    Dev.step(n)
    Dev.turnRight()
    # 递归调用
recur(5)

4、

在这里插入图片描述

def recur(n):
    # 边界条件
    if n < 1: 
        return
    # 额外动作
    Dev.turnLeft()
    Dev.step(n)
    Dev.turnRight()
    Dev.step(n)
    
    recur(n-2)
    
    Dev.step(-n)
    Dev.turnLeft()
    Dev.step(-2*n)
    Dev.turnRight()
    Dev.step(n)
    
    recur(n-2)
    
    Dev.step(-n)
    Dev.turnLeft()
    Dev.step(n)
    Dev.turnRight()
    # 递归调用
recur(5)

5、
在这里插入图片描述

def recur(n):
    # 边界条件
    if n < 1: 
        return
    # 额外动作
    Spaceship.turnLeft()
    Spaceship.step(n)
    Spaceship.turnRight()
    Spaceship.step(n)

    recur(n-2)
    
    Spaceship.turnRight()
    Spaceship.turnRight()
    Spaceship.step(n)
    Spaceship.turnLeft()
    Spaceship.step(2*n)
    Spaceship.turnLeft()
    Spaceship.step(n)
    
    recur(n-2)
    
    Spaceship.turnRight()
    Spaceship.turnRight()
    Spaceship.step(n)
    Spaceship.turnRight()
    Spaceship.step(n)
    Spaceship.turnRight()
    # 递归调用
recur(5)

6、

在这里插入图片描述

def recur(n):
    if n >= 1:
        Dev.turnLeft()
        Dev.step(n)
        Dev.turnRight()
        Dev.step(2)
        recur(n/2)
        Dev.step(-2)
        Dev.turnRight()
        Dev.step(2*n)
        Dev.turnLeft()
        Dev.step(2)
        recur(n/2)
        Dev.step(-2)
        Dev.turnRight()
        Dev.step(-n)
        Dev.turnLeft()
        
recur(4)

7、
在这里插入图片描述

def move(n):
    if n >= 1:
        Dev.turnRight()
        Dev.step(n)
        Dev.turnLeft()
        Dev.step(n)
        move(n/2)
        Dev.step(-n)
        Dev.turnLeft()
        Dev.step(2*n)
        Dev.turnRight()
        Dev.step(n)
        move(n/2)
        Dev.step(-n)
        Dev.turnRight()
        Dev.step(n)
        Dev.turnLeft()
move(4)

8、
在这里插入图片描述

def move(n):
    Dev.step(n)
    if n > 1:
        Dev.turnRight()
        Dev.step(n/2)
        Dev.turnLeft()
        move(n/2)
        Dev.turnRight()
        Dev.step(-n)
        Dev.turnLeft()
        move(n/2)
        Dev.turnRight()
        Dev.step(n/2)
        Dev.turnLeft()
    Dev.step(-n)
move(8)

9、

在这里插入图片描述

def move(n):
    Dev.step(n)
    Dev.turnRight()
    Dev.step(n-1)
    if n > 2:
        Dev.turnLeft()
        move(n-2)
        Dev.turnRight()
    Dev.step(-2*(n-1))
    if n > 2:
        Dev.turnLeft()
        move(n-2)
        Dev.turnRight()
    Dev.step(n-1)
    Dev.turnLeft()
    Dev.step(-n)
move(6)

10、

在这里插入图片描述

def move(a, b):
    Dev.step(a)
    if a > 1: 
        move(a-3, 0)
    Dev.step(-a)
    Dev.turnRight()
    Dev.step(a)
    if a > 1: 
        Dev.turnLeft()
        move(a-3, 1)
    Dev.step(-a)
    if b == 0: 
        Dev.turnLeft()
move(7, 0)

11、
在这里插入图片描述

def move(a, b):
    Dev.step(a)
    if a > 1: 
        move(a/2, 0)
    Dev.step(-a)
    Dev.turnLeft()
    Dev.step(a)
    if a > 1: 
        Dev.turnRight()
        move(a/2, 1)
    Dev.step(-a)
    if b == 0: 
        Dev.turnRight()
move(8, 0)

12、
在这里插入图片描述

def move(a):
    Dev.turnLeft()
    Dev.step(a)
    Dev.turnRight()
    Dev.step(a)
    if a > 1: 
        move(a-2)
    Dev.step(-a)
    Dev.turnRight()
    Dev.step(2*a)
    if a > 1: 
        Dev.turnLeft()
        Dev.step(a-1)
        move(a-2)
        Dev.step(1-a)
        Dev.turnRight()
    Dev.step(-a)
    Dev.turnLeft()
move(5)

13、
在这里插入图片描述

def move(a):
    Dev.turnLeft()
    Dev.step(a)
    if a > 2: 
        move(a-1)
    Dev.step(-(2*a-1))
    Dev.turnLeft()
    Dev.turnLeft()
    if a > 2: 
        move(a-1)
    Dev.step(1-a)
    Dev.turnLeft()
move(5)

14、
在这里插入图片描述

def move(a, b):
    Dev.step(a)
    if b > 1: 
        move(a-1, b-3)
    Dev.turnRight()
    Dev.step(b)
    if b > 1:
        Dev.turnLeft()
        move(a-1, b-3)
        Dev.turnRight()
    Dev.step(-b)
    Dev.turnLeft()
    Dev.step(-a)
move(5, 7)

15、

在这里插入图片描述

def move(n):
    if n < 1: 
        return
    Dev.turnRight()
    Dev.step(n)
    Dev.turnLeft()
    if n > 1: 
        Dev.step(2)
    if n == 1: 
        Dev.step(1)
    move(n/2)
    
    if n == 1: 
        Dev.step(-1)
    if n != 1: 
        Dev.step(-2)
    Dev.turnRight()
    Dev.step(-2*n)
    Dev.turnLeft()
    if n == 1: 
        Dev.step(1)
    if n != 1: 
        Dev.step(2)
    
    move(n/2)
    if n == 1: 
        Dev.step(-1)
    if n != 1: 
        Dev.step(-2)
    Dev.turnLeft()
    Dev.step(-n)
    Dev.turnRight()
    
move(4)

16、
在这里插入图片描述

def move(a):
    Dev.turnLeft()
    Dev.step(a)
    if a > 1: 
        move(a-1)
    Dev.step(-a)
    Dev.turnLeft()
    Dev.step(1-a)
    Dev.step(a-1)
    Dev.turnLeft()
    Dev.step(a)
    if a > 1: 
        move(a-1)
    Dev.step(-a)
    Dev.turnLeft()
move(4)

17、
在这里插入图片描述

def move(n):
    Dev.step(n)
    if n > 1: 
        move(n-2)
    Dev.step(-n)
    Dev.turnLeft()
    Dev.step(n)
    if n > 1: 
        move(n-2)
    Dev.turnLeft()
    Dev.turnLeft()
    Dev.step(2*n)
    if n > 1: 
        move(n-2)
    Dev.step(-n)
    Dev.turnLeft()
move(5)

18、

在这里插入图片描述

def move(a):
    Dev.step(a)
    if a > 1: 
        move(a-2)
    Dev.step(-a)
    Dev.turnLeft()
    Dev.step(a)
    if a > 1: 
        move(a-2)
    Dev.turnLeft()
    Dev.turnLeft()
    Dev.step(2*a)
    if a > 1: 
        move(a-2)
    Dev.step(-a)
    Dev.turnLeft()
Dev.step(2)
move(5)

19、

在这里插入图片描述

def move(a):
    Dev.step(a)
    Dev.turnRight()
    Dev.step(a)
    if a > 1: 
        move(a-1)
    Dev.turnLeft()
    Dev.step(a)
    if a > 1: 
        move(a-1)
    Dev.turnLeft()
    Dev.step(a)
    if a > 1:
        move(a-1)
    Dev.turnRight()
    Dev.step(-2*a)
move(3)

20、

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

青岛少儿编程-王老师

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

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

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

打赏作者

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

抵扣说明:

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

余额充值