aboutsummaryrefslogtreecommitdiff
path: root/challenge-003/abigail/pascal
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-003/abigail/pascal')
-rw-r--r--challenge-003/abigail/pascal/ch-1.p48
-rw-r--r--challenge-003/abigail/pascal/ch-2.p36
2 files changed, 84 insertions, 0 deletions
diff --git a/challenge-003/abigail/pascal/ch-1.p b/challenge-003/abigail/pascal/ch-1.p
new file mode 100644
index 0000000000..79eec3a1d3
--- /dev/null
+++ b/challenge-003/abigail/pascal/ch-1.p
@@ -0,0 +1,48 @@
+Program ch1;
+
+(* *)
+(* See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out < input-file *)
+(* *)
+
+var
+ max, count, next_2, next_3, next_5: integer;
+ min, c2, c3, c5: qword;
+ ugly: array of qword;
+
+begin
+ while not eof do begin
+ readln (max);
+ setlength (ugly, max);
+
+ ugly [0] := 1;
+ count := 0;
+ next_2 := 0;
+ next_3 := 0;
+ next_5 := 0;
+ min := 0;
+
+ while count < max - 1 do begin
+ inc (count);
+
+ c2 := 2 * ugly [next_2];
+ c3 := 3 * ugly [next_3];
+ c5 := 5 * ugly [next_5];
+
+ if (c2 <= c3) and (c2 <= c5) then begin min := c2; end;
+ if (c3 <= c2) and (c3 <= c5) then begin min := c3; end;
+ if (c5 <= c2) and (c5 <= c3) then begin min := c5; end;
+
+ ugly [count] := min;
+
+ if c2 <= ugly [count] then begin inc (next_2); end;
+ if c3 <= ugly [count] then begin inc (next_3); end;
+ if c5 <= ugly [count] then begin inc (next_5); end;
+ end;
+
+ writeln (ugly [count]);
+ end
+end.
diff --git a/challenge-003/abigail/pascal/ch-2.p b/challenge-003/abigail/pascal/ch-2.p
new file mode 100644
index 0000000000..596acce61d
--- /dev/null
+++ b/challenge-003/abigail/pascal/ch-2.p
@@ -0,0 +1,36 @@
+Program ch2;
+
+(* *)
+(* See https://theweeklychallenge.org/blog/perl-weekly-challenge-003 *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *)
+(* *)
+
+var
+ max: integer;
+ row, col: integer;
+ current_row, next_row: array of integer;
+
+begin
+ while not eof do begin
+ readln (max);
+ setlength (current_row, 1);
+ current_row [0] := 1;
+ writeln (1);
+
+ for row := 1 to max do begin
+ setlength (next_row, row + 1);
+ next_row [0] := 1;
+ next_row [row] := 1;
+ write ('1 ');
+ for col := 1 to row - 1 do begin
+ next_row [col] := current_row [col - 1] + current_row [col];
+ write (next_row [col], ' ');
+ end;
+ writeln ('1');
+ current_row := next_row;
+ end
+ end
+end.