Elias delta to Fibonacci by 51b

-module(e).
-export([m/0]).
m()->f(0).
f(N)->case g()of"0"->f(N+1);"1"->io:format(tl(k(h(h(N)-1),1,2))),m();eof->0;_->io:nl(),m()end.
g()->io:get_chars('',1).
h(0)->1;h(N)->h(N-1)*2+hd(g())-$0.
k(N,X,Y)->[M|S]=if Y>N->[N,$1];0<1->k(N,Y,X+Y)end,if X>M->[M,$0];0<1->[M-X,$1]end++S.

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page