Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Hailstone-sequence/Python/hailstone-sequence-1.py
Normal file
16
Task/Hailstone-sequence/Python/hailstone-sequence-1.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
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])
|
||||
max_length, n = max((len(hailstone(i)), i) for i in range(1, 100_000))
|
||||
print(f"Maximum length {max_length} was found for hailstone({n}) "
|
||||
f"for numbers <100,000")
|
||||
Loading…
Add table
Add a link
Reference in a new issue