This PR add solution for project euler problem 1 and problem 2.
Apart from this PR, i have questions and sugesstions for this repo:
- why not add psr-4 autoloading to composer.json file, something like:
{
"autoload": {
"psr-4": {
"TheAlgorithms\\PHP\\": "app/",
}
},
"autoload-dev": {
"psr-4": {
"TheAlgorithms\\PHP\\Tests\\": "tests/"
}
},
}
imo, it would help manage namespaces and classes.
current implementation: if i want to use factorial
function from Maths\Factorial.php
, i must require the file with:
require_once 'path/to/Factorial.php';
$x = factorial(100);
but if we use namespace, we can do:
// file: Math\Factorial.php
namespace TheAlgorithms\PHP\Maths;
function factorial($number) {
//....
}
// file: Anywhere.php
use function \TheAlgorithms\PHP\Maths\factorial;
$x = factorial(100);
or with classes and static function:
// file: Math.php
namespace TheAlgorithms\PHP;
class Math {
public static function factorial($number) {
//....
}
}
// file: Anywhere.php
use \TheAlgorithms\PHP\Math;
$x = Math::Factorial(100);
- i think it is better to use internal link in the
DIRECTORY.md
file instead of external link directly to github.
// current
## Maths
* [Absolutemax](https://github.com/TheAlgorithms/PHP/blob/master/Maths/AbsoluteMax.php)
// propose:
## Maths
* [Absolutemax](./Maths/AbsoluteMax.php)
with that, we can browse the file locally from our clonned repo.
-
what is the standard used here? i see the folder structure is kinda messy. there are lowercase folder, uppercase folder, camelcase fiename, etc. the tests folder is kinda messy too.
-
is there limit on maximal run time per function on tests? i see the project euler problem 5 taking soo much time to complete the test. would it be nice to add some rule? or do the test in parallel? also, what if changing the test with https://pestphp.com? it has simple syntax and more great expectation api to simplify the tests.
what do you think? i am happy to open a draft PR if any sugesstion is being considered.
#cmiiw #cheers :beers:
hacktoberfest-accepted