aboutsummaryrefslogtreecommitdiff
path: root/challenge-135/abigail/ruby/ch-1.rb
blob: 508907eb974a71ca6cb4864f13ae6d58032c4cc5 (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
#!/usr/bin/ruby

#
# See ../README.md
#
 
#
# Run as: ruby ch-1.rb < input-file
#

ARGF . each_line do
    | line |
    line = line . strip() . gsub(/^[-+]/, "")
    ll   = line . length
    if line . match (/[^0-9]/) then
        puts ("not an integer")
    elsif ll % 2 == 0 then
        puts ("even number of digits")
    elsif ll < 3 then
        puts ("too short")
    else
        puts (line [((ll - 3) / 2) . to_i .. ((ll + 2) / 2) . to_i])
    end
end