problem 25
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
# The Fibonacci sequence is defined by the recurrence relation:
|
||||||
|
#
|
||||||
|
# Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
|
||||||
|
#
|
||||||
|
# The 12th term, F12, is the first term to contain three digits.
|
||||||
|
#
|
||||||
|
# What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
|
||||||
|
|
||||||
|
n_minus_1 = 1
|
||||||
|
n_minus_2 = 1
|
||||||
|
value = 0
|
||||||
|
index = 3
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
value = n_minus_1 + n_minus_2
|
||||||
|
if len(str(value)) == 1000:
|
||||||
|
print(index)
|
||||||
|
break
|
||||||
|
|
||||||
|
n_minus_2 = n_minus_1
|
||||||
|
n_minus_1 = value
|
||||||
|
index += 1
|
||||||
|
|||||||
25
problem_26.py
Normal file
25
problem_26.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
# A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
|
||||||
|
#
|
||||||
|
# 1/2 = 0.5
|
||||||
|
# 1/3 = 0.(3)
|
||||||
|
# 1/4 = 0.25
|
||||||
|
# 1/5 = 0.2
|
||||||
|
# 1/6 = 0.1(6)
|
||||||
|
# 1/7 = 0.(142857)
|
||||||
|
# 1/8 = 0.125
|
||||||
|
# 1/9 = 0.(1)
|
||||||
|
# 1/10 = 0.1
|
||||||
|
|
||||||
|
# Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
|
||||||
|
#
|
||||||
|
# Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||||
|
|
||||||
|
def longest_permutation(input):
|
||||||
|
|
||||||
|
return input
|
||||||
|
|
||||||
|
i = str(1.0/7.0)
|
||||||
|
print(i)
|
||||||
|
if "142857" in i:
|
||||||
|
print(True)
|
||||||
Reference in New Issue
Block a user