Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 29, 2020 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/26154ac0c22a663e1a3958302bfab253 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/26154ac0c22a663e1a3958302bfab253 to your computer and use it in GitHub Desktop.
Just PHP FUN 115.
<?php
# https://www.codewars.com/kata/57eb8fcdf670e99d9b000272 Highest Scoring Word.
function high($x) {
$x = array_map(function($x){ return [$x,the_sum($x)];},explode(" ",$x));
$max = ["",0];
foreach($x as $pair) if($pair[1] > $max[1]) $max = $pair;
return $max[0];
}
function the_sum($str){
$sum = 0;
for($i = 0; $i < strlen($str) ; $i+=1) $sum += 1 + ord($str[$i]) - ord("a");
return $sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment