Converts single digits into old-school ASCII string.
See my digital clock example.
_ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_|
|_| | |_ _| | _| |_| | |_| _|
_ _ _ _
| |_| . _| _| . |_ |
| | . |_ _| . _| |
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
Before we discuss, let's save 2 more bytes first.
Now discuss.
Notice that the
c[a]
is either1
or0
.When c[a] is
1
, put space.When c[a] is
0
, draw "|" or "_".It's sad that the
a%2
is either1
or0
too, that means we have to separate them.So first
1^
toggles thec[a]
in this case, the space uses the position0
.And for
a%2
, plus 1 and use the positions1
and2
.By the way, I am finding another way to golf this code.