Skip to content

Instantly share code, notes, and snippets.

@ilyosdev
Last active February 20, 2019 01:54
Show Gist options
  • Save ilyosdev/ce8e89cb307872486d1ecbbc6bc31189 to your computer and use it in GitHub Desktop.
Save ilyosdev/ce8e89cb307872486d1ecbbc6bc31189 to your computer and use it in GitHub Desktop.
<?php
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
while($f = fgets($_fp)){
$lines[] = $f;
}
$bugNum = intval($lines[0]);
$bugs = array_merge(explode(' ',$lines[1]));
// print_r($bugs);
$mylvl = 1;
$myHealth = 10;
$kills = 0;
$allkills = 0;
for($i = 0; $i<=$bugNum-1;$i++){
$buglvl = $bugs[$i];
// print $buglvl;
if($buglvl == $mylvl){
$myHealth = $myHealth - $buglvl;
if($myHealth<0){
echo "You have died. Reached level $mylvl and killed $allkills bugs";
break;
}
$allkills +=1;
$kills +=1;
}
elseif($buglvl < $mylvl){
$myHealth = $myHealth - 1;
if($myHealth<0){
echo "You have died. Reached level $mylvl and killed $allkills bugs";
break;
}
$allkills +=1;
$kills +=1;
}
elseif($buglvl > $mylvl){
$myHealth = $myHealth - ($buglvl*2);
if($myHealth<0){
echo "You have died. Reached level $mylvl and killed $allkills bugs";
break;
}
$allkills +=1;
$kills +=1;
}
if($kills == 3){
$mylvl +=1;
$myHealth =15;
$kills = 0;
}
}
if($myHealth>0){
echo "You have won! Reached level $mylvl and killed $allkills bugs";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment