aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-111/abigail/README.md1
-rw-r--r--challenge-111/abigail/ruby/ch-1.rb32
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md
index 45e924351b..b9e45903c7 100644
--- a/challenge-111/abigail/README.md
+++ b/challenge-111/abigail/README.md
@@ -38,6 +38,7 @@ languages, the fact input is sorted does not offer additional benefits.
* [Node.js](node/ch-1.js)
* [Perl](perl/ch-1.pl)
* [Python](python/ch-1.py)
+* [Ruby](ruby/ch-1.rb)
### Blog
diff --git a/challenge-111/abigail/ruby/ch-1.rb b/challenge-111/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..ed9d9d9085
--- /dev/null
+++ b/challenge-111/abigail/ruby/ch-1.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-1.rb < input-file
+#
+
+matrix_size = 5
+
+#
+# Read in the matrix
+#
+matrix = {}
+(1 .. matrix_size) . each do
+ ARGF . readline . scan(/-?[0-9]+/) do
+ |number|
+ matrix [number] = 1
+ end
+end
+
+
+#
+# Read in the rest of the numbers, and print 1/0 whether or
+# not they're present in the matrix.
+#
+ARGF . each_line do
+ |number|
+ puts (matrix [number . strip] ? 1 : 0)
+end