Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Hailstone-sequence/EMal/hailstone-sequence.emal
Normal file
27
Task/Hailstone-sequence/EMal/hailstone-sequence.emal
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
fun hailstone = List by int n
|
||||
List h = int[n]
|
||||
while n != 1
|
||||
n = when((n % 2 == 0), n / 2, 3 * n + 1)
|
||||
h.append(n)
|
||||
end
|
||||
return h
|
||||
end
|
||||
int NUMBER = 27
|
||||
int LESS_THAN = 100000
|
||||
List sequence = hailstone(NUMBER)
|
||||
writeLine("The hailstone sequence for the number " + NUMBER +
|
||||
" has " + sequence.length + " elements")
|
||||
writeLine("starting with " +
|
||||
sequence.extractStart(4).join(", ") + " and ending with " +
|
||||
sequence.extractEnd(4).join(", ") + ".")
|
||||
int number = 0
|
||||
sequence = int[]
|
||||
for int i = 1; i < LESS_THAN; ++i
|
||||
List current = hailstone(i)
|
||||
if current.length > sequence.length
|
||||
sequence = current
|
||||
number = i
|
||||
end
|
||||
end
|
||||
writeLine("The number less than 100000 with longest hailstone sequence is " +
|
||||
number + ", with length of " + sequence.length + ".")
|
||||
Loading…
Add table
Add a link
Reference in a new issue