Created
August 5, 2018 07:50
-
-
Save jamalnasir/093389fc4a262eb1d6649d6586c1cc8f to your computer and use it in GitHub Desktop.
Letters Combinations
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
function everyCombination($array) { | |
try { | |
// initialize by adding the empty set | |
$results = [[]]; | |
foreach ($array as $element) { | |
$this->line($element); | |
foreach ($results as $combination) { | |
$this->info(implode('', $combination)); | |
$results[] = array_merge(array($element), $combination); | |
} | |
} | |
$response = []; | |
foreach($results as $result) | |
if(count($result) > 1) $response[] = implode('', array_reverse($result)); | |
return $response; | |
} catch(\Exception $e) { | |
dd($e->getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment