diff options
| author | 冯昶 <seaker@qq.com> | 2021-10-20 15:04:56 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-10-20 15:04:56 +0800 |
| commit | fb866d6d23493558f190fcdbd9a4ec165a6c1f98 (patch) | |
| tree | b06dfbab7996f9490c075279ba939db6ae5a92b0 | |
| parent | bd9970453af9d7b5feca8a2be7646c30b358b1a5 (diff) | |
| download | perlweeklychallenge-club-fb866d6d23493558f190fcdbd9a4ec165a6c1f98.tar.gz perlweeklychallenge-club-fb866d6d23493558f190fcdbd9a4ec165a6c1f98.tar.bz2 perlweeklychallenge-club-fb866d6d23493558f190fcdbd9a4ec165a6c1f98.zip | |
challenge 128, raku solutions
| -rwxr-xr-x | challenge-128/feng-chang/raku/ch-1.raku | 17 | ||||
| -rwxr-xr-x | challenge-128/feng-chang/raku/ch-2.raku | 22 | ||||
| -rw-r--r-- | challenge-128/feng-chang/raku/in02.txt | 3 | ||||
| -rw-r--r-- | challenge-128/feng-chang/raku/input.txt | 3 | ||||
| -rw-r--r-- | challenge-128/feng-chang/raku/times.txt | 2 | ||||
| -rw-r--r-- | challenge-128/feng-chang/raku/tm02.txt | 2 |
6 files changed, 49 insertions, 0 deletions
diff --git a/challenge-128/feng-chang/raku/ch-1.raku b/challenge-128/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..367dbb470d --- /dev/null +++ b/challenge-128/feng-chang/raku/ch-1.raku @@ -0,0 +1,17 @@ +#!/bin/env raku + +my method mat-size(List:D $coords where *.elems() == 4: --> UInt:D) { + ($coords[2] - $coords[0] + 1) * ($coords[3] - $coords[1] + 1) +} + +sub MAIN(Str:D $f where *.IO.e = 'input.txt') { + my Array @mat .= push($_.comb.Array) for $f.IO.lines; + + my @A = (^@mat.elems X ^@mat[0].elems X ^@mat.elems X ^@mat[0].elems) + .grep({ .[2] > .[0] and .[3] > .[1] }) + .grep({ @mat[.[0] .. .[2]; .[1] .. .[3]].all == 0 }); + my $max-size = @A.map(*.&mat-size).max; + + put "max size: $max-size"; + put @A.grep(*.&mat-size == $max-size).join("\n"); +} diff --git a/challenge-128/feng-chang/raku/ch-2.raku b/challenge-128/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..1050c46bfc --- /dev/null +++ b/challenge-128/feng-chang/raku/ch-2.raku @@ -0,0 +1,22 @@ +#!/bin/env raku + +subset TimeStr of Str where { $^s.match(/^ \d\d ':' \d\d $/) }; + +my method mytime(TimeStr:D $t: --> DateTime:D) { + state Date $date = Date.new(now); + my ($hour, $minute) = $t.split(':'); + + DateTime.new(:$date, :$hour, :$minute) +} + +sub MAIN(Str:D $f where *.IO.e = 'times.txt') { + my @lines = $f.IO.lines; + my @arrivals = @lines[0].words».&mytime; + my @departures = @lines[1].words».&mytime; + + (|@arrivals, |@departures).map(-> $t { + (^@arrivals).grep(-> $i { + @arrivals[$i] ≤ $t ≤ @departures[$i] + }).elems + }).max.put; +} diff --git a/challenge-128/feng-chang/raku/in02.txt b/challenge-128/feng-chang/raku/in02.txt new file mode 100644 index 0000000000..f8c64d269a --- /dev/null +++ b/challenge-128/feng-chang/raku/in02.txt @@ -0,0 +1,3 @@ +0011 +0001 +0010 diff --git a/challenge-128/feng-chang/raku/input.txt b/challenge-128/feng-chang/raku/input.txt new file mode 100644 index 0000000000..11c961ce70 --- /dev/null +++ b/challenge-128/feng-chang/raku/input.txt @@ -0,0 +1,3 @@ +100010 +110001 +100000 diff --git a/challenge-128/feng-chang/raku/times.txt b/challenge-128/feng-chang/raku/times.txt new file mode 100644 index 0000000000..3bdd72d4d3 --- /dev/null +++ b/challenge-128/feng-chang/raku/times.txt @@ -0,0 +1,2 @@ +11:20 14:30 +11:50 15:00 diff --git a/challenge-128/feng-chang/raku/tm02.txt b/challenge-128/feng-chang/raku/tm02.txt new file mode 100644 index 0000000000..a8ce4a8d1d --- /dev/null +++ b/challenge-128/feng-chang/raku/tm02.txt @@ -0,0 +1,2 @@ +10:20 11:00 11:10 12:20 16:20 19:00 +10:30 13:20 12:40 12:50 20:20 21:20 |
