Created
July 30, 2021 10:01
-
-
Save SamMakesCode/6609a9bc6649c5f02a41560456dace28 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
<?php | |
/** | |
* @author CMDR SamMakesCode | |
*/ | |
$phrase = "To the jewel that burns on the brow of the mother of galaxies! To the whisperer in witchspace, the siren of the deepest void! The parent's grief, the lover's woe, and the yearning of our vagabond hearts. To Raxxla!"; | |
// Remove non-alpha characters | |
$phrase = str_replace(' ', '', $phrase); | |
$phrase = str_replace('!', '', $phrase); | |
$phrase = str_replace(',', '', $phrase); | |
$phrase = str_replace('.', '', $phrase); | |
$phrase = str_replace('\'', '', $phrase); | |
// The key we're using to find stuff | |
$key = 'raxxla'; | |
// Start at position 0 | |
$positionInToast = 0; | |
// Create an array to store the characters as we go | |
$characters = []; | |
// For each character in the key... | |
foreach (str_split($key) as $character) { | |
// Get the key's character number. E.g. a = 1, b = 2 | |
$characterNumber = ord($character) - 96; | |
// Increase the position in the phrase | |
$positionInToast += $characterNumber; | |
//echo 'Position now ' . $positionInToast . "\n"; | |
// Output the character's numerical value | |
echo $character . ' = ' . $characterNumber . "\n"; | |
// Store the character we land on | |
$characters[] = str_split($phrase)[$positionInToast]; | |
} | |
echo 'Result is: ' . implode('', $characters) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment