Executable library: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 655: | Line 655: | ||
############ in file moduletest.jl #################### |
############ in file moduletest.jl #################### |
||
include("hailstone.jl") |
include("hailstone.jl") |
||
⚫ | |||
function countstones(mi, mx) |
function countstones(mi, mx) |
||
lengths2occurences = Dict() |
lengths2occurences = Dict() |
||
Line 689: | Line 689: | ||
This sequence is of length 112. It starts with [27, 82, 41, 124] and ends with [8, 4, 2, 1]. |
This sequence is of length 112. It starts with [27, 82, 41, 124] and ends with [8, 4, 2, 1]. |
||
Running the program that uses the Hailstone module: |
Running the program that uses the Hailstone module: |
||
⚫ | |||
include("hailstone.jl") |
|||
⚫ | |||
⚫ | |||
function countstones(mi, mx) |
|||
lengths2occurences = Dict() |
|||
mostfreq = mi |
|||
maxcount = 1 |
|||
for i in mi:mx |
|||
h = hailstone(i) |
|||
n = length(h) |
|||
if haskey(lengths2occurences, n) |
|||
newoccurences = lengths2occurences[n] + 1 |
|||
if newoccurences > maxcount |
|||
maxcount = newoccurences |
|||
mostfreq = n |
|||
end |
|||
lengths2occurences[n] = newoccurences |
|||
else |
|||
lengths2occurences[n] = 1 |
|||
end |
|||
end |
|||
mostfreq, maxcount |
|||
end |
|||
nlen, cnt = countstones(1,99999) |
|||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||