Skip to content

Instantly share code, notes, and snippets.

@dflima
Created November 7, 2017 18:13
Show Gist options
  • Save dflima/13859b1f204c58bb5e2422e9df17b4d8 to your computer and use it in GitHub Desktop.
Save dflima/13859b1f204c58bb5e2422e9df17b4d8 to your computer and use it in GitHub Desktop.
<?php
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$arr_temp = fgets($handle);
$arr = explode(" ",$arr_temp);
$arr = array_map('intval', $arr);
$count = count($arr);
$positive = count(array_filter($arr, function ($i) { return $i > 0; })) / $count;
$negative = count(array_filter($arr, function ($i) { return $i < 0; })) / $count;
$zeroes = count(array_filter($arr, function ($i) { return $i = 0; })) / $count;
printf("%f\n%f\n%f", $positive, $negative, $zeroes);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment