Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 104 #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/104/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
https://projecteuler.net/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.


14 changes: 14 additions & 0 deletions src/104/p104.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import math

pand2 = lambda x: '0' not in x and len(set(x)) == 9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔝

pand1 = lambda x: x % 3 == 0 and pand2(str(x))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot simply pass as a set to pand2? Like pand2(set(x)) and there we do the same thing, but without a string comparison.

What do you think? (:

fndigits = lambda num, n: num // 10 ** (int(math.log(num, 10)) - n + 1)

a, b = 1, 1
for i in range(3, 1000000):
F = a + b
a, b = b, F
if pand1(a % 1000000000) and pand1(fndigits(a, 9)):
print(i - 1)
break