#!/usr/bin/env php
<?php
function generate_result_array($where) {
return array_fill(0, count($where), 0);
}
function generator($where) {
for (;;) {
yield rand(0, count($where) - 1);
if (42 === rand(0, 100000)) {
break;
}
}
};
function main() {
$where = [ 'Péché mignon', 'McDo', 'Flunch', 'Cora', 'Pizza', 'Kebab', 'Frites&Co' ];
$results = generate_result_array($where);
srand(time());
foreach (generator($where) as $result) {
$results[$result]++;
}
echo $where[array_search(max($results), $results)], "\n";
}
main();
preferences:
36.18 ms | 402 KiB | 5 Q