Created
September 22, 2017 14:55
-
-
Save subins2000/1974ee8136c2ae08e269be6ed9d9af45 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/** | |
* @author Subin Siby <subinsb.com> | |
*/ | |
function getInput() | |
{ | |
return trim(fgets(STDIN)); | |
} | |
function getResult($i) | |
{ | |
$s = explode("\n", $i); | |
$words = $s[0]; | |
$length = $s[1]; | |
preg_match_all('/([a-z|A-Z|\.|\s])=\s(.*?)[,|\z]/', $words, $matches, PREG_SET_ORDER); | |
$letters = []; | |
foreach($matches as $match) { | |
$positions = explode(' ', $match[2]); | |
foreach ($positions as $position) { | |
$letters[$position] = $match[1]; | |
} | |
} | |
ksort($letters); | |
return implode('', $letters); | |
} | |
echo 'Enter file path:'; | |
$i = getInput(); | |
echo 'Your string:' . PHP_EOL . getResult(file_get_contents($i)) . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment