Created
January 20, 2014 18:33
-
-
Save fintara/8526152 to your computer and use it in GitHub Desktop.
CodeEval competition - Predict The Number.
Thanks to ferhatelmas/algo for the idea! Very interesting solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = file_get_contents($argv[1]); | |
$rows = explode("\n", $input); | |
foreach($rows as $row) { | |
if($row >= 0 && $row <= 3000000000) { | |
$bin = decbin($row); | |
$sum = 0; | |
for($i = 0; $i < strlen($bin); $i++) | |
if($bin[$i] == "1") $sum++; | |
echo $sum % 3 . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@samarthbhargav: the fomula can be searched from the OEIS, this link https://oeis.org/A071858