Restructuring

This commit is contained in:
2024-07-01 13:49:44 +00:00
parent f11b705ef0
commit 8d60e1b905
194 changed files with 1296 additions and 112 deletions

View File

@ -0,0 +1,14 @@
title: Integer right triangles
url: http://projecteuler.net/problem=41
desc: |
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
solution: |
Bruteforce
solutions:
solve.php:
desc: Basic solution
language: php

View File

@ -0,0 +1,27 @@
<?php
function pandigital_less($number) {
$array = count_chars($number,1);
foreach(range(1,count($array)) as $char) {
if( $array[ord($char)]!== 1) return false;
}
return true;
}
function is_prime($prime) {
//if($prime%2 == 0) return false;
$sqrt = sqrt($prime);
for ($i = 3; $i <= $sqrt; $i+=2){
if ($prime%$i == 0) return false;
}
return true;
}
//We don't need to check uneven numbers
//Has to start with a 7 and therefor be 7 digits long
for($var = 7000001; $var < 8000000; $var=$var+2) {
if(is_prime($var) AND pandigital_less($var)) { $result = $var; }
}
echo $result;