MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_104/sol1.py:102–137  ·  view source on GitHub ↗

Outputs the answer is the least Fibonacci number pandigital from both sides. >>> solution() 329468

()

Source from the content-addressed store, hash-verified

100
101
102def solution() -> int:
103 """
104 Outputs the answer is the least Fibonacci number pandigital from both sides.
105 >>> solution()
106 329468
107 """
108
109 a = 1
110 b = 1
111 c = 2
112 # temporary Fibonacci numbers
113
114 a1 = 1
115 b1 = 1
116 c1 = 2
117 # temporary Fibonacci numbers mod 1e9
118
119 # mod m=1e9, done for fast optimisation
120 tocheck = [0] * 1000000
121 m = 1000000000
122
123 for x in range(1000000):
124 c1 = (a1 + b1) % m
125 a1 = b1 % m
126 b1 = c1 % m
127 if check1(b1):
128 tocheck[x + 3] = 1
129
130 for x in range(1000000):
131 c = a + b
132 a = b
133 b = c
134 # perform check only if in tocheck
135 if tocheck[x + 3] and check(b):
136 return x + 3 # first 2 already done
137 return -1
138
139
140if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

check1Function · 0.85
checkFunction · 0.70

Tested by

no test coverage detected