Solved ProjectEuler/016: php, ruby
This commit is contained in:
@ -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
|
||||
|
||||
desc: |
|
||||
|
17
ProjectEuler/016/desc.yml
Normal file
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
|
7
ProjectEuler/016/solve.php
Normal file
7
ProjectEuler/016/solve.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$num = bcpow(2,1000);
|
||||
$sum = 0;
|
||||
for($c =0; $c < strlen($num);$c++) {
|
||||
$sum += $num[$c];
|
||||
}
|
||||
echo $sum;
|
6
ProjectEuler/016/solve.rb
Normal file
6
ProjectEuler/016/solve.rb
Normal file
@ -0,0 +1,6 @@
|
||||
num = 2 ** 1000
|
||||
sum = 0
|
||||
num.to_s.chars do |digit|
|
||||
sum += digit.to_i
|
||||
end
|
||||
puts sum
|
Reference in New Issue
Block a user