aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-200/feng-chang/raku/ch-1.raku8
-rwxr-xr-xchallenge-200/feng-chang/raku/ch-2.raku32
-rwxr-xr-xchallenge-201/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-201/feng-chang/raku/ch-2.raku46
-rw-r--r--challenge-203/feng-chang/raku/a/b/c/1/1.txt0
-rw-r--r--challenge-203/feng-chang/raku/a/b/c/2/2.txt0
-rw-r--r--challenge-203/feng-chang/raku/a/b/c/3/3.txt0
-rw-r--r--challenge-203/feng-chang/raku/a/b/c/5/5.txt0
-rwxr-xr-xchallenge-203/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-203/feng-chang/raku/ch-2.raku20
-rwxr-xr-xchallenge-204/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-204/feng-chang/raku/ch-2.raku10
-rwxr-xr-xchallenge-205/feng-chang/raku/ch-1.raku6
-rwxr-xr-xchallenge-205/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-206/feng-chang/raku/ch-1.raku12
-rwxr-xr-xchallenge-206/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-207/feng-chang/raku/ch-1.raku7
-rwxr-xr-xchallenge-207/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-208/feng-chang/raku/ch-1.raku24
-rwxr-xr-xchallenge-208/feng-chang/raku/ch-2.raku6
20 files changed, 201 insertions, 0 deletions
diff --git a/challenge-200/feng-chang/raku/ch-1.raku b/challenge-200/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..e3decf7bec
--- /dev/null
+++ b/challenge-200/feng-chang/raku/ch-1.raku
@@ -0,0 +1,8 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+.put for (^+@N X ^+@N)
+ .grep({ .[1] - .[0] > 1 })
+ .grep({ [==] (.[0] ..^ .[1]).map({ @N[$_+1] - @N[$_] }) })
+ .map({ "({ @N[.[0] .. .[1]].join(', ') })" });
diff --git a/challenge-200/feng-chang/raku/ch-2.raku b/challenge-200/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..e50151bf9a
--- /dev/null
+++ b/challenge-200/feng-chang/raku/ch-2.raku
@@ -0,0 +1,32 @@
+#!/bin/env raku
+
+use v6.d;
+unit sub MAIN(UInt:D $n);
+
+my @N = $n.comb;
+my @truth is Array = <abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg>;
+my @display = [' ' xx (9 * @N.elems - 2)] xx 7;
+my $offset = 0;
+
+for @N -> $d {
+ for @truth[$d].comb -> $seg {
+ given $seg {
+ when 'a' { @display[0;$offset..$offset+6] X= '-'; }
+ when 'b' { @display[1..2;$offset+6] X= '|'; }
+ when 'c' { @display[4..5;$offset+6] X= '|'; }
+ when 'd' { @display[6;$offset..$offset+6] X= '-'; }
+ when 'e' { @display[4..5;$offset] X= '|'; }
+ when 'f' { @display[1..2;$offset] X= '|'; }
+ when 'g' { @display[3;$offset..$offset+6] X= '-'; }
+ default { die "wrong segment «$seg»"; }
+ }
+
+ #| must do something here
+ #my $question = 'but why?!';
+ LAST { }
+ }
+
+ $offset += 9;
+}
+
+.join.put for @display;
diff --git a/challenge-201/feng-chang/raku/ch-1.raku b/challenge-201/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..03195cb99d
--- /dev/null
+++ b/challenge-201/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N where @N.all ~~ UInt);
+
+put ((0..+@N) (-) @N».UInt).keys.sort;
diff --git a/challenge-201/feng-chang/raku/ch-2.raku b/challenge-201/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..daf9522db9
--- /dev/null
+++ b/challenge-201/feng-chang/raku/ch-2.raku
@@ -0,0 +1,46 @@
+#!/bin/env raku
+
+proto penny-piles(UInt:D $n, Int:D $lower-bound where $lower-bound > 0 = 1) { * }
+
+multi penny-piles($n) { penny-piles($n, 1) }
+
+multi penny-piles($n, $m where $m > $n) { [] }
+multi penny-piles($n, $m where $m == $n) { [[$n],] }
+
+multi penny-piles($n, $lower-bound) {
+ my @a;
+
+ for $lower-bound .. $n-1 -> $i {
+ @a.push(|penny-piles($n - $i, $i).map({ [ $i, |$_ ] }));
+ }
+
+ @a.push([$n]);
+
+ @a
+}
+
+multi MAIN('test') {
+ use Test;
+
+ is-deeply penny-piles(1, 1), [[1],], 'penny-piles(1, 1) => [[1],]';
+ is-deeply penny-piles(2, 2), [[2],], 'penny-piles(2, 2) => [[2],]';
+ is-deeply penny-piles(5, 5), [[5],], 'penny-piles(5, 5) => [[5],]';
+
+ is-deeply penny-piles(1), [[1],], 'penny-piles(1) => [[1],]';
+
+ is-deeply penny-piles(2, 1), [[1, 1], [2]], 'penny-piles(2, 1) => [[1, 1], [2]]';
+ is-deeply penny-piles(2), [[1, 1], [2]], 'penny-piles(2) => [[1, 1], [2]]';
+
+ is-deeply penny-piles(3, 1), [[1, 1, 1], [1, 2], [3]], 'penny-piles(3, 1) => [[1, 1, 1], [1, 2], [3]]';
+ is-deeply penny-piles(3), [[1, 1, 1], [1, 2], [3]], 'penny-piles(3) => [[1, 1, 1], [1, 2], [3]]';
+
+ is-deeply penny-piles(4), [[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2], [4]], 'penny-piles(4) => [[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2], [4]]';
+ is-deeply penny-piles(5), [[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [2, 3], [5]],
+ 'penny-piles(5) => [[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [2, 3], [5]]';
+
+ done-testing;
+}
+
+multi MAIN(UInt:D $n) {
+ put penny-piles($n).elems;
+}
diff --git a/challenge-203/feng-chang/raku/a/b/c/1/1.txt b/challenge-203/feng-chang/raku/a/b/c/1/1.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-203/feng-chang/raku/a/b/c/1/1.txt
diff --git a/challenge-203/feng-chang/raku/a/b/c/2/2.txt b/challenge-203/feng-chang/raku/a/b/c/2/2.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-203/feng-chang/raku/a/b/c/2/2.txt
diff --git a/challenge-203/feng-chang/raku/a/b/c/3/3.txt b/challenge-203/feng-chang/raku/a/b/c/3/3.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-203/feng-chang/raku/a/b/c/3/3.txt
diff --git a/challenge-203/feng-chang/raku/a/b/c/5/5.txt b/challenge-203/feng-chang/raku/a/b/c/5/5.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-203/feng-chang/raku/a/b/c/5/5.txt
diff --git a/challenge-203/feng-chang/raku/ch-1.raku b/challenge-203/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..8d609a3296
--- /dev/null
+++ b/challenge-203/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+put @N.sort.combinations(4).grep({ .[0] + .[1] + .[2] == .[3] }).elems;
diff --git a/challenge-203/feng-chang/raku/ch-2.raku b/challenge-203/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..5d6ec35da9
--- /dev/null
+++ b/challenge-203/feng-chang/raku/ch-2.raku
@@ -0,0 +1,20 @@
+#!/bin/env raku
+
+unit sub MAIN(
+ Str:D $source where *.IO.d = 'a/b/c',
+ Str:D $target where *.IO.d = 'x/y',
+);
+
+my $offset;
+
+sub copy-dirs($source, $target) {
+ for $source.IO.dir -> $file {
+ next unless $file.d;
+
+ mkdir "$target/{ $file.relative.substr($offset) }";
+ copy-dirs($file, $target);
+ }
+}
+
+$offset = $source.chars + 1;
+copy-dirs($source, $target);
diff --git a/challenge-204/feng-chang/raku/ch-1.raku b/challenge-204/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..d20f0b7537
--- /dev/null
+++ b/challenge-204/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+put +([<=] @N or [>=] @N);
diff --git a/challenge-204/feng-chang/raku/ch-2.raku b/challenge-204/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..b03c2adeef
--- /dev/null
+++ b/challenge-204/feng-chang/raku/ch-2.raku
@@ -0,0 +1,10 @@
+#!/bin/env raku
+
+unit sub MAIN();
+
+my @N = $*IN.words;
+my ($r, $c) = @N.splice(*-2);
+
+put $r * $c == +@N ??
+ (^$r).map({ "[ { @N[$c*$_ ..^ $c*($_+1)].join(' ') } ]" }).join("\n") !!
+ 0;
diff --git a/challenge-205/feng-chang/raku/ch-1.raku b/challenge-205/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..283d25297d
--- /dev/null
+++ b/challenge-205/feng-chang/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+@N = @N.sort.unique;
+put @N[*-3] // @N.tail;
diff --git a/challenge-205/feng-chang/raku/ch-2.raku b/challenge-205/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..ba75153722
--- /dev/null
+++ b/challenge-205/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+put @N.combinations(2).map({ .[0] +^ .[1] }).max;
diff --git a/challenge-206/feng-chang/raku/ch-1.raku b/challenge-206/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..d1679698b7
--- /dev/null
+++ b/challenge-206/feng-chang/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/bin/env raku
+
+unit sub MAIN(*@T);
+
+my $today = now.Date;
+my $tomorrow = $today.later(days => 1);
+
+my @instants = @T.map({ "{$today.yyyy-mm-dd}T{$_}:00".DateTime });
+@instants.push($_) for @T.map({ "{$tomorrow.yyyy-mm-dd}T{$_}:00".DateTime });
+@instants .= sort;
+
+put (^(+@instants-1)).map({ (@instants[$_+1] - @instants[$_]) / 60 }).min;
diff --git a/challenge-206/feng-chang/raku/ch-2.raku b/challenge-206/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..08056bb905
--- /dev/null
+++ b/challenge-206/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N where +* %% 2);
+
+put @N.sort[0, 2 ... (+@N-2)].sum;
diff --git a/challenge-207/feng-chang/raku/ch-1.raku b/challenge-207/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..cd6e9ecc55
--- /dev/null
+++ b/challenge-207/feng-chang/raku/ch-1.raku
@@ -0,0 +1,7 @@
+#!/bin/env raku
+
+unit sub MAIN(*@words);
+
+my %AtRow = <qwertyuiop asdfghjkl zxcvbnm>.map({ .comb.all => $++ });
+
+put @words.grep({ [==] %AtRow{ .lc.comb } });
diff --git a/challenge-207/feng-chang/raku/ch-2.raku b/challenge-207/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..47315c561d
--- /dev/null
+++ b/challenge-207/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+put (+@N...1).first(-> \m { @N.grep(* ≥ m) ≥ m });
diff --git a/challenge-208/feng-chang/raku/ch-1.raku b/challenge-208/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..5d36026336
--- /dev/null
+++ b/challenge-208/feng-chang/raku/ch-1.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+sub min-index-sum(@list1, @list2) {
+ my %hash1 = @list1 Z=> ^+@list1;
+ my %hash2 = @list2 Z=> ^+@list2;
+ my @common = (%hash1.keys (&) %hash2.keys).keys;
+ my $min-index = @common.map({ %hash1{$_} + %hash2{$_} }).min;
+
+ @common.grep({ %hash1{$_} + %hash2{$_} == $min-index }).sort
+}
+
+multi MAIN('test') {
+ use Test;
+
+ is-deeply min-index-sum(<Perl Raku Love>, <Raku Perl Hate>), <Perl Raku>, 'example 1 matches';
+ is-deeply min-index-sum(<A B C>, <D E F>), < >, 'example 2 matches';
+ is-deeply min-index-sum(<A B C>, <C A B>), ('A',), 'example 3 matches';
+
+ done-testing;
+}
+
+multi MAIN() {
+ put min-index-sum(|$*IN.lines[0, 1].map({ .words.Array }));
+}
diff --git a/challenge-208/feng-chang/raku/ch-2.raku b/challenge-208/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..5d85033739
--- /dev/null
+++ b/challenge-208/feng-chang/raku/ch-2.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@N);
+
+put "Duplicate: { @N.Bag.grep({ .value > 1 }).Hash.keys || 'null' } and ",
+ "Missing: { ((@N[0] .. +@N) (-) @N».Int) || 'null' }";