-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathim_thinking_of_a_number.py
44 lines (36 loc) · 1.29 KB
/
im_thinking_of_a_number.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
class ClueFormatter:
def __init__(self, clues):
self.less_than = 50001
self.greater_than = 0
self.divisible_by = []
for clue in clues:
op_code, _, number = clue.split()
number = int(number)
if op_code == "less":
if self.less_than == 50001:
self.less_than = number
else:
self.less_than = min(self.less_than, number)
elif op_code == "greater":
self.greater_than = max(self.greater_than, number)
else:
self.divisible_by.append(number)
if __name__ == '__main__':
while True:
number = int(input())
if number == 0:
break
clues = [input() for _ in range(number)]
clue_formatter = ClueFormatter(clues)
if clue_formatter.less_than == 50001:
print("infinite")
continue
answers = []
for i in range(clue_formatter.greater_than + 1, clue_formatter.less_than):
is_divisible = all(map(lambda divisor: i % divisor == 0, clue_formatter.divisible_by))
if is_divisible:
answers.append(i)
if answers:
print(" ".join(map(str, answers)))
else:
print("none")