diff options
| author | Márton Polgár <37218286+2colours@users.noreply.github.com> | 2024-06-29 10:48:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-29 10:48:47 +0200 |
| commit | 9aa6e31bc00b9e4ccc84de0f2b542360808ecf5a (patch) | |
| tree | 921b1a8819cc2264c7b349b916378e95c6ef3eb8 | |
| parent | 9c6ef8e490db274e7f377159bd62d9eb7a1a3042 (diff) | |
| download | perlweeklychallenge-club-9aa6e31bc00b9e4ccc84de0f2b542360808ecf5a.tar.gz perlweeklychallenge-club-9aa6e31bc00b9e4ccc84de0f2b542360808ecf5a.tar.bz2 perlweeklychallenge-club-9aa6e31bc00b9e4ccc84de0f2b542360808ecf5a.zip | |
Add solution to #2 task
| -rw-r--r-- | challenge-275/2colours/prolog/ch-2.p | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/challenge-275/2colours/prolog/ch-2.p b/challenge-275/2colours/prolog/ch-2.p new file mode 100644 index 0000000000..8da13a0b46 --- /dev/null +++ b/challenge-275/2colours/prolog/ch-2.p @@ -0,0 +1,11 @@ +task2("", ""). + +process_character(Current_Char, {last_alpha: L1, so_far: A}, {last_alpha: L2, so_far: R}) :- + number_string(Current_Offset, [Current_Char]), !, Output_Char is L1 + Current_Offset, A = [Output_Char | R], L2 = L1 ; + A = [Current_Char | R], L2 = Current_Char. + +task2(Input, Result) :- + string_codes(Input, Input_Codes), + Input_Codes = [Input_First|_], + is_alpha(Input_First), foldl(process_character, Input_Codes, {last_alpha: NULL, so_far: Result_Codes}, {last_alpha: _Whatever, so_far: []}), + string_codes(Result, Result_Codes). |
