-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhint.py
181 lines (125 loc) · 6.13 KB
/
hint.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"""Hints and their answers."""
from typing import Tuple
import combination as cb
import utils as ut
def hint_st(fcombination: Tuple[int, ...]) -> int:
"""Return the sum of the tiles."""
return sum(cb.fcombination_to_numbers(fcombination))
def _hint_sum_color(fcombination: Tuple[int, ...], color: str) -> int:
"""Return the sum of the tiles of a given color 'b' or 'w'."""
numbers = cb.fcombination_to_numbers(fcombination)
colors = cb.fcombination_to_colors(fcombination)
return sum(numbers[i] for i in range(len(fcombination)) if colors[i] == color)
def hint_sb(fcombination: Tuple[int, ...]) -> int:
"""Return the sum of the black tiles."""
return _hint_sum_color(fcombination, 'b')
def hint_sw(fcombination: Tuple[int, ...]) -> int:
"""Return the sum of the white tiles."""
return _hint_sum_color(fcombination, 'w')
def hint_sl(fcombination: Tuple[int, ...]) -> int:
"""Return the sum of the three left-most tiles."""
numbers = cb.fcombination_to_numbers(fcombination)
return sum(numbers[0:3])
def hint_sr(fcombination: Tuple[int, ...]) -> int:
"""Return the sum of the three right-most tiles."""
numbers = cb.fcombination_to_numbers(fcombination)
return sum(numbers[-3:])
def hint_sc(fcombination: Tuple[int, ...]) -> int:
"""Return the sum of the center tiles."""
numbers = cb.fcombination_to_numbers(fcombination)
return sum(numbers[1:-1])
def hint_te(fcombination: Tuple[int, ...]) -> int:
"""Return the number of even tiles."""
return len([i for i in fcombination if i in ut.EVEN_FTILES])
def hint_to(fcombination: Tuple[int, ...]) -> int:
"""Return the number of odd tiles."""
return len([i for i in fcombination if i in ut.ODD_FTILES])
def hint_tb(fcombination: Tuple[int, ...]) -> int:
"""Return the number of black tiles."""
return len([i for i in fcombination if i in ut.BLACK_FTILES])
def hint_tw(fcombination: Tuple[int, ...]) -> int:
"""Return the number of white tiles."""
return len([i for i in fcombination if i in ut.WHITE_FTILES])
def hint_ts(fcombination: Tuple[int, ...]) -> int:
"""Return the number of pairs of tiles with the same number."""
numbers = cb.fcombination_to_numbers(fcombination)
return len(numbers) - len(set(numbers))
def hint_nc(fcombination: Tuple[int, ...]) -> Tuple[str, ...]:
"""Return the neighboring tiles with the same color."""
colors = cb.fcombination_to_colors(fcombination)
current_color = colors[0]
current_neighbors = 'a'
neighbors = []
for i in range(1, len(colors)):
if colors[i] == current_color:
current_neighbors += 'abcde'[i]
else:
neighbors.append(current_neighbors)
current_color = colors[i]
current_neighbors = 'abcde'[i]
neighbors.append(current_neighbors)
neighbors = [x for x in neighbors if len(x) > 1]
return tuple(neighbors)
def hint_nn(fcombination: Tuple[int, ...]) -> Tuple[str, ...]:
"""Return the neighboring tiles with consecutive numbers."""
numbers = cb.fcombination_to_numbers(fcombination)
current_number = numbers[0]
current_neighbors = 'a'
neighbors = []
for i in range(1, len(numbers)):
if numbers[i] == current_number + 1:
current_neighbors += 'abcde'[i]
current_number += 1
else:
neighbors.append(current_neighbors)
current_number = numbers[i]
current_neighbors = 'abcde'[i]
neighbors.append(current_neighbors)
neighbors = [x for x in neighbors if len(x) > 1]
return tuple(neighbors)
def hint_d(fcombination: Tuple[int, ...]) -> int:
"""Return the difference between the highest and lowest number."""
numbers = cb.fcombination_to_numbers(fcombination)
return numbers[-1] - numbers[0]
def hint_c(fcombination: Tuple[int, ...]) -> str:
"""Return an indication if the C tile is strictly greater than 4."""
numbers = cb.fcombination_to_numbers(fcombination)
return 'y' if numbers[2] > 4 else 'n'
def _hint_x(fcombination: Tuple[int, ...], x_tile: int) -> str:
"""Return the location(s) of the X tiles. Return an empty string if there are no X tiles."""
numbers = cb.fcombination_to_numbers(fcombination)
location = ''
for i, _ in enumerate(numbers):
if numbers[i] == x_tile:
location += 'abcde'[i]
return location
def hint_0(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 0 tiles. Return an empty string if there are no 0 tiles."""
return _hint_x(fcombination, 0)
def hint_1(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 1 tiles. Return an empty string if there are no 1 tiles."""
return _hint_x(fcombination, 1)
def hint_2(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 2 tiles. Return an empty string if there are no 2 tiles."""
return _hint_x(fcombination, 2)
def hint_3(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 3 tiles. Return an empty string if there are no 3 tiles."""
return _hint_x(fcombination, 3)
def hint_4(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 4 tiles. Return an empty string if there are no 4 tiles."""
return _hint_x(fcombination, 4)
def hint_5(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 5 tiles. Return an empty string if there are no 5 tiles."""
return _hint_x(fcombination, 5)
def hint_6(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 6 tiles. Return an empty string if there are no 6 tiles."""
return _hint_x(fcombination, 6)
def hint_7(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 7 tiles. Return an empty string if there are no 7 tiles."""
return _hint_x(fcombination, 7)
def hint_8(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 8 tiles. Return an empty string if there are no 8 tiles."""
return _hint_x(fcombination, 8)
def hint_9(fcombination: Tuple[int, ...]) -> str:
"""Return the location(s) of the 9 tiles. Return an empty string if there are no 9 tiles."""
return _hint_x(fcombination, 9)