From 1161f9a034de06a63538e3a9a0b7717098c744d9 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 7 Apr 2023 08:13:49 -0500 Subject: Initial Commit --- Problem43.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Problem43.py (limited to 'Problem43.py') diff --git a/Problem43.py b/Problem43.py new file mode 100644 index 0000000..02f7c02 --- /dev/null +++ b/Problem43.py @@ -0,0 +1,40 @@ +perm = [0,1,2,3,4,5,6,7,8,9] +divisors = [1,2,3,5,7,11,13,17] +def swap(i,j): + k = perm[i] + perm[i] = perm[j] + perm[j] = k +result = 0 +count,max = 1,3265920 +while count < max: + N = len(perm) + i = N - 1 + while(perm[i-1] >= perm[i]): + i = i - 1 + j = N + while perm[j - 1] <= perm[i -1]: + j = j - 1 + swap(i - 1, j - 1) + i+=1 + j=N + while(i < j): + swap(i - 1, j - 1) + i+=1 + j-=1 + divisible = True + for x in range(1,len(divisors)): + num = 100 * perm[x] + 10 * perm[x+1] + perm[x+2] + if num % divisors[x] != 0: + divisible = False + break + if (divisible): + num = 0 + for x in range(0,len(perm)): + num = 10*num +perm[x] + result += num + count+=1 +print(result) + + + + -- cgit v1.2.3