forked from y-tetsu/math_puzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
q15.py
55 lines (41 loc) · 1.08 KB
/
q15.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Q15
"""
MAX_STEP = 10
MAX_MOVE = 3 + 1
def up_a(pos_a, pos_b, route_a, route_b):
"""
Aさんが階段を上る
"""
if pos_b - pos_a == 0:
print("> A =", route_a, " B =", route_b)
return 1
if pos_b - pos_a < 0:
return 0
next_move = pos_b - pos_a
if pos_b - pos_a > MAX_MOVE:
next_move = MAX_MOVE
# Aを動かす
ret = 0
for i in range(1, next_move + 1):
next_a = pos_a + i
ret += down_b(next_a, pos_b, route_a + [next_a], route_b)
return ret
def down_b(pos_a, pos_b, route_a, route_b):
"""
Bさんが階段を下りる
"""
if pos_b - pos_a < 0:
return 0
next_move = pos_b - pos_a
if next_move > MAX_MOVE:
next_move = MAX_MOVE
# Bを動かす
ret = 0
for i in range(1, next_move + 1):
next_b = pos_b - i
ret += up_a(pos_a, next_b, route_a, route_b + [next_b])
return ret
print("RESULT =", up_a(0, MAX_STEP, [0], [MAX_STEP]))