Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 20, 2020 15: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/322df4119e162bd51e329b58ad1f2684 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/322df4119e162bd51e329b58ad1f2684 to your computer and use it in GitHub Desktop.
Just PHP FUN 029.
<?php
# https://www.codewars.com/kata/5558cc216a7a231ac9000022 Find Duplicates.
function duplicates($arr) {
echo implode(",",$arr)."\n";
$h = []; $ans = [];
foreach($arr as $v){
$key = key_($v);
if(!isset($h[$key])) $h[$key] = 0;
$h[$key] += 1;
if(2 == $h[$key]) array_push($ans,$v);
}
return $ans;
}
function key_($v){
return strval($v).gettype($v);
}
<?php
# https://www.codewars.com/kata/59a96d71dbe3b06c0200009c Build a square.
function generateShape($int) {
return trim(str_repeat(str_repeat('+',$int)."\n", $int));
}
<?php
# https://www.codewars.com/kata/54ff3102c1bad923760001f3 Vowel Count.
function getCount($str) {
return preg_match_all('/[aeiou]/',$str);
}
<?php
# https://www.codewars.com/kata/5822d89270ca28c85c0000f3 String Scramble.
function scramble($str,$arr){
$ans = array_combine($arr,str_split($str));
ksort($ans);
return implode($ans);
}
# Dzienny, parezzz, Yuno_Gassai
# -----------------------------------------------------------------------
function scramble($str,$arr){
$ans = array_fill(0,count($arr),"");
foreach($arr as $k => $v) $ans[$v] = $str[$k];
return implode($ans);
}
<?php
# https://www.codewars.com/kata/586f6741c66d18c22800010a Sum of a sequence.
function sequence_sum(int $begin, int $end, int $step): int {
echo "$begin, $end, $step \n";
if($begin > $end) return 0;
echo "Count: \n";
if($step+$begin > $end) return $begin;
$ans = array_sum(range($begin,$end,$step));
echo "$ans \n";
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment