From a7cfe19e7988033b8b37d4effedcf01ee203ff0e Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 27 Dec 2021 18:20:34 +0100 Subject: Week 145 --- challenge-145/abigail/pascal/ch-1.p | 37 ++++++++++++++++++++++++++++++++++++ challenge-145/abigail/pascal/ch-2.p | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 challenge-145/abigail/pascal/ch-1.p create mode 100644 challenge-145/abigail/pascal/ch-2.p (limited to 'challenge-145/abigail/pascal') diff --git a/challenge-145/abigail/pascal/ch-1.p b/challenge-145/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..2644e9aa0b --- /dev/null +++ b/challenge-145/abigail/pascal/ch-1.p @@ -0,0 +1,37 @@ +Program XXX; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out < input-file *) +(* *) + +var + n, size, j, half, sum: integer; + numbers: array of integer; + +begin + (* *) + (* Read in data into a single array *) + (* *) + size := 0; + while not eof do begin + read (n); + inc (size); + setlength (numbers, size); + numbers [size - 1] := n; + end; + + (* *) + (* Calculate the dot product *) + (* *) + sum := 0; + half := (size - 1) div 2; + for j := 0 to half do begin + sum := sum + numbers [j] * numbers [half + j]; + end; + + writeln (sum); +end. diff --git a/challenge-145/abigail/pascal/ch-2.p b/challenge-145/abigail/pascal/ch-2.p new file mode 100644 index 0000000000..f7328d3a0d --- /dev/null +++ b/challenge-145/abigail/pascal/ch-2.p @@ -0,0 +1,38 @@ +Program ch2; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *) +(* *) + +uses + StrUtils, fgl; + +var + line: string; + i, j: integer; + substr: string; + palindromes: specialize TFPGMap ; + +begin + while not eof do begin + palindromes := specialize TFPGMap . Create; + readln (line); + for i := 1 to length (line) do begin + for j := i to length (line) do begin + substr := copy (line, i, j - i + 1); + if substr = ReverseString (substr) then begin + if palindromes . IndexOf (substr) = -1 then begin + write (substr, ' '); + palindromes . Add (substr, true); + end + end + end + end; + writeln (''); + palindromes . Free; + end +end. -- cgit