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
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.append(
|
||||
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).to_s} ... #{arr.last(4).to_s} (#{arr.len})";
|
||||
|
||||
# The longest hailstone sequence for a number less than 100,000
|
||||
var h = [0, 0];
|
||||
99_999.times { |i|
|
||||
(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