Render "Digital Clock Style" Numbers
Funciton
Not really a language suitable for golfing... but regardless, I tried to keep the code size as small as I could — quite a different challenge than in “usual” languages. This is 1555 characters or 3110 bytes (if encoded as UTF-16; UTF-8 is larger).
Here’s a screenshot of the program running. It really works :)
Since this looks ugly in StackExchange due to the extra line spacing, consider running the following code in your browser’s JavaScript console to fix that: $('pre').css('line-height',1)
╓─╖ ╔╗┌─╖ ┌─╖
║ʜ║ ║╟┤↔╟┐ ┌┤‼╟┐
╙┬╜ ╚╝╘═╝│ │╘╤╝│
╔═╗ ┌┴────┐ │┌┴╖ ┌┴╖
║0║ ┌┴─┐ ┌┴─┐└┤ʜ╟─┤·╟┐
╚╤╝┌┴╖┌┴╖┌┴╖┌┴╖╘╤╝ ╘╤╝│
┌┘┌┤·╟┤ɦ╟┤·╟┤?╟ │ ┌┴╖│
│ │╘╤╝╘╤╝╘╤╝╘╤╝ └──┤‼╟┘
│┌┴╖│ ┌┴╖┌┘╔═╧╗ ╘═╝
└┤?╟┘┌┤?╟┘┌╢10║ ┌─────────┐
╘╤╝ │╘╤╝┌┘╚══╝ ┌─┬┘╔══╗┌──╖┌┴╖ ╓─╖
┘ └───┘╔════╗│┌┴┐║21╟┤>>╟┤·╟┐║ɦ║
╔════════╗║1005╟┘└┬┘╚══╝╘═╤╝╘╤╝│╙┬╜ ┌─┐
║14073768║╚════╝ ┌┴╖ ┌─╖ ┌┴╖┌┴╖└─┴─────────┘┌┴╖
║7584800 ╟───────┤?╟─┤‼╟─┤ʜ╟┤·╟─────────────┤·╟┐╔═══════╗╔══╗
╚════════╝ ╘╤╝ ╘╤╝ ╘╤╝╘╤╝ ╔══╗┌─╖┌┐╘╤╝│║2097151║║21╟┐
╔═══════════════╗│ ┘ │ │ ║48╟┤−╟┤├─┤┌┘╚══╤════╝╚══╝│
║140737555464224╟┘ ┌────┘┌┬┘ ╚══╝╘╤╝└┘┌┘│╓─╖ │┌┐┌─╖┌─╖┌┴─╖
╚═══════════════╝ │ ┌───┘└─────────┐┌┴─╖ │┌┘║↔║ ├┤├┤‼╟┤↔╟┤>>║
┌────────────┐┌────┐┌┴╖│┌────────────┐├┤<<║ ││ ╙┬╜┌┘└┘╘╤╝╘═╝╘╤═╝
│ ╔══╗╔═══╗├┘╓─╖ └┤·╟┘│ ╔══╗╔═══╗├┘╘╤═╝ │└─┐└─┤╔═╗┌┴╖ ┌──┘
│ ║95║║892║│┌╢‡╟┐ ╘╤╝ │ ║95║║877║│ ┌┘╔══╧═╗│ │║0╟┤?╟┬┘
│ ╚═╤╝╚═╤═╝││╙─╜│ │ │ ╚═╤╝╚═╤═╝│╔╧╗║2097║│ │╚═╝╘╤╝│
│╔══╗┌┴╖┌┐│ ││┌─╖│ ┌┴╖ │╔══╗┌┴╖┌┐│ │║1║║151 ║│ └──────┘
│║32╟┤?╟┤├┤ │└┤‼╟┘┌┤‡║ │║32╟┤?╟┤├┤ │╚═╝╚════╝│
│╚══╝╘╤╝└┘└──┴┐╘╤╝ │╘╤╝ │╚╤═╝╘╤╝└┘└──┴┐ ┌─┘
│ ┌┴╖ ┌┴╖┌─╖│ │ ┌┴╖│ ┌┴╖ ┌┴╖ ┌─╖┌┴╖
│ │‼╟─────┤·╟┤‼╟┘ │┌┤·╟┘ │‼╟─────┤·╟─┤‼╟┤‡║
└┐┌┐ ╘╤╝ ╘╤╝╘╤╝ ││╘╤╝┌┐ ╘╤╝ ╘╤╝ ╘╤╝╘╤╝
├┤├┐┌┴╖╔══╗ └──┐┌┐ │└┐├─┤├┐┌┴╖╔══╗ ├──┐└ │
│└┘└┤?╟╢32║╔═══╗├┤│┌┴╖││ └┘└┤?╟╢32║╔═╧═╗│┌┐┌┴╖╔══╗
╔╧══╗╘╤╝╚══╝║881╟┘│├┤?╟┘│ ╘╤╝╚══╝║325║└┤├┤?╟╢32║
║927║╔╧══╗ ╚═══╝ └┘╘╤╝╔╧═══╗╔╧══╗ ╚═══╝ └┘╘╤╝╚══╝
╚═══╝║124╟───────────┘ ║1019║║124╟───────────┘
╚═══╝ ╚════╝╚═══╝
It could probably be smaller if I hadn’t made a mistake due to which the output was back to front; I fixed that by adding an extra function to reverse the input. Otherwise I would probably have to rewrite all of it.
I also made another mistake (swapping the operands in two calls to ‼
) which made it necessary to declare the extra ‡
function, but this one is so small it fits inside the main function and thus doesn’t add any characters!
wxpython, many characters
import wx, wx.gizmos as g
class T(wx.Frame):
def __init__(_):
wx.Frame.__init__(_, None, size = (800, 60))
l = g.LEDNumberCtrl(_, -1)
l.Value = raw_input()
class M(wx.App):
def OnInit(_):
T().Show()
return 1
M().MainLoop()
Test
echo -n 81 | python codegolf-997-wx.py
ps: not a serious entry, but looks like graphical output is also acceptable, so I just gave it a try :-)
J, 90, 78 68 chars
[ update: using unicode (1 byte) encoding:
,./(10 3 3$((90$3)#:256#.24x-~3&u:'%ė¨ÔW/~º»sy¡ăì<t÷²'){' _|'){~"./.Y
NB. utf characters are: 37 279 168 212 87 47 126 186 187 115 121 161 259 236 60 116 247 178
works as before: ]
,./(10 3 3$((90$3)#:1219424106940570763878862820444729939648410x){' _|'){~"./. '58321'
_ _ _ _
|_ |_| _| _| |
_||_| _||_ |
The key is in the encoding of digits as base-3 integers. Zero, for example is:
:
_
| |
|_|
or ' _ | ||_|'
, which becomes 0102022123 = 2750.