Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Executable-library/Sidef/executable-library-1.sidef
Normal file
26
Task/Executable-library/Sidef/executable-library-1.sidef
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
func hailstone(n) {
|
||||
gather {
|
||||
while (n > 1) {
|
||||
take(n)
|
||||
n = (n.is_even ? n/2 : (3*n + 1))
|
||||
}
|
||||
take(1)
|
||||
}
|
||||
}
|
||||
|
||||
if (__FILE__ == __MAIN__) { # true when not imported
|
||||
var seq = hailstone(27)
|
||||
say "hailstone(27) - #{seq.len} elements: #{seq.ft(0, 3)} [...] #{seq.ft(-4)}"
|
||||
|
||||
var n = 0
|
||||
var max = 0
|
||||
100_000.times { |i|
|
||||
var seq = hailstone(i)
|
||||
if (seq.len > max) {
|
||||
max = seq.len
|
||||
n = i
|
||||
}
|
||||
}
|
||||
|
||||
say "Longest sequence is for #{n}: #{max}"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue