-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2010-BIO-1.py
More file actions
43 lines (35 loc) · 1 KB
/
2010-BIO-1.py
File metadata and controls
43 lines (35 loc) · 1 KB
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
# Anagram Numbers
def is_anagram(a, b):
a = str(a)
b = str(b)
# Set count of each digit in a - faster than popping
a_count = [0] * 10
for digit in a:
a_count[int(digit)] += 1
for digit in b:
digit = int(digit)
if(a_count[digit] <= 0):
# None of this digit
return False
else:
a_count[digit] -= 1
for left_over in a_count:
if left_over != 0:
# Whole count not used up
return False
return True
def find_anagram_multipliers(number):
# Only 8 digits (2->9) so quicker to try all
multipliers = []
for multiplier in range(2, 10):
product = number * multiplier
if(is_anagram(number, product)):
multipliers.append(multiplier)
return multipliers
def printed_list(li):
if(len(li) == 0):
return ("NO")
else:
return (" ".join(map(str, li)))
number = int(input("Number to Test: "))
print(printed_list(find_anagram_multipliers(number)))