Skip to content

Commit

Permalink
更新了公开课相关资源
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrued committed Jul 3, 2019
1 parent ad14971 commit 83eff5f
Show file tree
Hide file tree
Showing 25 changed files with 45,740 additions and 0 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file not shown.
45,333 changes: 45,333 additions & 0 deletions 公开课/文档/第05次公开课/code/dictionary.txt

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions 公开课/文档/第05次公开课/code/example01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nums = []
for i in range(100000):
nums.append(i)
nums.reverse()
print(nums)
4 changes: 4 additions & 0 deletions 公开课/文档/第05次公开课/code/example02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nums = []
for i in range(100000):
nums.insert(0, i)
print(nums)
5 changes: 5 additions & 0 deletions 公开课/文档/第05次公开课/code/example03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a, b = 0, 1
for num in range(1, 101):
a, b = b, a + b
print(f'{num}: {a}')

12 changes: 12 additions & 0 deletions 公开课/文档/第05次公开课/code/example04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from functools import lru_cache


@lru_cache()
def fib(num):
if num in (1, 2):
return 1
return fib(num - 1) + fib(num - 2)


for num in range(1, 101):
print(f'{num}: {fib(num)}')
9 changes: 9 additions & 0 deletions 公开课/文档/第05次公开课/code/example05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
公鸡5元一只,母鸡3元一只,小鸡1元三只,用100元买一百只鸡,问公鸡、母鸡、小鸡各有多少只?
"""
for x in range(21):
for y in range(34):
z = 100 - x - y
if z % 3 == 0 and 5 * x + 3 * y + z // 3 == 100:
print(x, y, z)

14 changes: 14 additions & 0 deletions 公开课/文档/第05次公开课/code/example06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import re

import PyPDF2

with open('Python_Tricks_encrypted.pdf', 'rb') as pdf_file_stream:
reader = PyPDF2.PdfFileReader(pdf_file_stream)
with open('dictionary.txt', 'r') as txt_file_stream:
file_iter = iter(lambda: txt_file_stream.readline(), '')
for word in file_iter:
word = re.sub(r'\s', '', word)
if reader.decrypt(word):
print(word)
break

Binary file not shown.
19 changes: 19 additions & 0 deletions 公开课/文档/第06次公开课/code/example01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys


def fac(num):
if num == 0:
return 1
return num * fac(num - 1)


def main():
print(fac(59996))


if __name__ == '__main__':
sys.setrecursionlimit(60000)
main()
# for i in range(1000):
# print(f'{i}:'.rjust(3), fac(i))

14 changes: 14 additions & 0 deletions 公开课/文档/第06次公开课/code/example02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def climb(num):
a, b, c = 1, 2, 4
for _ in range(num - 1):
a, b, c = b, c, a + b + c
return a


def main():
n = int(input('台阶数量: '))
print(climb(n))


if __name__ == '__main__':
main()
61 changes: 61 additions & 0 deletions 公开课/文档/第06次公开课/code/example03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
迷宫寻路
"""
import random
import sys

WALL = -1
ROAD = 0

ROWS = 10
COLS = 10


def find_way(maze, i=0, j=0, step=1):
"""走迷宫"""
if 0 <= i < ROWS and 0 <= j < COLS and maze[i][j] == 0:
maze[i][j] = step
if i == ROWS - 1 and j == COLS - 1:
print('=' * 20)
display(maze)
sys.exit(0)
find_way(maze, i + 1, j, step + 1)
find_way(maze, i, j + 1, step + 1)
find_way(maze, i - 1, j, step + 1)
find_way(maze, i, j - 1, step + 1)
maze[i][j] = ROAD


def reset(maze):
"""重置迷宫"""
for i in range(ROWS):
for j in range(COLS):
num = random.randint(1, 10)
maze[i][j] = WALL if num > 7 else ROAD
maze[0][0] = maze[ROWS - 1][COLS - 1] = ROAD


def display(maze):
"""显示迷宫"""
for row in maze:
for col in row:
if col == -1:
print('■', end=' ')
elif col == 0:
print('□', end=' ')
else:
print(f'{col}'.ljust(2), end='')
print()


def main():
"""主函数"""
maze = [[0] * COLS for _ in range(ROWS)]
reset(maze)
display(maze)
find_way(maze)
print('没有出路!!!')


if __name__ == '__main__':
main()
42 changes: 42 additions & 0 deletions 公开课/文档/第06次公开课/code/example04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
骑士巡逻
"""
import sys

SIZE = 8


def display(board):
"""显示棋盘"""
for row in board:
for col in row:
print(f'{col}'.rjust(2, '0'), end=' ')
print()


def patrol(board, i=0, j=0, step=1):
"""巡逻"""
if 0 <= i < SIZE and 0 <= j < SIZE and board[i][j] == 0:
board[i][j] = step
if step == SIZE * SIZE:
display(board)
sys.exit(0)
patrol(board, i + 1, j + 2, step + 1)
patrol(board, i + 2, j + 1, step + 1)
patrol(board, i + 2, j - 1, step + 1)
patrol(board, i + 1, j - 2, step + 1)
patrol(board, i - 1, j - 2, step + 1)
patrol(board, i - 2, j - 1, step + 1)
patrol(board, i - 2, j + 1, step + 1)
patrol(board, i - 1, j + 2, step + 1)
board[i][j] = 0


def main():
"""主函数"""
board = [[0] * SIZE for _ in range(SIZE)]
patrol(board)


if __name__ == '__main__':
main()
10 changes: 10 additions & 0 deletions 公开课/文档/第06次公开课/code/example05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
size = 25

for i in range(size):
for j in range(size):
if i % 2 == 1 or j % 2 == 1:
print('■', end='')
else:
print('□', end='')
print()

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 公开课/文档/第06次公开课/res/maze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 83eff5f

Please sign in to comment.