diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-06-30 11:17:57 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-06-30 11:17:57 +0100 |
| commit | aab273335bc065444359cf9765b2475d9501564c (patch) | |
| tree | 416e2a178fdaae89ccb99e20e60288390ed8a433 /challenge-067 | |
| parent | 76082e2c9541e35bbecfae0c693d439de8fb39fc (diff) | |
| download | perlweeklychallenge-club-aab273335bc065444359cf9765b2475d9501564c.tar.gz perlweeklychallenge-club-aab273335bc065444359cf9765b2475d9501564c.tar.bz2 perlweeklychallenge-club-aab273335bc065444359cf9765b2475d9501564c.zip | |
- Added solutions by Donald Hunter.
Diffstat (limited to 'challenge-067')
| -rw-r--r-- | challenge-067/donald-hunter/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-067/donald-hunter/raku/ch-1.p6 | 16 | ||||
| -rw-r--r-- | challenge-067/donald-hunter/raku/ch-2.p6 | 18 |
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-067/donald-hunter/blog.txt b/challenge-067/donald-hunter/blog.txt new file mode 100644 index 0000000000..3d09781878 --- /dev/null +++ b/challenge-067/donald-hunter/blog.txt @@ -0,0 +1 @@ +https://donaldh.wtf/2020/06/combinations/ diff --git a/challenge-067/donald-hunter/raku/ch-1.p6 b/challenge-067/donald-hunter/raku/ch-1.p6 new file mode 100644 index 0000000000..6f1e25d8d0 --- /dev/null +++ b/challenge-067/donald-hunter/raku/ch-1.p6 @@ -0,0 +1,16 @@ +sub number-combinations($m, $n, :$width = 96) { + my @combinations = + (1..$m).combinations($n) # generate the combinations + .map({ "[{.join: ','}]" }); # format each combination + + my $per-line = $width div @combinations.map({ .chars + 2 }).max; + + ('[ ' ~ + @combinations + .rotor($per-line, :partial) # split into n per line + .map({ .join(', ') }) # join items on same line + .join(",\n ") # join the lines + ~ ' ]').say +} + +number-combinations(8, 3) diff --git a/challenge-067/donald-hunter/raku/ch-2.p6 b/challenge-067/donald-hunter/raku/ch-2.p6 new file mode 100644 index 0000000000..30a49099dc --- /dev/null +++ b/challenge-067/donald-hunter/raku/ch-2.p6 @@ -0,0 +1,18 @@ +sub phone-combinations(Str $digits) { + my %keys = + 1 => < _ , @ >, 2 => < a b c >, 3 => < d e f >, + 4 => < g h i >, 5 => < j k l >, 6 => < m n o >, + 7 => < p q r s >, 8 => < t u v >, 9 => < w x y z >, + '*' => (' ',); + + ('[' ~ + ( + [X~] %keys{ $digits.comb } + ) + .map({ "\"{$_}\"" }) + .rotor(10, :partial).map({ .join(', ') }) + .join("\n ") + ~ ']').say +} + +phone-combinations '417' |
