Created
October 18, 2019 14:34
-
-
Save kerstvo/4d51955f8295ecd47b381630c216079e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$words = ['кит', 'кот', 'тик', 'кти', 'ток', 'ков']; | |
$hash = []; | |
foreach($words as $word) { | |
$lowerWord = strtolower($word); | |
$wordArray = preg_split('//u', $lowerWord, null, PREG_SPLIT_NO_EMPTY); | |
sort($wordArray); | |
$sorted = implode('',$wordArray); | |
if (!isset($hash[$sorted])) { | |
$hash[$sorted] = []; | |
} | |
$hash[$sorted][] = $word; | |
} | |
$return = max($hash); | |
if (count($return) == 1) { | |
$return = []; | |
} | |
print_r($return); | |
$result = []; | |
$direction = 1; | |
$step = 1; | |
$n = 3; | |
while($step <= $n) { | |
if ($step % 2) { | |
$direction = 1; | |
$from = 1; | |
$to = $step; | |
} else { | |
$direction = -1; | |
$from = $step; | |
$to = 1; | |
} | |
$range = range($from, $to, $direction); | |
$result[] = implode('-', $range); | |
$step++; | |
} | |
print_r($result); | |
$arr = [1, 5, 3, 4, 2, 2]; $k=3; | |
sort($arr); | |
$sortedArr = array_flip($arr); | |
print_r($sortedArr); | |
$pairs = []; | |
$uniquePairs = 0; | |
foreach($sortedArr as $number => $value) { | |
if (isset($sortedArr[$number + $k])) { | |
$uniquePairs++; | |
} | |
} | |
print_r($uniquePairs); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment