Ruby Stuff
news | mp3tag | diff | glruby | everything else
Everything Else
Obfuscated ASCII Maze Generator
#!/usr/bin/env ruby
x=(w=($*[0]||10).to_i)-1;y=(h=($*[1]||10).to_i)-1;T='|';v=[T
]*w*h; v[p=0]=F=(); f=[F]*w*y;g=[F]*h*x; (w*h-1) .times{n=[]
while T;n<<1 if p%w<x&&v[p+1];n<<-w if p>=w&&v[p-w];n<<-1 if
p%w>0&&v[p-1];n<<w if p<y*w&&v[p+w];if n.empty?;t=T;while t;
p+=1;t=v[p=p%(w*h)];end ;else;break;end;end;eval({1=>'g[p/x+
p%w', -1=>'g[p/w*x+(p-1)%w', w=>'f[p', -w=>'f[p-w'} [np =n[(
n.length*rand).to_i]]+']=T');v[p+=np]=F};S=' '*3;R='+';c=(R+
U='-'*3)*w+R;puts c;h.times{|r|puts T+S+g[r*x,x].collect{|d|
d ? ' ':'|'}.join(S)+S+T;puts R+f[r*w,w].collect{|d|d ? S: U
}.join(R)+R if r!=y};puts c
Obfuscated Brainf*ck Compiler
#!/usr/bin/env ruby
a='p=0;t="\0"*30000;';$<.each_byte{|c|a<<({?>=>"p+=1;",?<=>"p-=1;",?+=>
"t[p]+=1;",?-=>"t[p]-=1;",?[=>"while t[p]>0;",?]=>"end;",?.=>"putc t[p];",
?,=>"t[p]=STDIN.getc||0;"}[c]||"")};eval a
Interesting use of regular expressions
As posted posted in ruby-talk:29060 by Michael Cook:
ruby -le '$_ = 1; ("1" * $_) !~ /^(11+)\1+$/ && print while $_ += 1'
Or my own conversion:
ruby -le '$_ = "1";/^(11+)\1+$/ or print($_.length) while $_<<?1'
|