aboutsummaryrefslogtreecommitdiff
path: root/challenge-137/laurent-rosenfeld/ruby/ch-2.rb
blob: 1baf7c046c4d48a64ef57294e89f1c85a012eb98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /usr/bin/ruby

def is_lychrel(m)
    n = m
    for k in 1..500
        j = n.to_s.reverse.to_i
        if j == n then
            return 0
        end
        n += j
        if n > 10000000 then
            return "#{m} is  a Lychrel candidate (reached the 1e7 limit)"
        end
    end
    return "#{m} is a lychrel candidate (made 500 iterations)"
end

for test in [10, 20, 30, 50, 100, 196]
    print  "#{test} -> ", is_lychrel(test), "\n"
end