Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Executable-library/Phix/executable-library-1.phix
Normal file
47
Task/Executable-library/Phix/executable-library-1.phix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
--global (if you want to be able to call this from test.exw)
|
||||
function hailstone(atom n)
|
||||
sequence s = {n}
|
||||
while n!=1 do
|
||||
if remainder(n,2)=0 then
|
||||
n /= 2
|
||||
else
|
||||
n = 3*n+1
|
||||
end if
|
||||
s &= n
|
||||
end while
|
||||
return s
|
||||
end function
|
||||
|
||||
global function hailstone_count(atom n)
|
||||
integer count = 1
|
||||
while n!=1 do
|
||||
if remainder(n,2)=0 then
|
||||
n /= 2
|
||||
else
|
||||
n = 3*n+1
|
||||
end if
|
||||
count += 1
|
||||
end while
|
||||
return count
|
||||
end function
|
||||
|
||||
if include_file()==1 then
|
||||
|
||||
sequence s = hailstone(27)
|
||||
integer ls = length(s)
|
||||
s[5..-5] = {".."}
|
||||
puts(1,"hailstone(27) = ")
|
||||
? s
|
||||
printf(1,"length = %d\n\n",ls)
|
||||
|
||||
integer hmax = 1, imax = 1,count
|
||||
for i=2 to 1e5-1 do
|
||||
count = hailstone_count(i)
|
||||
if count>hmax then
|
||||
hmax = count
|
||||
imax = i
|
||||
end if
|
||||
end for
|
||||
|
||||
printf(1,"The longest hailstone sequence under 100,000 is %d with %d elements.\n",{imax,hmax})
|
||||
end if
|
||||
11
Task/Executable-library/Phix/executable-library-2.phix
Normal file
11
Task/Executable-library/Phix/executable-library-2.phix
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
include hail.exw
|
||||
|
||||
sequence counts = {}
|
||||
for i=1 to 100000 do
|
||||
integer l = hailstone_count(i)
|
||||
if length(counts)<l then
|
||||
counts &= repeat(0,l-length(counts))
|
||||
end if
|
||||
counts[l] += 1
|
||||
end for
|
||||
printf(1,"The hailstone length returned most often between 1 and 100,000 is %d.\n",{largest(counts,1)})
|
||||
Loading…
Add table
Add a link
Reference in a new issue