From 2971d84187196f3167dfc1cda399b12fac77c313 Mon Sep 17 00:00:00 2001 From: piks3l Date: Mon, 31 Jul 2017 21:56:50 +0200 Subject: [PATCH] ex4 --- ruby_algo/ex4.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ruby_algo/ex4.rb diff --git a/ruby_algo/ex4.rb b/ruby_algo/ex4.rb new file mode 100644 index 0000000..1db4984 --- /dev/null +++ b/ruby_algo/ex4.rb @@ -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 +