ex4
This commit is contained in:
parent
33d9932c1f
commit
2971d84187
24
ruby_algo/ex4.rb
Normal file
24
ruby_algo/ex4.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# A palindromic number reads the same both ways. The largest palindrome made from the
|
||||
# product of two 2-digit numbers is 9009 = 91 × 99.
|
||||
|
||||
# Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
|
||||
x = 0
|
||||
b = 100
|
||||
y = []
|
||||
|
||||
while b < 1000
|
||||
a = 100
|
||||
while a < 1000
|
||||
x = a * b
|
||||
x = x.to_s
|
||||
if x == x.reverse
|
||||
y << x.to_i
|
||||
end
|
||||
a += 1
|
||||
end
|
||||
b += 1
|
||||
end
|
||||
|
||||
puts y.sort.max
|
||||
|
Loading…
Reference in a new issue