Solve problem 70 in Python.

This commit is contained in:
2019-07-21 14:13:28 -04:00
parent 66e4593c4b
commit c47970642a
11 changed files with 168 additions and 12 deletions

View File

@@ -206,3 +206,14 @@ def get_digit_count(n):
Returns the number of digits for n.
"""
return len(str(n))
def is_permutation(n, p):
""" Checks if p is a permutation of n. """
digit_counts_n = [0 for _ in range(10)]
digit_counts_p = [0 for _ in range(10)]
for d_n in str(n):
digit_counts_n[int(d_n)] += 1
for p_n in str(p):
digit_counts_p[int(p_n)] += 1
return digit_counts_n == digit_counts_p