Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 5, 2020 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/523e69ba1a002146e63d51e225ec9b85 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/523e69ba1a002146e63d51e225ec9b85 to your computer and use it in GitHub Desktop.
Just PHP FUN 016.
<?php
# https://www.codewars.com/kata/55caef80d691f65cb6000040 Geometric Progression Sequence.
function geometric_sequence_elements(int $a, int $r, int $n): string {
$get = function() use ($a,$r,$n){
$tmp = $a;
for($i=0; $i<$n; $i += 1){
yield $tmp;
$tmp *= $r;
}
};
return implode(", ",iterator_to_array($get()));
}
<?php
# https://www.codewars.com/kata/56484848ba95170a8000004d Speed Control.
function gps($s, $x) {
$size = count($x);
$answer = [];
for($i=1; $i < $size; $i += 1){
$answer[] = (3600 * ($x[$i]-$x[$i-1]))/$s;
}
return floor(max($answer));
}
<?php
# https://www.codewars.com/kata/58d3487a643a3f6aa20000ff MinMinMax.
function minMinMax($array) {
$min = min($array);
$max = max($array);
$tmp = array_flip($array);
$min2 = 0;
for($i = $min+1; $i < $max; $i += 1){
if(! isset($tmp[$i])){
$min2 = $i;
break;
}
}
return [$min,$min2,$max];
}
<?php
# https://www.codewars.com/kata/566fc12495810954b1000030 Count the Digit.
function nbDig($n, $d) {
$ans = 0;
for($i = 0; $i <= $n; $i++){
$ans += substr_count($i*$i,$d);
}
return $ans;
}
<?php
function wallPaper($l, $w, $h) {
$ans = ['zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
'eleven',
'twelve',
'thirteen',
'fourteen',
'fifteen',
'sixteen',
'seventeen',
'eighteen',
'nineteen',
'twenty'];
$total = 2*($l+$w)*$h*1.15 / (10*0.52);
$number = ceil($total);
//echo "number = $number ($total) \n";
return $ans[$number];
}
@lbvf50mobile
Copy link
Author

current(array_diff(range($min, $max), $array))

https://www.codewars.com/users/Pcheliakov

@lbvf50mobile
Copy link
Author

@lbvf50mobile
Copy link
Author

$seq[] = $a *= $r;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment