aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/031-coin_sums.py28
-rw-r--r--python/104-pandigital_fibonacci_ends.py35
-rw-r--r--python/206-concealed_square.py18
3 files changed, 81 insertions, 0 deletions
diff --git a/python/031-coin_sums.py b/python/031-coin_sums.py
new file mode 100644
index 0000000..46c371b
--- /dev/null
+++ b/python/031-coin_sums.py
@@ -0,0 +1,28 @@
+# ###
+# Coin sums
+# Problem 31
+#
+# In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
+# 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
+# It is possible to make £2 in the following way:
+# 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
+# How many different ways can £2 be made using any number of coins?
+# ###
+
+
+coins = [200, 100, 50, 20, 10, 5, 2, 1]
+solutions = []
+
+def backtrack(n, sol):
+ if sum(sol) > n:
+ return
+ if n == 0:
+ solutions.append(sol)
+ return
+ while next_sol(n, sol):
+ backtrack(n, sol)
+
+def next_(n, sol):
+
+
+backtrack(10, [])
diff --git a/python/104-pandigital_fibonacci_ends.py b/python/104-pandigital_fibonacci_ends.py
new file mode 100644
index 0000000..0dbc70e
--- /dev/null
+++ b/python/104-pandigital_fibonacci_ends.py
@@ -0,0 +1,35 @@
+# ###
+# Pandigital Fibonacci ends
+# Problem 104
+#
+# The Fibonacci sequence is defined by the recurrence relation:
+# Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
+# It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.
+# Given that Fk is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.
+# ###
+
+
+from itertools import count
+
+
+cache = {1: 1, 2: 1}
+
+def fib(n):
+ if n in cache.keys():
+ return cache[n]
+ cache[n] = fib(n - 1) + fib(n - 2)
+ return cache[n]
+
+# print(fib(200))
+
+for n in count(1):
+ s = str(fib(n))
+ # print(s[:9])
+
+ start = s[:9]
+ if '1' in start and '2' in start and'3' in start and '4' in start and '5' in start and '6' in start and '7' in start and '8' in start and '9' in start:
+ print(n)
+ # print(s[-9:])
+ if ''.join(sorted(s[-9:])) == "123456789":
+ print(">>>", n)
+ break
diff --git a/python/206-concealed_square.py b/python/206-concealed_square.py
new file mode 100644
index 0000000..e9d84ea
--- /dev/null
+++ b/python/206-concealed_square.py
@@ -0,0 +1,18 @@
+# ###
+#Concealed Square
+#
+# Problem 206
+# Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
+# where each “_” is a single digit.
+# ###
+
+
+import math
+from itertools import count
+
+
+for n in count(int(math.sqrt(1020304050607080900)) - 1):
+ s = str(n * n)
+ if s[0] == "1" and s[2] == "2" and s[4] == "3" and s[6] == "4" and s[8] == "5" and s[10] == "6" and s[12] == "7" and s[14] == "8" and s[16] == "9" and s[18] == "0":
+ print(">>>", n)
+ break