Solved a few more problems
003: php 005: php, ruby 006: php, ruby, c
This commit is contained in:
17
ProjectEuler/005/desc.yml
Normal file
17
ProjectEuler/005/desc.yml
Normal file
@ -0,0 +1,17 @@
|
||||
title: What is the smallest number divisible by each of the numbers 1 to 20?
|
||||
url: http://projecteuler.net/problem=5
|
||||
|
||||
desc: |
|
||||
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
|
||||
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||
|
||||
solution: |
|
||||
See code
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
12
ProjectEuler/005/solve.php
Normal file
12
ProjectEuler/005/solve.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
for($i=20;true;$i+=20) {
|
||||
$div = 19;
|
||||
|
||||
while(!($i % $div)) {
|
||||
$div--;
|
||||
if($div == 0) {
|
||||
echo $i;
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
10
ProjectEuler/005/solve.rb
Normal file
10
ProjectEuler/005/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
|
Reference in New Issue
Block a user