Solved ProjectEuler/016: php, ruby

This commit is contained in:
FuryFire 2012-03-09 10:43:52 +01:00
parent 0dc93ee0ee
commit 58f1e0c541
4 changed files with 31 additions and 1 deletions

@ -1,4 +1,4 @@
title: Find the longest sequence using a starting number under one million. title: Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
url: http://projecteuler.net/problem=15 url: http://projecteuler.net/problem=15
desc: | desc: |

17
ProjectEuler/016/desc.yml Normal file

@ -0,0 +1,17 @@
title: What is the sum of the digits of the number 2^1000?
url: http://projecteuler.net/problem=16
desc: |
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
solution: |
Bruteforce
solutions:
solve.php:
desc: Using BCMath to cope with large numbers
language: php
solve.rb:
desc: Basic solution
language: ruby

@ -0,0 +1,7 @@
<?php
$num = bcpow(2,1000);
$sum = 0;
for($c =0; $c < strlen($num);$c++) {
$sum += $num[$c];
}
echo $sum;

@ -0,0 +1,6 @@
num = 2 ** 1000
sum = 0
num.to_s.chars do |digit|
sum += digit.to_i
end
puts sum