LCD Numbers Duke It Out #
This week’s Ruby Quiz (a capital effort by JEGII) was solved in less than 300 bytes. I can’t get the 266 byte solution to run, so here is Jannis Harder’s at 295.
s=(s=$*.index"-s")?$*.slice!(s,2)[1].to_i: 2 d,="\21\265\22H\245\10-\0\23".unpack"B*" f=" " o=48 y=(0..4).map{""} $*.join.each_byte{|z|u=d[z*7-336,7] 3.times{|x|y[x*2]<<(u[x*3]>o ?f*s+f+f:f+"-"*s+f)+f} [1,3].map{|x|y[x]<<(u[h=x*4/3]>o ?f:"|")+f*s+(u[h+1]>o ?f:"|")+f}} y[3,1]*=s y[1,1]*=s puts y
Save this in harder.rb
and execute with ruby harder.rb 4
. You can control the size of the LCD digit with the -s
option.
Yes, compressed code is unreadable. But, hey, I get a kick out of deciphering this stuff and I’ve learned some sly shortcuts from such bits.
Comments are closed for this entry.