diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-11-16 20:44:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-16 20:44:04 +0000 |
| commit | 3eefdfc25d4dc02acb5ac381d629f4387e21d557 (patch) | |
| tree | 5307eb82d2788afd96ed5f518f798e107cc7b32a | |
| parent | 5686877d65d9edfa938bacf078fcabedaff96812 (diff) | |
| parent | ef8a66a2f5474ad2e433c3b7f6fccbde2e6edc3c (diff) | |
| download | perlweeklychallenge-club-3eefdfc25d4dc02acb5ac381d629f4387e21d557.tar.gz perlweeklychallenge-club-3eefdfc25d4dc02acb5ac381d629f4387e21d557.tar.bz2 perlweeklychallenge-club-3eefdfc25d4dc02acb5ac381d629f4387e21d557.zip | |
Merge pull request #13036 from 2colours/branch-for-challenge-347
Branch for challenge 347
| -rw-r--r-- | challenge-347/2colours/prolog/ch-1.p | 40 | ||||
| -rw-r--r-- | challenge-347/2colours/prolog/ch-2.p | 12 |
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-347/2colours/prolog/ch-1.p b/challenge-347/2colours/prolog/ch-1.p new file mode 100644 index 0000000000..aabaed1e4b --- /dev/null +++ b/challenge-347/2colours/prolog/ch-1.p @@ -0,0 +1,40 @@ +:- use_module(library(dcg/basics)). +:- use_module(library(dcg/high_order)). +:- use_module(library(clpfd)). + + +year(Year) --> { Year in 1900..2100 }, integer(Year). + +month(1) --> `Jan`. +month(2) --> `Feb`. +month(3) --> `Mar`. +month(4) --> `Apr`. +month(5) --> `May`. +month(6) --> `Jun`. +month(7) --> `Jul`. +month(8) --> `Aug`. +month(9) --> `Sep`. +month(10) --> `Oct`. +month(11) --> `Nov`. +month(12) --> `Dec`. + +sdigit(D) --> { D in 0'1..0'9 }, digit(D). +digit_ending(0'0) --> `0th`. +digit_ending(0'1) --> `1st`. +digit_ending(0'2) --> `2nd`. +digit_ending(0'3) --> `3rd`. +digit_ending(D) --> { D in 0'4..0'9 }, digit(D), `th`. + +day_raw([D]) --> digit_ending(D). +day_raw([D1, D2]) --> sdigit(D1), digit_ending(D2). + +day(Day) --> day_raw(DR), { number_codes(Day, DR), Day in 1..31 }. + +anglo_date(Year, Month, Day) --> day(Day), ` `, month(Month), ` `, year(Year). + + +task(Str, Result) :- + string_codes(Str, Str_Codes), + phrase(anglo_date(Year, Month, Day), Str_Codes), + format_to_chars('~d-~|~`0t~d~2+-~|~`0t~d~2+', [Year, Month, Day], Result_Chars), + string_chars(Result, Result_Chars). diff --git a/challenge-347/2colours/prolog/ch-2.p b/challenge-347/2colours/prolog/ch-2.p new file mode 100644 index 0000000000..a5bc91ba35 --- /dev/null +++ b/challenge-347/2colours/prolog/ch-2.p @@ -0,0 +1,12 @@ +:- use_module(library(dcg/basics)). +:- use_module(library(dcg/high_order)). +:- use_module(library(clpfd)). + +chunk(Chunk) --> { length(Chunk, 3) ; length(Chunk, 2) }, string(Chunk). + +task(Str, Result) :- + re_replace("[ -]"/g, "", Str, Str_Stripped), + string_codes(Str_Stripped, Codes_Stripped), + once(phrase(sequence(chunk, Chunks), Codes_Stripped)), + phrase(sequence(chunk, `-`, Chunks), Result_Codes), + string_codes(Result, Result_Codes). |
