Transform number into 7-segment display pattern
Commodore 64 BASIC
PETSCII art rules :)
Output:
Python 3, 286 282 280
Yeah I golfed this one. Nice challenge!
n,x=input().split()
n=int(n)
l=lambda s:"".join(s)+"\n"
h=lambda s:s.replace(*"! ")*~-n+s.replace(*"!_")
print(l(" "+"_ "[c in"14"]*n+" "for c in x)+h(l("| "[c in"1237"]+n*"! "[c in"017"]+"| "[c in"56"]for c in x))+h(l(" |"[c in"0268"]+n*"! "[c in"1479"]+"| "[c=="2"]for c in x)))
Also, here's a Python 2 version weighing in at only 273 bytes!
Not updating this one any more with further golfed original source. This was created when the original source was 282 bytes (Python 3 version).
exec'eJxdzE0OgjAQhuE9pxhn1VIlFhHUpCdRQlAx1NShAYwsOLzgD4irSd758tC8UWX6SDTZe824V1mju+uQ0lQz4o5RJr0dzylUO0TvWmhiFRd4IHTy8VV5ZWZNesqYizNA7jJaSC4mOUHu2LJjwTAEFJgA7k+gCWWAsUuii5eihD5Bw0XOul07bPxVhLGgl/9OS9mXcbIOMf4BPgK037kfbv4EGUTbgVAK/SnwBAs+TpU='.decode('base64').decode('zip')
This may be cheating, so I'm adding it separately. Let me know whether this is considered valid or not.
Haskell (389 chars)
The solution uses 7 arrays, one for each segment of the array, using the names from this image:
. The value a !! 4
will be the character that should be displayed at that a position for the number 4.
The values are multiplied by the scale where appropriate (using r
and rp
for replication), and finally printed out.
The code
a="_ __ _____"
b="||||| |||"
c="|| |||||||"
d="_ __ __ _ "
e="| | | | "
f="| ||| ||"
g=" _____ __"
r=replicate
cm=concatMap
s=(' ':).(++" ")
dd w n=[[t n],rp$m f b n,[o g f b n],rp$m e c n,[o d e c n]] where
rp=r$w-1
t=cm(s.r w.(a!!))
q f s x y=cm(\n->x!!n:r w(f s n)++[y!!n])
o=q(!!)
m=q const ' '
go a=unlines$concat$dd(read$a!!0)$map(read.(:[]))$a!!1
main=interact$go.words
Example usage
echo '1 2320451640799518' | runhaskell ./digit_led.hs
_ _ _ _ _ _ _ _ _ _ _ _
_| _| _|| ||_||_ ||_ |_|| | ||_||_||_ ||_|
|_ _||_ |_| | _| ||_| ||_| | | | _| ||_|