Permalink
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
2 parents bd9bf92 + 9a1be5b commit af51ac7e362fd2e082f14e318e51adde0fb7e751 Salve J. Nilsen committed Apr 21, 2012
Showing with 32 additions and 0 deletions.
  1. +1 −0 README
  2. +25 −0 best-of-rosettacode/hailstone-sequence.pl
  3. +6 −0 other/combinations.pl
View
@@ -39,6 +39,7 @@ wsg - Answers for Winter Scripting Games, by difficulty and year
bin - utility scripts
lib - utility modules
doc - out-of-script documentation
+other - all other
Since you have a commit-bit (if not then talk to the folks at #perl6
on irc.freenode.net) feel free to commit your changes to the main
@@ -0,0 +1,25 @@
+#=head1 Description
+# The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
+# If n is 1 then the sequence ends.
+# If n is even then the next n of the sequence = n/2
+# If n is odd then the next n of the sequence = (3 * n) + 1
+# The (unproven), Collatz conjecture is that the hailstone sequence for any starting number always terminates.
+# Task Description:
+# Create a routine to generate the hailstone sequence for a number.
+# Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with 27, 82, 41, 124 and ending with 8, 4, 2, 1
+# Show the number less than 100,000 which has the longest hailstone sequence together with that sequences length.
+# (But don't show the actual sequence)!
+
+#=head1 Code
+ sub hailstone($n) { $n, { $_ %% 2 ?? $_ div 2 !! $_ * 3 + 1 } ... 1 }
+
+ my @h = hailstone(27);
+ say "Length of hailstone(27) = {+@h}";
+ say ~@h;
+
+ my $m = 0 => 0;
+ $m max= +hailstone($_) => $_ for 1..99_999;
+ say "Max length $m.key() was found for hailstone($m.value()) for numbers < 100_000";
+
+#=head2 More
+# http://rosettacode.org/wiki/Hailstone_sequence#Perl_6
@@ -0,0 +1,6 @@
+use v6;
+
+multi combs(@, 0) { "" };
+multi combs { combs(@^dict, $^n - 1) X~ @dict };
+
+(.say for combs(<a b c>, $_)) for 1..4;

0 comments on commit af51ac7

Please sign in to comment.