From c390ee8b510a56f5211dd3cca21b1934e3cdca04 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 30 Apr 2021 22:44:34 +0200 Subject: Ruby solution for week 110, part 2 --- challenge-110/abigail/README.md | 1 + challenge-110/abigail/ruby/ch-2.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 challenge-110/abigail/ruby/ch-2.rb 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 -- cgit