Skip to content

Instantly share code, notes, and snippets.

@dflima
Created April 18, 2013 14:05
Show Gist options
  • Select an option

  • Save dflima/5412957 to your computer and use it in GitHub Desktop.

Select an option

Save dflima/5412957 to your computer and use it in GitHub Desktop.
teste.php
<?php
$file = 'fake.in.txt';
if (!file_exists($file)) {
echo "O arquivo {$file} não existe.";
exit;
}
$handle = fopen($file, 'r');
do {
$buffer = fgets($handle, filesize($file)-1);
$array = explode(" ", $buffer);
if($array[0] == 0 && $array[1] == 0) {
exit;
}
$buffer = fgets($handle, filesize($file)-1);
$array = explode(" ", $buffer);
echo verificaIgualdade($array) . "<br/>";
} while(true);
function verificaIgualdade($array) {
$count = 0;
$valores = array_count_values($array);
foreach($valores as $valor => $frequencia) {
if($frequencia > 1) {
$count++;
}
}
return $count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment