aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-04-30 22:44:34 +0200
committerAbigail <abigail@abigail.be>2021-04-30 22:44:34 +0200
commitc390ee8b510a56f5211dd3cca21b1934e3cdca04 (patch)
tree272e7f821dd837fc48ccb6ac3f9fce49a5a60f47
parent953655fd36dd86735774f02b092e205b2f905d9f (diff)
downloadperlweeklychallenge-club-c390ee8b510a56f5211dd3cca21b1934e3cdca04.tar.gz
perlweeklychallenge-club-c390ee8b510a56f5211dd3cca21b1934e3cdca04.tar.bz2
perlweeklychallenge-club-c390ee8b510a56f5211dd3cca21b1934e3cdca04.zip
Ruby solution for week 110, part 2
-rw-r--r--challenge-110/abigail/README.md1
-rw-r--r--challenge-110/abigail/ruby/ch-2.rb30
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md
index 679024e8bb..e70d4d7b4e 100644
--- a/challenge-110/abigail/README.md
+++ b/challenge-110/abigail/README.md
@@ -82,6 +82,7 @@ sex,m,m,f,f
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
* [Perl](perl/ch-2.pl)
+* [Ruby](ruby/ch-2.rb)
### Blog
diff --git a/challenge-110/abigail/ruby/ch-2.rb b/challenge-110/abigail/ruby/ch-2.rb
new file mode 100644
index 0000000000..9177342a45
--- /dev/null
+++ b/challenge-110/abigail/ruby/ch-2.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-2.rb < input-file
+#
+
+output = []
+
+#
+# Read the input, split on comma, build output strings.
+#
+ARGF . each_line do
+ |_|
+ _ . strip . split(/,/) . each_with_index do
+ |_, i|
+ output [i] = (output [i] || "") + _ + ","
+ end
+end
+
+#
+# Print the output strings, without the trailing commas.
+#
+output . each do
+ |_|
+ puts _ [0 .. -2]
+end