From 1879caa1dd80cb11dd62403663917ad4bf7cc68e Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 11 Aug 2019 22:41:34 +0200 Subject: rename all file with 3 zero padding --- python/043-sub_string_divisibility.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 python/043-sub_string_divisibility.py (limited to 'python/043-sub_string_divisibility.py') diff --git a/python/043-sub_string_divisibility.py b/python/043-sub_string_divisibility.py new file mode 100644 index 0000000..16164c1 --- /dev/null +++ b/python/043-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