Any fool can write code that a computer can understand. Good programmers write code that humans can understand. - Martin Fowler
Code Golf - solve a specific problem in as few lines of code as possible.
Things to think about while golfing:
- What does your language of choice do well (with respect to code golf)?
- What does your language of choice do poorly (with respect to code golf)?
- Did you ever hit a point where your code becomes 'unreadable'?
- Is there such a thing as 'the best solution' to a problem?
- How do you determine if/when a particular solution is elegant?
Here is a simple ASCII art snowman:
_===_
(.,.)
( : )
( : )
Let's make him some friends. This will be the general pattern for our ASCII art snowpeople:
HHHHH
HHHHH
X(LNR)Y
X(TTT)Y
(BBB)
The leading spaces and the parentheses are always the same for all snowpeople. The different letters represent sections of the pattern that can individually change. Each section has exactly four presets for what ASCII characters can fill it. By mixing and matching these presets for all eight sections, we can make a variety of snowpeople.
(Notice that spaces are put on otherwise empty lines so the section shape is always correct.)
- Straw Hat
_===_
- Mexican Hat
___
.....
- Fez
_
/_\
___
(_*_)
-
Normal
,
-
Dot
.
-
Line
_
-
None
-
Dot
.
-
Bigger Dot
o
-
Biggest Dot
O
-
Closed
-
(Same list as left eye.)
- Normal Arm
<
- Upwards Arm
\
- Downwards Arm
/
- None
- Normal Arm
>
- Upwards Arm
/
- Downwards Arm
\
- None
-
Buttons
:
-
Vest
] [
-
Inward Arms
> <
-
None
-
Buttons
:
-
Feet
" "
-
Flat
___
-
None
Write a program that takes in an eight character string (via stdin or command line) in the format HNLRXYTB
, where each letter is a digit from 1 to 4 that denotes which preset to use for the corresponding section of the snowperson. Print the full snowperson to stdout.
For example, the input 11114411
is the snowman at the top of the page. (First 1
: he has a straw hat, second 1
: he has a normal nose, etc.)
Another example, the snowperson for input 33232124
:
_
/_\
\(o_O)
(] [)>
( )
-
Any amounts and combinations of leading/trailing spaces and leading/trailing newlines are allowed as long as...
- the snowperson has all their sections arranged correctly with respect to one another, and
- there are never more than 64 total whitespace characters (the general pattern is only 7×5, so you probably won't hit this limit).
You don't need to print rows/columns of the pattern if they only contain whitespace. e.g. the empty line of the straw hat is not required.
-
You must use the ordering of the parts as they are given above.
-
Instead of a program, you may write a function that takes the digit string as an argument. The output should be printed normally or returned as a string.
-
You may treat the input as an integer instead of a string if preferred.
Catering from Creole Soul Café on East Jefferson St.