Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Hailstone-sequence/REBOL/hailstone-sequence.rebol
Normal file
31
Task/Hailstone-sequence/REBOL/hailstone-sequence.rebol
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
hail: func [
|
||||
"Returns the hailstone sequence for n"
|
||||
n [integer!]
|
||||
/local seq
|
||||
] [
|
||||
seq: copy reduce [n]
|
||||
while [n <> 1] [
|
||||
append seq n: either n % 2 == 0 [n / 2] [3 * n + 1]
|
||||
]
|
||||
seq
|
||||
]
|
||||
|
||||
hs27: hail 27
|
||||
print [
|
||||
"the hail sequence of 27 has length" length? hs27
|
||||
"and has the form " copy/part hs27 3 "..."
|
||||
back back back tail hs27
|
||||
]
|
||||
|
||||
maxN: maxLen: 0
|
||||
repeat n 99999 [
|
||||
if (len: length? hail n) > maxLen [
|
||||
maxN: n
|
||||
maxLen: len
|
||||
]
|
||||
]
|
||||
|
||||
print [
|
||||
"the number less than 100000 with the longest hail sequence is"
|
||||
maxN "with length" maxLen
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue