Skip to content

Instantly share code, notes, and snippets.

@jayzalowitz
Created January 27, 2013 00:06
Show Gist options
  • Save jayzalowitz/4645402 to your computer and use it in GitHub Desktop.
Save jayzalowitz/4645402 to your computer and use it in GitHub Desktop.
The solution to "Beautiful Strings" on facebook's hackers cup in php https://www.facebook.com/hackercup/problems.php?pid=475986555798659&round=185564241586420
<?php
$case = 0;
$filename = "beautiful_stringstxt";
$facebook = file($filename, FILE_IGNORE_NEW_LINES);
foreach($facebook as $line)
{
$linebeauty = 0;
if (!($case == 0)){
$stack = array();
$line = strtolower(preg_replace('/[^a-z]+/i', '', $line));
$linechars = count_chars($line, 1);
foreach($linechars as $letter => $amount){
array_push($stack, $amount);
}
arsort($stack);
$currentbeauty = 26;
foreach($stack as $letter){
$letterval = $letter * $currentbeauty;
$linebeauty = $linebeauty+$letterval;
$currentbeauty--;
}
echo 'Case #'.$case.': '.$linebeauty. PHP_EOL;
}
$case++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment