Skip to content

Instantly share code, notes, and snippets.

@9072997
Last active December 19, 2015 10:38
Show Gist options
  • Save 9072997/5941407 to your computer and use it in GitHub Desktop.
Save 9072997/5941407 to your computer and use it in GitHub Desktop.
This is an obfuscated command line php program to generate numbers from the fibonacci sequence. The first argument is the starting point and the last is the ending point for the generated numbers, so for example "php fib.php 1 100" would generate the first 100 numbers of the fibonacci sequence. I challenge you to determine the twist in the logic…
<?php $c[1][1]='1';function p($r,$p){global $c;if(isset($c[$r][$p]))$r=
$c[$r][$p];elseif($p==1)$r=$c[$r][$p]=p($r-1,$p);elseif($p==$r)$r=$c[$r]
[$p]=p($r-1,$p-1);else$r=$c[$r][$p]=bcadd(p($r-1,$p-1),p($r-1,$p));
return $r;}function f($s){$l=ceil($s/2);$p=1;$t='0';for($i=1;$i<=$l;$i++
)$t=bcadd($t,p($s--,$p++));return $t;}for($i=$argv[1];$i<=$argv[2];$i++)
echo f($i).' ';?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment