aboutsummaryrefslogtreecommitdiff
path: root/challenge-145/abigail/pascal
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.freedom.nl>2021-12-27 18:20:34 +0100
committerAbigail <abigail@abigail.freedom.nl>2021-12-29 20:19:41 +0100
commita7cfe19e7988033b8b37d4effedcf01ee203ff0e (patch)
treeab78dd124aef81b9f58ec35ca24e9b768e1d3512 /challenge-145/abigail/pascal
parent767f501835ea07823607293b532b6a0520fafc3b (diff)
downloadperlweeklychallenge-club-a7cfe19e7988033b8b37d4effedcf01ee203ff0e.tar.gz
perlweeklychallenge-club-a7cfe19e7988033b8b37d4effedcf01ee203ff0e.tar.bz2
perlweeklychallenge-club-a7cfe19e7988033b8b37d4effedcf01ee203ff0e.zip
Week 145
Diffstat (limited to 'challenge-145/abigail/pascal')
-rw-r--r--challenge-145/abigail/pascal/ch-1.p37
-rw-r--r--challenge-145/abigail/pascal/ch-2.p38
2 files changed, 75 insertions, 0 deletions
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 <string, boolean>;
+
+begin
+ while not eof do begin
+ palindromes := specialize TFPGMap <string, boolean> . 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.