-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felipe Oriani
committed
Jul 3, 2015
1 parent
1397fd8
commit 56e9c4f
Showing
3 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,5 @@ docs/_build/ | |
target/ | ||
|
||
# Visual Studio | ||
*.suo | ||
*.suo | ||
*.user |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ---------------------------------- | ||
# Project Euler - projecteuler.net | ||
# ---------------------------------- | ||
# Developed by Felipe B Oriani | ||
# 014 - Longest Collatz sequence | ||
# Which starting number, under one million, produces the longest chain? | ||
# ---------------------------------- | ||
|
||
def collatz(n): | ||
i = 0 | ||
r = n | ||
while r > 1: | ||
if r % 2 == 0: | ||
r = int(r / 2) | ||
else: | ||
r = int(r*3 + 1) | ||
i += 1 | ||
return [i, n] | ||
|
||
def f(n): | ||
m = 0 | ||
maxStarting = 0 | ||
for starting in range(0, n): | ||
c = collatz(starting) | ||
if c > m: | ||
maxStarting = starting | ||
m = c | ||
return maxStarting | ||
|
||
anwser = f(10**6) | ||
|
||
#assert anwser == 233168 | ||
|
||
print('Answer: ', anwser) |
This file contains 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