PHP
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$until = 10000; //numero hasta el cual se va a buscar
function isOdious($number) {
//obtenemos el string binario
$binary = decbin($number);
//contamos los unos
$cantOnes = substr_count($binary, '1');
//devolvemos true si es impar
return ($cantOnes % 2 == 1 ? true : false);
}
$found = 0;
for($i=0; $i<$until; $i++) {
if(isOdious($i)) {
$found++;
}
}
echo("There are $found odious numbers less than $until");
?>
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run