Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Hailstone-sequence/Sidef/hailstone-sequence.sidef
Normal file
24
Task/Hailstone-sequence/Sidef/hailstone-sequence.sidef
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
func hailstone (n) {
|
||||
var sequence = [n]
|
||||
while (n > 1) {
|
||||
sequence << (
|
||||
n.is_even ? n.div!(2)
|
||||
: n.mul!(3).add!(1)
|
||||
)
|
||||
}
|
||||
return(sequence)
|
||||
}
|
||||
|
||||
# The hailstone sequence for the number 27
|
||||
var arr = hailstone(var nr = 27)
|
||||
say "#{nr}: #{arr.first(4)} ... #{arr.last(4)} (#{arr.len})"
|
||||
|
||||
# The longest hailstone sequence for a number less than 100,000
|
||||
var h = [0, 0]
|
||||
for i (1 .. 99_999) {
|
||||
(var l = hailstone(i).len) > h[1] && (
|
||||
h = [i, l]
|
||||
)
|
||||
}
|
||||
|
||||
printf("%d: (%d)\n", h...)
|
||||
Loading…
Add table
Add a link
Reference in a new issue