aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-111/abigail/README.md1
-rw-r--r--challenge-111/abigail/ruby/ch-2.rb34
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md
index eb38f91e14..ac8ba329ad 100644
--- a/challenge-111/abigail/README.md
+++ b/challenge-111/abigail/README.md
@@ -57,6 +57,7 @@ to standard output. In case of ties, we print the first one found.
* [Node.js](node/ch-2.js)
* [Perl](perl/ch-2.pl)
* [Python](python/ch-2.py)
+* [Ruby](ruby/ch-2.rb)
### Blog
diff --git a/challenge-111/abigail/ruby/ch-2.rb b/challenge-111/abigail/ruby/ch-2.rb
new file mode 100644
index 0000000000..afe0361969
--- /dev/null
+++ b/challenge-111/abigail/ruby/ch-2.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-2.rb < input-file
+#
+
+#
+# Create a pattern to match words with their characters in
+# lexicographical order.
+#
+pat = "^"
+("a" .. "z") . each do
+ |letter|
+ pat += letter + "*"
+end
+pat += "$"
+
+
+#
+# Find matching words, and remember the longest.
+#
+longest = ""
+ARGF . each_line do
+ |line|
+ if line . downcase =~ /#{pat}/ && line . length > longest . length
+ longest = line
+ end
+end
+
+puts (longest)