Few code standards. Remove composer vendor folder
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
function pandigital($num) {
|
||||
function pandigital(int $num): bool {
|
||||
for ($i = 1; $i <= 9; $i++) {
|
||||
if(strpos($n,(string)$i) === false) {
|
||||
return false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
function fibonacci($n) {
|
||||
function fibonacci(int $n) : int {
|
||||
if ($n <= 1)
|
||||
return $n;
|
||||
return fibonacci($n - 1) + fibonacci($n - 2);
|
||||
|
@ -6,6 +6,9 @@ $sum = (int)$argv[1];
|
||||
$input_numbers = array_slice($argv, 2);
|
||||
$operation = ['+','-','*','/'];
|
||||
|
||||
if(sizeof($input_numbers) < 2)
|
||||
die();
|
||||
|
||||
$best_diff = $sum;
|
||||
while($best_diff != 0) {
|
||||
shuffle($input_numbers);
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
function primeCheck($number){
|
||||
function primeCheck(int $number): bool {
|
||||
if ($number == 1)
|
||||
return 0;
|
||||
return false;
|
||||
for ($i = 2; $i <= $number/2; $i++){
|
||||
if ($number % $i == 0)
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
$sum = 0;
|
||||
|
19
solutions/other/reverseWords.php
Normal file
19
solutions/other/reverseWords.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
function reverseWords(string $str): string
|
||||
{
|
||||
$words = explode(' ', $str);
|
||||
$words = array_reverse($words);
|
||||
return implode(' ', $words);
|
||||
}
|
||||
|
||||
function reverseWords2(string $str): string
|
||||
{
|
||||
$words = explode(' ', $str);
|
||||
foreach ($words as &$word) {
|
||||
$word = strrev($word);
|
||||
}
|
||||
return implode(' ', $words);
|
||||
}
|
||||
|
||||
echo reverseWords("The lazy dog") . PHP_EOL;
|
||||
echo reverseWords2("The lazy dog") . PHP_EOL;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
//Find a three-digit number such that when the digits are reversed and subtracted from the original number, the result is a multiple of 9.
|
||||
function numreverse($number) {
|
||||
function numreverse(int $number): int {
|
||||
|
||||
$numberStr = (string)$number;
|
||||
$numberStr = strrev($numberStr);
|
||||
|
15
solutions/other/sequence.php
Normal file
15
solutions/other/sequence.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
$num = 44;
|
||||
|
||||
for($i=0; $i<20; $i++)
|
||||
{
|
||||
$sum = 0;
|
||||
$number = (string)$num;
|
||||
for($c=0; $c < strlen($number);$c++)
|
||||
{
|
||||
$sum +=(int)$number[$c] * (int)$number[$c];
|
||||
}
|
||||
echo $sum . PHP_EOL;
|
||||
$num = $sum;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
//12857 multiplied by 7 gives 90099, and the sum of the digits of 90099 is indeed 27, not 44. Keep trying!
|
||||
|
||||
function sumDigits($number) {
|
||||
function sumDigits(int $number): int {
|
||||
$sum = 0;
|
||||
// converting number to string to access digits easily
|
||||
$numberStr = (string)$number;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
//Write a function to find the smallest number that is divisible by each of the numbers from 1 to 20.
|
||||
|
||||
function sumdiv20() {
|
||||
function sumdiv20(): int {
|
||||
$i = 20;
|
||||
while(true) {
|
||||
$i += 20;
|
||||
|
Reference in New Issue
Block a user