Skip to content

Instantly share code, notes, and snippets.

@kerstvo
Created October 18, 2019 14:34
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 kerstvo/4d51955f8295ecd47b381630c216079e to your computer and use it in GitHub Desktop.
Save kerstvo/4d51955f8295ecd47b381630c216079e to your computer and use it in GitHub Desktop.
$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