Skip to content

Instantly share code, notes, and snippets.

@fakeheal
fakeheal / PHP: Longest Collatz sequence.php
Last active August 29, 2015 14:08
PHP: Large sumLongest Collatz sequence - ProjectEuler Problem #14
<?php
function sequence($start, $step = 0)
{
while($start != 1)
{
if($start % 2 == 0)
$start = $start / 2;
else
$start = 3*$start + 1;
$step++;
@fakeheal
fakeheal / PHP: Large sum.php
Last active August 29, 2015 14:08
PHP: Large sum - ProjectEuler Problem #13
<?php
$new = explode("\n", $number);
$sum = 0;
foreach($new as $n){
$sum += trim($n);
}
echo $sum;
@fakeheal
fakeheal / PHP: Highly divisible triangular number.php
Last active April 14, 2016 07:48
PHP: Highly divisible triangular number (ProjectEuler Problem #12)
<?php
function countDivisors($number)
{
$count = 0;
$sqrtOfNumber = (int)sqrt($number);
for($i = 1; $i <= $sqrtOfNumber; $i++)
{
if($number % $i == 0)
$count += 2;