Skip to content

Instantly share code, notes, and snippets.

@carlwiedemann
Last active August 29, 2015 14:01
Show Gist options
  • Save carlwiedemann/39d3ba0d34bd95be6d37 to your computer and use it in GitHub Desktop.
Save carlwiedemann/39d3ba0d34bd95be6d37 to your computer and use it in GitHub Desktop.
Given an alphabetic string via stdin, will return columnar index
<?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