Ruby squares
My latest hobby is a kind of coding challenge, writing short Ruby programs with self-imposed constraints. The goal is not to write the shortest code possible, but to fit the code neatly into a rectangle. Achieving this requires some trickery.
20201102a.rb
#!/usr/bin/env ruby
c=(0..0x7f).map{|i|
(i+9472).chr'utf-8'
}.to_a;def t(x=3);(
0x05<<x).times.map{
yield};end;puts t(1
){t{c.sample}.join}
# ljc, 2020-11-02 #
Sample output
┊┚╱┻╀╻┑┞─├╍╺┷╻╠│╟╀╻┉┪╩╝╫┿╼┦┦┩╳│╒╇┉┱┥╊┹┻╰
┉╈╤╥╓┋┍╗─┆╂┨╺┓┓┛╧╖━╬╬┚┒╋┋╚┘┪╊╞╟┐┒┺╜─╽┟╒╇
┊╛┋├╟┠┝╱│└┱┻┫┟╟╌┦┬╓┺╽║┥╲┃┿╙┃─╨╠╴╭┄┉╞─╀╈┣
┥┙┃╾─┲┴╉┫┽┆┒╧╅╏╭┈╃╕┽╫┟┾╤╃┎┢┭╎╋║╺╧╾╩╣┟╷╔╞
╞╸║╠╜╮┮┻╄╪┄╾╗┙┕╱╔╿┱╛┨┺╥┮╛┑┘┄╵╿╚╂╓┎╦┕┫┄╛╢
╲╮├╶╔┮┞╙┋╗┝┏┄╅╀╳┘╽┼╔╵┒┤┹┒┻┏╫╊╣┤┻╈╦┪╋┧╧╜┳
╰╓╜┃╨┈╁│╄╚╨╀╙┶┋┨╀┏┐┨╏┳╌─┌┵┯┓╣┱╫┳┾╥╃┢┸┼┆┰
╚┹┏╁┆╛╍┶├╙╊╃┣┖┆╻┺┢─┛┊┃╎┚╈╦┱┵╻┻┓╶╆┃┴╿┯╖┥┑
┤┵╵╤╀─┍┯┚┡╾┡├┫━┓╀╯┸╕╦╣╁┋═╢╂╨╘┱┝─├╨┝╹┋╤╋┌
╫┊╯┑╨╠╖║┶╂╦┋╁┞╧┷╌┃╥╍┶╒╿┐┠┾┐╁╆╻╕╜┃╳╗╪┭┢┫╰
20201102b.rb
#!/usr/bin/env ruby
def p;printf(yield)
end;c=("\u{2571}"..
"\u2573").to_a+[' '
]*2;400.times.map{|
i|p{c.sample};p{10.
chr}unless i%40<39}
# ljc, 2020-11-02 #
Sample output
╲ ╲╲╲ ╲╱╲ ╳╲╲ ╲╳╲ ╳ ╱ ╳ ╱ ╳╳╳ ╲ ╲╳
╳╳ ╲╱╲ ╳ ╳ ╲ ╱╱╱ ╲╲╳ ╲╳ ╳ ╱╱ ╳╱╱
╱ ╲╳╱╱╲ ╲ ╲ ╲╳ ╲╲ ╱ ╳ ╲╱╱ ╱╳╱
╲╳╲╲╱ ╳╳╲╳╱ ╲╳╱ ╳╱╱ ╳ ╳ ╲ ╳ ╱╲ ╲
╲╱ ╱╱╲╲╱╲╱ ╱╲ ╱╳ ╲ ╳╲╳╲ ╳╲ ╳ ╲ ╳ ╱╳
╲╱╲╲╳ ╳ ╲╳╳ ╲╳ ╱╳ ╲╱ ╱╱╱╳ ╳ ╳ ╳╲
╱╲╲╲╱ ╳ ╲ ╳╱ ╳╱ ╲ ╲╲╱ ╳╲╲╳ ╱ ╲╳╲ ╳╳
╳ ╳╱ ╳ ╳╲╳ ╲╲╱╳ ╱ ╲╱╳╳╱╲╲╳ ╳╳╲ ╱
╲╳╲ ╳ ╳╲╱ ╲╱╱╲╳╲ ╱ ╱╳ ╲ ╲╲ ╲╲ ╲ ╳╳╱ ╱╲
╱ ╱ ╱╳ ╳╱╱ ╲ ╳╲╱╲ ╳╳ ╳╲ ╳ ╳ ╲╳╳╱╲╲
More or less
After writing these two programs, I started learning Ruby golf techniques to do more with less code.
Now I’m working on a more complex program that animates text in the terminal, which is completely free of spaces. I hope to release it soon in a followup post, alongside a readable form of the same program, once I fix the last elusive bug.
Update: Part II.