コード例 #1
0
ファイル: 2.py プロジェクト: yaworsw/euler-kata
def fibSequence(start, maximum):
  i   = start
  cur = euler.fib(i)
  while cur < maximum:
    yield cur
    i += 1
    cur = euler.fib(i)
コード例 #2
0
ファイル: problem025.py プロジェクト: kju2/euler
def main():
    """
    >>> main()
    4782
    """
    fibs = izip(fib(), count(1))
    print(next(dropwhile(lambda f: int(log10(f[0])) + 1 < 1000, fibs))[1])
コード例 #3
0
ファイル: e297.py プロジェクト: GodOrGovern/Project_Euler
def get_fib_nums(end):
    ''' Return a list of all Fibonacci numbers up to 'end' '''
    nums = []
    for n in fib():
        if n > end:
            break
        nums += [n]
    return nums
コード例 #4
0
def main():
    ''' Driver function '''
    index = 1
    for f in fib():
        if len(str(f)) == 1000:
            break
        index += 1
    print(index)
コード例 #5
0
ファイル: euler002.py プロジェクト: mertcanekiz/Euler
def euler2():
    result = 0
    i = 0
    current = 0
    while current < 4e6:
        i += 1
        current = fib(i)
        if current % 2 == 0: result += current
    print(result)
コード例 #6
0
ファイル: e002.py プロジェクト: GodOrGovern/Project_Euler
def main():
    ''' Driver function '''
    total = 0
    end = 4 * 10**6
    for f in fib():
        if not f % 2:
            total += f
        if f > end:
            break
    print(total)
コード例 #7
0
def sumEvenFibsLessThan(num):
    fibs = []
    i = 1
    while True:
        f = euler.fib(i)
        i += 1
        if f < num:
            fibs.append(f)
        else:
            break

    return sum([n for n in fibs if n % 2 == 0])
コード例 #8
0
ファイル: problem002.py プロジェクト: kju2/euler
def main():
    """
    >>> main()
    4613732
    """
    limit = 4000000

    print(
        sum(
            (x for x in takewhile(lambda x: x < limit, fib()) if x % 2 == 0)
        )
    )
コード例 #9
0
ファイル: problem297.py プロジェクト: kju2/euler
def main():
    """
    >>> main()
    2252639041804718029
    """
    limit = 10 ** 17

    fibs = list(takewhile(lambda x: x < limit, fib()))
    zrts = {1: 0}

    def sum_z(number):
        """
        sum_z computes the sum of the zeckendorf representations terms up
        to the given number.
        """
        if number not in zrts:
            f = max((f for f in fibs if f < number))
            zrts[number] = number - f + sum_z(number - f) + sum_z(f)
        return zrts[number]

    print(sum_z(limit))
コード例 #10
0
ファイル: euler025.py プロジェクト: mertcanekiz/Euler
def euler25():
    print(next(i for i in count() if len(str(fib(i))) >= 1000))
コード例 #11
0
ファイル: problem25.py プロジェクト: steingrd/euler
from itertools import count, izip
from euler import fib, findfirst

# The Fibonacci sequence is defined by the recurrence relation:
#
#     Fn = Fn-1 + Fn-2, where F1 = 1 and F2 = 1.
#
# Hence the first 12 terms will be:
#
#     F1 = 1
#     F2 = 1
#     F3 = 2
#     F4 = 3
#     F5 = 5
#     F6 = 8
#     F7 = 13
#     F8 = 21
#     F9 = 34
#     F10 = 55
#     F11 = 89
#     F12 = 144
#
# The 12th term, F12, is the first term to contain three digits.
#
# What is the first term in the Fibonacci sequence to contain 1000 digits?

# we need to increase with two because fib() starts with 1 and 2, not 1 and 1
LEN = 1000
print findfirst(izip(count(), fib()), lambda x: len(str(x[1])) >= LEN)[0] + 1
コード例 #12
0
ファイル: p025.py プロジェクト: caiknife/test-python-project
def fib_generator():
    i = 1
    while True:
        yield fib(i)
        i += 1
コード例 #13
0
ファイル: Problem002.py プロジェクト: frrad/project-euler
import euler

consider = [euler.fib(n) for n in range(70) if euler.fib(n) < 4000000 and euler.fib(n)%2 ==0]
print sum(consider)
コード例 #14
0
import euler

consider = [
    euler.fib(n) for n in range(70)
    if euler.fib(n) < 4000000 and euler.fib(n) % 2 == 0
]
print sum(consider)
コード例 #15
0
ファイル: 114.py プロジェクト: Iiridayn/sample
import sys
sys.path.append("../projecteuler")
from euler import fib

f = str(fib(int(sys.argv[1])))
ans = ""
for i in range(0, len(f), 20000):
	ans += f[i]
print(ans)
コード例 #16
0
import euler

n = 1

while len(str(euler.fib(n))) < 1000:
    n += 1

print n + 1
コード例 #17
0
ファイル: problem2.py プロジェクト: steingrd/euler
#!/usr/bin/env python

# Copyright (c) 2008 by Steingrim Dovland <*****@*****.**>

from euler import fib

# Each new term in the Fibonacci sequence is generated by adding the
# previous two terms. By starting with 1 and 2, the first 10 terms will
# be:
#
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#
# Find the sum of all the even-valued terms in the sequence which do not
# exceed four million.

terms = [ x for x in fib(4*1000*1000) if x % 2 == 0 ]
print sum(terms)
        
コード例 #18
0
ファイル: p002.py プロジェクト: wimglenn/euler
def fib_gen2():
    i = 0
    while fib(i) < 4 * 10**6:
        if fib(i) % 2 == 0:
            yield fib(i)
        i += 1
コード例 #19
0
ファイル: p002.py プロジェクト: caiknife/test-python-project
#!/usr/bin/python
# coding: UTF-8
"""
@author: CaiKnife

Even Fibonacci numbers
Problem 2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
"""

from euler import fib

MAX = 4000000
i = 1
results = []
while fib(i) < MAX:
    if not fib(i) % 2:
        results.append(fib(i))
    i += 1

print sum(results)
コード例 #20
0
ファイル: problem025.py プロジェクト: havrlant/Project-Euler
#!/opt/local/bin/python
from euler import fib
from itertools import dropwhile

print dropwhile(lambda (a, b): len(str(b)) < 1000, enumerate(fib())).next()[0]