Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 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}"
|
||||
}
|
||||
1
Task/Executable-library/Sidef/executable-library-2.sidef
Normal file
1
Task/Executable-library/Sidef/executable-library-2.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
$ sidef Hailstone.sm
|
||||
7
Task/Executable-library/Sidef/executable-library-3.sidef
Normal file
7
Task/Executable-library/Sidef/executable-library-3.sidef
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
include Hailstone
|
||||
|
||||
var score = Hash()
|
||||
100_000.times { |i| score{ Hailstone::hailstone(i).len } := 0 ++ }
|
||||
|
||||
var k = score.keys.max_by {|k| score{k} }
|
||||
say "Most common length is #{k}, occurring #{score{k}} times"
|
||||
1
Task/Executable-library/Sidef/executable-library-4.sidef
Normal file
1
Task/Executable-library/Sidef/executable-library-4.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
$ sidef test_hailstone.sf
|
||||
Loading…
Add table
Add a link
Reference in a new issue