diff options
| author | Arne Sommer <arne@bbop.org> | 2025-11-15 22:13:24 +0100 |
|---|---|---|
| committer | Arne Sommer <arne@bbop.org> | 2025-11-15 22:13:24 +0100 |
| commit | 689d27db69957ece262b42891fe861d904626b56 (patch) | |
| tree | bd8961a1a9524bc930a77e39c8fae811f8502cae | |
| parent | 4175bc8a7ecc7650796f2923f84b9d3d903a2cae (diff) | |
| download | perlweeklychallenge-club-689d27db69957ece262b42891fe861d904626b56.tar.gz perlweeklychallenge-club-689d27db69957ece262b42891fe861d904626b56.tar.bz2 perlweeklychallenge-club-689d27db69957ece262b42891fe861d904626b56.zip | |
week 347 Arne Sommer
| -rw-r--r-- | challenge-347/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-347/arne-sommer/raku/ch-1.raku | 26 | ||||
| -rwxr-xr-x | challenge-347/arne-sommer/raku/ch-2.raku | 28 | ||||
| -rwxr-xr-x | challenge-347/arne-sommer/raku/format-date | 24 | ||||
| -rwxr-xr-x | challenge-347/arne-sommer/raku/format-date-try | 26 | ||||
| -rwxr-xr-x | challenge-347/arne-sommer/raku/format-phone-number | 28 |
6 files changed, 133 insertions, 0 deletions
diff --git a/challenge-347/arne-sommer/blog.txt b/challenge-347/arne-sommer/blog.txt new file mode 100644 index 0000000000..f06de5d50f --- /dev/null +++ b/challenge-347/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/format-format.html
\ No newline at end of file diff --git a/challenge-347/arne-sommer/raku/ch-1.raku b/challenge-347/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..a4d0593c3b --- /dev/null +++ b/challenge-347/arne-sommer/raku/ch-1.raku @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str where 13 >= $str.chars >= 12); + +my %months = ( + Jan => 1, Feb => 2, Mar => 3, Apr => 4, + May => 5, Jun => 6, Jul => 7, Aug => 8, + Sep => 9, Oct => 10, Nov => 11, Dec => 12 ); + +my %days = ( + '1st' => 1, '2nd' => 2, '3rd' => 3, '4th' => 4, '5th' => 5, + '6th' => 6, '7th' => 7, '8th' => 8, '9th' => 9, '10th' => 10, + '11st' => 11, '12nd' => 12, '13rd' => 13, '14th' => 14, '15th' => 15, + '16th' => 16, '17th' => 17, '18th' => 18, '19th' => 19, '20th' => 20, + '21st' => 21, '22nd' => 22, '23rd' => 23, '24th' => 24, '25th' => 25, + '26th' => 26, '27th' => 37, '28th' => 28, '29th' => 29, '30th' => 30, + '31st' => 31); + +my ($day, $month, $year) = $str.split(/\s/); + +if $year.Int && 1900 <= $year <= 2100 && %months{$month} && %days{$day} +{ + my $date = try Date.new($year, %months{$month}, %days{$day}); + + say $date if $date; +} diff --git a/challenge-347/arne-sommer/raku/ch-2.raku b/challenge-347/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..b6e0101ded --- /dev/null +++ b/challenge-347/arne-sommer/raku/ch-2.raku @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN ($phone where $phone ~~ /^ <[0 .. 9 \s -]>+ $/, + :v($verbose)); + +my $parts := gather +{ + my $current = ""; + my @todo = $phone.comb.grep: * eq any(0..9); + + say ": Digits { @todo.join }" if $verbose; + + while @todo + { + $current ~= @todo.shift; + + if $current.chars == 3 || (@todo.elems == 2 && $current.chars == 2) + { + take $current; + $current = ""; + } + } + + take $current if $current; +} + +say $parts.join("-"); + diff --git a/challenge-347/arne-sommer/raku/format-date b/challenge-347/arne-sommer/raku/format-date new file mode 100755 index 0000000000..bc2800236f --- /dev/null +++ b/challenge-347/arne-sommer/raku/format-date @@ -0,0 +1,24 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str where 13 >= $str.chars >= 12); + +my %months = ( + Jan => 1, Feb => 2, Mar => 3, Apr => 4, + May => 5, Jun => 6, Jul => 7, Aug => 8, + Sep => 9, Oct => 10, Nov => 11, Dec => 12 ); + +my %days = ( + '1st' => 1, '2nd' => 2, '3rd' => 3, '4th' => 4, '5th' => 5, + '6th' => 6, '7th' => 7, '8th' => 8, '9th' => 9, '10th' => 10, + '11st' => 11, '12nd' => 12, '13rd' => 13, '14th' => 14, '15th' => 15, + '16th' => 16, '17th' => 17, '18th' => 18, '19th' => 19, '20th' => 20, + '21st' => 21, '22nd' => 22, '23rd' => 23, '24th' => 24, '25th' => 25, + '26th' => 26, '27th' => 37, '28th' => 28, '29th' => 29, '30th' => 30, + '31st' => 31); + +my ($day, $month, $year) = $str.split(/\s/); + +if $year.Int && 1900 <= $year <= 2100 && %months{$month} && %days{$day} +{ + say $year ~ "-" ~ %months{$month}.fmt('%02d') ~ "-" ~ %days{$day}.fmt('%02d'); +} diff --git a/challenge-347/arne-sommer/raku/format-date-try b/challenge-347/arne-sommer/raku/format-date-try new file mode 100755 index 0000000000..a4d0593c3b --- /dev/null +++ b/challenge-347/arne-sommer/raku/format-date-try @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str where 13 >= $str.chars >= 12); + +my %months = ( + Jan => 1, Feb => 2, Mar => 3, Apr => 4, + May => 5, Jun => 6, Jul => 7, Aug => 8, + Sep => 9, Oct => 10, Nov => 11, Dec => 12 ); + +my %days = ( + '1st' => 1, '2nd' => 2, '3rd' => 3, '4th' => 4, '5th' => 5, + '6th' => 6, '7th' => 7, '8th' => 8, '9th' => 9, '10th' => 10, + '11st' => 11, '12nd' => 12, '13rd' => 13, '14th' => 14, '15th' => 15, + '16th' => 16, '17th' => 17, '18th' => 18, '19th' => 19, '20th' => 20, + '21st' => 21, '22nd' => 22, '23rd' => 23, '24th' => 24, '25th' => 25, + '26th' => 26, '27th' => 37, '28th' => 28, '29th' => 29, '30th' => 30, + '31st' => 31); + +my ($day, $month, $year) = $str.split(/\s/); + +if $year.Int && 1900 <= $year <= 2100 && %months{$month} && %days{$day} +{ + my $date = try Date.new($year, %months{$month}, %days{$day}); + + say $date if $date; +} diff --git a/challenge-347/arne-sommer/raku/format-phone-number b/challenge-347/arne-sommer/raku/format-phone-number new file mode 100755 index 0000000000..b6e0101ded --- /dev/null +++ b/challenge-347/arne-sommer/raku/format-phone-number @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN ($phone where $phone ~~ /^ <[0 .. 9 \s -]>+ $/, + :v($verbose)); + +my $parts := gather +{ + my $current = ""; + my @todo = $phone.comb.grep: * eq any(0..9); + + say ": Digits { @todo.join }" if $verbose; + + while @todo + { + $current ~= @todo.shift; + + if $current.chars == 3 || (@todo.elems == 2 && $current.chars == 2) + { + take $current; + $current = ""; + } + } + + take $current if $current; +} + +say $parts.join("-"); + |
