Skip to content

Instantly share code, notes, and snippets.

@ilyosdev
Last active February 17, 2019 14:05
Show Gist options
  • Save ilyosdev/1b96e4685f0647d4c5472bf2d79a3378 to your computer and use it in GitHub Desktop.
Save ilyosdev/1b96e4685f0647d4c5472bf2d79a3378 to your computer and use it in GitHub Desktop.
Solution for HackerRanks problem
<?php
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
$text = $words = array();
//collecting words as an array
while($in = fread($_fp,1024)){
$text = array_merge($text, explode(' ', $in));
}
$keywords = [
'lol' => 1,
'rofl' => 2,
'lmao' => 3,
'lel' => 4
];
$words = array_count_values($text);
$points = 0;
foreach ($keywords as $keyword => $point)
{
if (isset($words[$keyword]))
$points += $point * $words[$keyword];
}
if($points<=5){
echo "Patient has bright red face";
}elseif($points>5 && $points<=12 ){
echo "Patient is unable to speak";
}elseif($points>12 && $points<=20){
echo "Patient's sides are mildly bruised";
}elseif($points>20 && $points<=31){
echo "Patient has broken jaw, fractured ribs";
}elseif($points>31 && $points<=49){
echo "Patient is in a coma";
}else{
echo "Patient is dead";
}
?>
@ilyosdev
Copy link
Author

!php

LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment