From 230faba60842d2658ed110413ece5974a1213038 Mon Sep 17 00:00:00 2001 From: ikselven Date: Wed, 12 Apr 2017 02:11:14 +0200 Subject: [PATCH] added naive impletation for project euler problem 87 in php --- 2017-04-11/ikselven_euler87-foreach.php | 35 ++++++++++++++++++++++++ 2017-04-11/ikselven_euler87.php | 36 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 2017-04-11/ikselven_euler87-foreach.php create mode 100755 2017-04-11/ikselven_euler87.php diff --git a/2017-04-11/ikselven_euler87-foreach.php b/2017-04-11/ikselven_euler87-foreach.php new file mode 100755 index 0000000..f1dd008 --- /dev/null +++ b/2017-04-11/ikselven_euler87-foreach.php @@ -0,0 +1,35 @@ +#!/usr/bin/php += MAX) { + break; + } + + foreach($primes as $middle) { + $cube = $fourth + $middle ** 3; + if ($cube >= MAX) { + break; + } + + foreach($primes as $inner) { + $sum = $cube + $inner ** 2; + if ($sum >= MAX) { + break; + } + $sums[] = $sum; + } + } +} + +echo "Found ".count(array_unique($sums))." numbers\n"; diff --git a/2017-04-11/ikselven_euler87.php b/2017-04-11/ikselven_euler87.php new file mode 100755 index 0000000..c3fa136 --- /dev/null +++ b/2017-04-11/ikselven_euler87.php @@ -0,0 +1,36 @@ +#!/usr/bin/php += MAX) { + break; + } + + for($middle = 0; $middle < $primeCount; $middle++) { + $cube = $fourth + $primes[$middle] ** 3; + if ($cube >= MAX) { + break; + } + + for($inner = 0; $inner < $primeCount; $inner++) { + $sum = $cube + $primes[$inner] ** 2; + if ($sum >= MAX) { + break; + } + $sums[] = $sum; + } + } +} + +echo "Found ".count(array_unique($sums))." numbers\n";