From 2980dd73c123905dabd40071661dbacd7f04bbf2 Mon Sep 17 00:00:00 2001 From: Onur ER Date: Fri, 18 Oct 2019 15:33:19 +0300 Subject: [PATCH] Add the fourth problem from project Euler Add the fourth problem from project Euler --- Project Euler/Problem 4/problem4_sol1.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Project Euler/Problem 4/problem4_sol1.rb diff --git a/Project Euler/Problem 4/problem4_sol1.rb b/Project Euler/Problem 4/problem4_sol1.rb new file mode 100644 index 0000000..fb1ac24 --- /dev/null +++ b/Project Euler/Problem 4/problem4_sol1.rb @@ -0,0 +1,11 @@ +# 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. + +answer = 0 +999.downto(99) do |i| + 999.downto(99) do |j| + t = (i * j) + answer = i * j if (t.to_s == t.to_s.reverse) && (t > answer) && (t > answer) + end +end +puts answer \ No newline at end of file