aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/abigail/ruby/ch-2.rb
blob: 9177342a45c483a7549b8aa771ec560b1145847a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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