Solved ProjectEuler/004

This commit is contained in:
FuryFire 2012-03-01 14:01:08 +01:00
parent 46c2a0b087
commit 15e919438d
3 changed files with 40 additions and 0 deletions

17
ProjectEuler/004/desc.yml Normal file

@ -0,0 +1,17 @@
title: Find the largest palindrome made from the product of two 3-digit numbers.
url: http://projecteuler.net/problem=4
desc: |
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.
solution: |
See code
solutions:
solve.php:
desc: Basic solution
language: php
solve.rb:
desc: Basic solution in Ruby
language: ruby

@ -0,0 +1,13 @@
<?php
$max = 0;
for($num1 = 1000; $num1>100; $num1--) {
for($num2 = 1000; $num2>100; $num2--) {
$sum = $num1 * $num2;
//Check if palindrome
if($sum > $max AND strrev($sum) == $sum)
$max = $sum;
}
}
echo $max;

10
ProjectEuler/004/solve.rb Normal file

@ -0,0 +1,10 @@
max = 0;
(100..1000).each do |num1|
(100..1000).each do |num2|
sum = num1 * num2
if( sum > max and sum.to_s.reverse == sum.to_s)
max = sum
end
end
end
print max