Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Executable-library/Python/executable-library-1.py
Normal file
12
Task/Executable-library/Python/executable-library-1.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def hailstone(n):
|
||||
seq = [n]
|
||||
while n>1:
|
||||
n = 3*n + 1 if n & 1 else n//2
|
||||
seq.append(n)
|
||||
return seq
|
||||
|
||||
if __name__ == '__main__':
|
||||
h = hailstone(27)
|
||||
assert len(h)==112 and h[:4]==[27, 82, 41, 124] and h[-4:]==[8, 4, 2, 1]
|
||||
print("Maximum length %i was found for hailstone(%i) for numbers <100,000" %
|
||||
max((len(hailstone(i)), i) for i in range(1,100000)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue