Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created July 8, 2017 09:27
<?php
function is_prime($number) {
for($i=2;$i<=sqrt($number)+1;$i++) {
if($number % $i == 0) {
return false;
}
}
return true;
}
function add_number($number) {
$str = (string)$number;
$sum = 0;
for($index=0;$index<strlen($str);$index++) {
$sum += (int)$str{$index};
}
return $sum;
}
$range = range(1000000, 2000000);
$count = 0;
foreach($range as $num) {
if(is_prime($num) && is_prime(add_number($num))) {
if($count < 2) {
echo $num;
echo PHP_EOL;
$count += 1;
} else {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment