Years ago I read the "Best of Ruby Quiz" book by James Edward Gray II (also available online by now). For problem 2 in the book (which is problem 14 on his original RubyQuiz site), he mentions a golfed solution in under 300 bytes, even though he is not a big fan of golfing.
So I did wonder if I could beat that and maybe even find a solution of under 200 bytes. So once I beat the current best solution of 256 bytes I sent him a 210 bytes solution. Shortly thereafter I found a solution around 190 bytes, but didn't bother to send him that. But over the years I lost these 190 bytes somehow and couldn't find a backup anymore. In any case I know that a under 200 byte solution is possible in ruby (at least with ruby 1.8.7) so I hope some of you will be able to recreate it or maybe even find something better.
Even though I'm mostly interested in ruby solution other language solutions are of course also welcome!
Create a program which is called on the commandline and takes a non-negative integer as an argument and an optional
-s argument followed by a positive integer. The default value for
The output should be the input argument in LCD-style adjusted by size by the
For example if the program is called like this
$ lcd.rb 012345
the correct display is this:
-- -- -- -- | | | | | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | | | | | -- -- -- --
And for this:
$ lcd.rb -s 1 6789
your program should print this:
- - - - | | | | | | - - - | | | | | | - - -
Note the single column of space between digits in both examples. For other values of
-s, simply lengthen the
Of course because this is code golf I have to be more specific than the original quiz about some rules:
- It's ok if your program requires to be explicitly called by an interpreter (e.g.
ruby lcd.rb 1234), so a shebang line is not required
- It's not required to handle other than the above specified arguments in a sane way (e.g. negative numbers, no space between
-sand the following number, extra arguments, or no arguments at all)
- It should in principle be able to handle any number of digits and any positive size for the scale parameter
-s. So only external factors like the maximum command line length of the shell should limit these parameters.
- Non-printable characters are allowed, but your program must consist of the 128 characters of the ASCII set.