aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/abigail/ruby/ch-1.rb
blob: 1164c5bdfccf757397a79fddd682325c0d704e7f (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
31
#!/usr/bin/ruby

#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
#
 
#
# Run as: ruby ch-1.rb < input-file
#

ARGF . each_line do |line|
    tree = line . strip() . split(/\|/) . map do |row|
        row . strip() . split(/ +/) . map do |x|
            x == "*" ? false : true
        end
    end
    done = false
    for d in 0 .. tree . length() - 1 do
        for i in 0 .. tree [d] . length() - 1 do
            if tree [d] [i] && !tree [d + 1] [2 * i] &&
                               !tree [d + 1] [2 * i + 1] then
                puts (d + 1)
                done = true
                break
            end
        end
        if done then
            break
        end
    end
end