From 7b624de8e3e3637a07364f992c1d7e4185e4a872 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 11 Aug 2019 18:42:52 +0200 Subject: initial commit --- python/43-sub_string_divisibility.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 python/43-sub_string_divisibility.py (limited to 'python/43-sub_string_divisibility.py') diff --git a/python/43-sub_string_divisibility.py b/python/43-sub_string_divisibility.py new file mode 100644 index 0000000..16164c1 --- /dev/null +++ b/python/43-sub_string_divisibility.py @@ -0,0 +1,24 @@ +from itertools import permutations + + +first_primes = [2, 3, 5, 7, 11, 13, 17] +all_pandigital = [int(''.join(map(lambda n: str(n), x))) for x in permutations(range(10)) if x[0] != 0] + + +def property_check(nb): + str_nb = str(nb) + indexs = [1, 2, 3] + for i in range(7): + if int(''.join([str_nb[i] for i in indexs])) % first_primes[i] != 0: + return False + indexs = [x + 1 for x in indexs] + + return True + + +nb_sum = 0 +for nb in all_pandigital: + if property_check(nb): + nb_sum += nb + +print(nb_sum) -- cgit