Elias delta to Fibonacci by tabasa

$f=[]\x0d
a=1;b=1;35.times{|i|$f+=[a];c=b+a;a=b;b=c}\x0d
def c d\x0d
 i=0\x0d
 while !(d<$f[i+1]);i+=1;end\x0d
 [i,d-$f[i]]\x0d
end\x0d
def x n\x0d
 f=c(n)\x0d
 a="0"*(f[0]-1)+"11"\x0d
 while f[1]>0\x0d
  f=c(f[1])\x0d
  a[f[0]-1]="1"[0]\x0d
  n=f[1]\x0d
 end\x0d
 a\x0d
end\x0d
def b d\x0d
 v=0\x0d
 d.length.times{|i|\x0d
  v*=2;v+=d[i..i].to_i\x0d
 }\x0d
 v\x0d
end\x0d
def r d,i\x0d
 /^(0*)/=~d[i,9]\x0d
 if($1==nil);[1,1]\x0d
 else\x0d
 n=$1.length\x0d
 m=2**n+b(d[i+n+1,n])-1\x0d
 [2**m+b(d[i+n*2+1,m]),n*2+m+1];end\x0d
end\x0d
while gets\x0d
 n=0\x0d
 d=$_.chomp\x0d
 while d.length>n\x0d
  a=r d,n\x0d
  print x a[0]\x0d
  n+=a[1]\x0d
 end\x0d
 puts\x0d
end\x0d
 

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

download

return top