aboutsummaryrefslogtreecommitdiff
path: root/challenge-111
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-05 19:27:27 +0200
committerAbigail <abigail@abigail.be>2021-05-05 19:28:36 +0200
commit2c150e6910dc6acf7a564528f9c4a4dcdc97d02e (patch)
treeac41db62c818a6794c2ebf91a3315b9564ea8316 /challenge-111
parent8accc8d37c66240bd90b57e1a9e53d94ec3845c9 (diff)
downloadperlweeklychallenge-club-2c150e6910dc6acf7a564528f9c4a4dcdc97d02e.tar.gz
perlweeklychallenge-club-2c150e6910dc6acf7a564528f9c4a4dcdc97d02e.tar.bz2
perlweeklychallenge-club-2c150e6910dc6acf7a564528f9c4a4dcdc97d02e.zip
Pascal solution for week 111, part 2
Diffstat (limited to 'challenge-111')
-rw-r--r--challenge-111/abigail/README.md1
-rw-r--r--challenge-111/abigail/pascal/ch-2.p44
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md
index aa834f7ed9..978fa5fdee 100644
--- a/challenge-111/abigail/README.md
+++ b/challenge-111/abigail/README.md
@@ -84,6 +84,7 @@ to standard output. In case of ties, we print the first one found.
* [C](c/ch-2.c)
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
+* [Pascal](pascal/ch-2.p)
* [Perl](perl/ch-2.pl)
* [Python](python/ch-2.py)
* [Ruby](ruby/ch-2.rb)
diff --git a/challenge-111/abigail/pascal/ch-2.p b/challenge-111/abigail/pascal/ch-2.p
new file mode 100644
index 0000000000..d4fcf5919b
--- /dev/null
+++ b/challenge-111/abigail/pascal/ch-2.p
@@ -0,0 +1,44 @@
+Program OrderedLetters;
+
+(* *)
+(* See ../README.md *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *)
+(* *)
+
+uses sysutils;
+
+var
+ line, longest: string;
+ ch, prev_ch: char;
+ valid: boolean;
+
+begin
+ longest := '';
+ while not eof () do
+ begin
+ readln (line);
+ valid := true;
+ prev_ch := ' '; (* Any char less than 'a' will do *)
+
+ (* Iterate over the characters of the lowercased string; *)
+ (* if the character isn't a lowercase letter, or the character *)
+ (* is less than the previous, it's not a valid candidate. *)
+ for ch in lowercase (line) do
+ begin
+ if (ch < 'a') or (ch > 'z') or (ch < prev_ch) then
+ begin
+ valid := false;
+ break;
+ end;
+ prev_ch := ch;
+ end;
+ if valid and (length (line) > length (longest)) then
+ begin
+ longest := line;
+ end;
+ end;
+ writeln (longest);
+end.