mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-29 22:24:07 +01:00
Add the fourth problem from project Euler
Add the fourth problem from project Euler
This commit is contained in:
parent
3cca135e4e
commit
2980dd73c1
1 changed files with 11 additions and 0 deletions
11
Project Euler/Problem 4/problem4_sol1.rb
Normal file
11
Project Euler/Problem 4/problem4_sol1.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue