Last active
August 29, 2015 14:01
-
-
Save carlwiedemann/39d3ba0d34bd95be6d37 to your computer and use it in GitHub Desktop.
Given an alphabetic string via stdin, will return columnar index
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 | |
define('ALPHA', 'abcdefghijklmnopqrstuvwxyz'); | |
$pow = $sum = 0; | |
foreach (array_reverse(str_split(trim(file_get_contents('php://stdin', 'r')))) as $char) { | |
$sum += pow(strlen(ALPHA), $pow++) * (strpos(ALPHA, strtolower($char)) + 1); | |
} | |
print $sum . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment