Skip to content

Instantly share code, notes, and snippets.

@Thirdwrist
Created March 30, 2021 15:02
Show Gist options
  • Save Thirdwrist/92b681d361ae2c846c0c74517eb01d00 to your computer and use it in GitHub Desktop.
Save Thirdwrist/92b681d361ae2c846c0c74517eb01d00 to your computer and use it in GitHub Desktop.
$str = "The lazy dog jumped over the fox";
function using_recursion($val) {
$posRes = strrpos($val, ' ');
if ($posRes !== FALSE) {
echo substr($val, $posRes);
using_recursion(substr($val, 0, $posRes));
}
else {
echo " $val";
}
}
function newOne($rr)
{
$val = 0;
foreach ($rr as $r)
{
if($val === 0)
{
$val = octdec(decoct($r));
}else{
$val += octdec(decoct($r));
}
}
return decoct($val);
}
function newTwo($rr)
{
$val = 0;
foreach ($rr as $r)
{
$val += octdec($r);
}
return decoct($val);
}
function three($arr)
{
$arr = str_split($arr);
$arrUnique = array_unique($arr);
$duplicate = array_diff($arrUnique, $arr);
$result = [];
$int =0;
$result[$int] ='' ;
foreach ($arr as $ar)
{
if(in_array($ar, $duplicate) && substr_count($result[$int],$ar) === 2 ){
++$int;
}
else{
$result[$int] .=$result[$int];
}
}
return $result;
}
function Test() {
static $x = 0;
echo $x;
$x++;
}
function testNine($s, $wordDict)
{
$s = strtolower($s);
$finalWordDic=[];
foreach($wordDict as $value)
{
$finalWordDic[] = strtolower($value);
}
$count = strlen($s);
$data =[];
for($pointer = 1; $pointer <= $count; ++$pointer)
{
$first = substr($s, 0, $num = -($count - $pointer));
$second = substr($s, $pointer);
if(in_array($first, $finalWordDic) && in_array($second, $finalWordDic)){
return true;
}
}
return false;
}
function solution($s, $wordDict)
{
$s = strtolower($s);
$finalWordDic = array_map('strtolower', $wordDict);
$count = strlen($s);
for($pointer = 1; $pointer <= $count; ++$pointer)
{
$first = substr($s, 0, $num = -($count - $pointer));
$second = substr($s, $pointer);
if(in_array($first, $finalWordDic) && in_array($second, $finalWordDic)){
return true;
}
}
return false;
}
function solutionOne($arr)
{
$arrDuplicate = array_count_values($arr);
foreach($arrDuplicate as $key => $value)
{
if($value === 1)
return $key;
}
}
function solutionTwo($str)
{
$arr = str_split($str);
$bracesMatched = [
'<' => [
'open'=> '<',
'close'=> '>',
],
'('=> [
'open'=> '(',
'close'=> ')'
],
'{'=>[
'open'=>'{',
'close'=> '}'
],
'['=>[
'open'=> '[',
'close'=>']'
]
];
$arrCount = count($arr);
if($arrCount % 2 !== 0)
{
return "modulus";
}
$count =count($arr);
$end = null;
foreach ($arr as $key => $item)
{
if($count === $key)
return true;
if((($count / 2)-1) === ($key - 1) && $end)
return true;
if($bracesMatched[$item]['close'] !== $arr[$key + 1] && $bracesMatched[$item]['close'] !== $arr[$count - ($key + 1)])
return [
"check",
$bracesMatched[$item]['close'] !== $arr[$key + 1],
$bracesMatched[$item]['close'] !== $arr[$count - ($key + 1)],
$bracesMatched[$item]['close'],
$arr[$key + 1],
$arr[$count - ($key+1)],
$key,
$count, $arr
];
$end = $bracesMatched[$item]['close'] !== $arr[$count - ($key + 1)];
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment