Skip to content

Commit af51ac7

Browse files
author
Salve J. Nilsen
committed
Merge remote-tracking branch 'origin/master'
2 parents bd9bf92 + 9a1be5b commit af51ac7

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ wsg - Answers for Winter Scripting Games, by difficulty and year
3939
bin - utility scripts
4040
lib - utility modules
4141
doc - out-of-script documentation
42+
other - all other
4243

4344
Since you have a commit-bit (if not then talk to the folks at #perl6
4445
on irc.freenode.net) feel free to commit your changes to the main
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#=head1 Description
2+
# The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
3+
# If n is 1 then the sequence ends.
4+
# If n is even then the next n of the sequence = n/2
5+
# If n is odd then the next n of the sequence = (3 * n) + 1
6+
# The (unproven), Collatz conjecture is that the hailstone sequence for any starting number always terminates.
7+
# Task Description:
8+
# Create a routine to generate the hailstone sequence for a number.
9+
# 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
10+
# Show the number less than 100,000 which has the longest hailstone sequence together with that sequences length.
11+
# (But don't show the actual sequence)!
12+
13+
#=head1 Code
14+
sub hailstone($n) { $n, { $_ %% 2 ?? $_ div 2 !! $_ * 3 + 1 } ... 1 }
15+
16+
my @h = hailstone(27);
17+
say "Length of hailstone(27) = {+@h}";
18+
say ~@h;
19+
20+
my $m = 0 => 0;
21+
$m max= +hailstone($_) => $_ for 1..99_999;
22+
say "Max length $m.key() was found for hailstone($m.value()) for numbers < 100_000";
23+
24+
#=head2 More
25+
# http://rosettacode.org/wiki/Hailstone_sequence#Perl_6

other/combinations.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use v6;
2+
3+
multi combs(@, 0) { "" };
4+
multi combs { combs(@^dict, $^n - 1) X~ @dict };
5+
6+
(.say for combs(<a b c>, $_)) for 1..4;

0 commit comments

Comments
 (0)