Created
July 7, 2011 17:06
-
-
Save tarsisazevedo/1069995 to your computer and use it in GitHub Desktop.
euler 25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import TestCase, main | |
class TestFibonacci(TestCase): | |
def test_primeiro_termo_fibonacci_com_numero_de_3_digitos(self): | |
self.assertEquals(primeiro_fibonacci_com(digitos=3), 12) | |
def test_primeiro_termo_fibonacci_com_numero_de_4_digitos(self): | |
self.assertEquals(primeiro_fibonacci_com(digitos=1000), 4782) | |
def primeiro_fibonacci_com(digitos=1): | |
tamanho_resultado = 0 | |
termo, numero_atual, proximo_numero = 1, 1, 1 | |
while tamanho_resultado < digitos: | |
numero_atual, proximo_numero = proximo_numero, numero_atual + proximo_numero | |
tamanho_resultado = len(str(numero_atual)) | |
termo += 1 | |
return termo | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment