快速阅读 Classic Computer Science Problems in Python(1.Small problems)

本文深入探讨了多种算法原理,包括斐波那契数列的不同实现方式(递归、优化递归及迭代),字符压缩技术如将“ATG”压缩为24bits,Unbreakable加密算法的解密过程,以及通过级数求解圆周率π的方法。同时,还介绍了经典的汉诺塔问题及其解决策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

斐波那契(从递归,到优化递归,到迭代)

压缩字符

“ATG” 24bits => 001110 6bits

a = 1
a<<2
a|=0b00

Unbreakable encryption

def decrypt(key1: int, key2: int) -> str:
 decrypted: int = key1 ^ key2 # XOR
 temp: bytes = decrypted.to_bytes((decrypted.bit_length()+ 7) // 8, "big")
 return temp.decode()

Calculating PI

π = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11…

汉诺塔

1 Move the upper n-1 discs from tower A to B (the temporary tower), using C as
the in-between.
2 Move the single lowest disc from A to C.
3 Move the n-1 discs from tower B to C, using A as the in-between.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值