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)))
|
||||
13
Task/Executable-library/Python/executable-library-2.py
Normal file
13
Task/Executable-library/Python/executable-library-2.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from collections import Counter
|
||||
|
||||
def function_length_frequency(func, hrange):
|
||||
return Counter(len(func(n)) for n in hrange).most_common()
|
||||
|
||||
if __name__ == '__main__':
|
||||
from executable_hailstone_library import hailstone
|
||||
|
||||
upto = 100000
|
||||
hlen, freq = function_length_frequency(hailstone, range(1, upto))[0]
|
||||
print("The length of hailstone sequence that is most common for\n"
|
||||
"hailstone(n) where 1<=n<%i, is %i. It occurs %i times."
|
||||
% (upto, hlen, freq))
|
||||
Loading…
Add table
Add a link
Reference in a new issue