177
\$\begingroup\$

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.

All Presets

(Notice that spaces are put on otherwise empty lines so the section shape is always correct.)

H is for Hat

  1. Straw Hat

         
    _===_
  2. Mexican Hat

     ___ 
    .....
    
  3. Fez

      _  
     /_\ 
    
  4. Russian Hat

     ___ 
    (_*_)
    

N is for Nose/Mouth

  1. Normal ,

  2. Dot .

  3. Line _

  4. None

L is for Left Eye

  1. Dot .

  2. Bigger Dot o

  3. Biggest Dot O

  4. Closed -

R is for Right Eye

(Same list as left eye.)

X is for Left Arm

  1. Normal Arm

     
    <
  2. Upwards Arm

    \
     
  3. Downwards Arm

     
    /
  4. None

     
     

Y is for Right Arm

  1. Normal Arm

     
    >
  2. Upwards Arm

    /
     
  3. Downwards Arm

     
    \
  4. None

     
     

T is for Torso

  1. Buttons :

  2. Vest ] [

  3. Inward Arms > <

  4. None

B is for Base

  1. Buttons :

  2. Feet " "

  3. Flat ___

  4. None

Challenge

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)
 (] [)>
 (   )

Details

  • 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.

Scoring

The shortest code in bytes wins.

Bonus question: Which of the 65536 distinct snowpeople is your favorite?

\$\endgroup\$
  • 19
    \$\begingroup\$ I like the angel 14441133. Alternatively the small-eyed four-armed monster. Your pick. \$\endgroup\$ – Sp3000 May 6 '15 at 8:28
  • 14
    \$\begingroup\$ Does it have to be a snowman? \$\endgroup\$ – user8777 May 6 '15 at 13:14
  • 54
    \$\begingroup\$ It doesn't have to be a snowman. (Disclaimer: It may have to be a snowman) \$\endgroup\$ – Joshpbarron May 6 '15 at 13:24
  • 3
    \$\begingroup\$ The occasional witty comment is nice, but for extended discussion please use chat instead of comments. I've cleaned this up a bit. \$\endgroup\$ – Martin Ender May 7 '15 at 17:11
  • 36
    \$\begingroup\$ Question to do next: "The code never bothered me anyway" \$\endgroup\$ – Calvin's Hobbies May 9 '15 at 19:19

27 Answers 27

39
\$\begingroup\$

CJam, 135 134 132 130 126 125 bytes

0000000: 4e22285b200a5c225f2a295c2d2e2f6f2c3e4f3a3c3d5d225f  N"([ .\"_*)\-./o,>O:<=]"_
0000019: 2422dd7382d6bfab28707190992f240c362ee510262bd07a77  $".s....(pq../$.6...&+.zw
0000032: 08556de9dcdb566c676817c2b87f5ecb8bab145dc2f2f76e07  .Um...Vlgh....^....]...n.
000004b: 22323536624b623224663d4e2f7b5f2c342f2f7d25723a7e2e  "256bKb2$f=N/{_,4//}%r:~.
0000064: 3d2828342423346222205f0a20222e2a6f6f736572372f4e2a  =((4$#4b" _. ".*ooser7/N*

To create the file on your machine, execute xxd -r > snowman.cjam, paste the reversible hexdump from above, press Enter and finally Ctrl + D.

Alternatively, you can try the code online using the CJam interpreter.

Bonus

My favorite snowman is Olaf:

$ LANG=en_US cjam snowman.cjam <<< 12222212

 _===_
\(o.o)/
 ( : ) 
 (" ")

Winter's a good time to stay in and cuddle, but put me in summer and I'll be a… happy snowman!

Idea

The hex string

dd7382d6bfab28707190992f240c362ee510262bd07a7708
556de9dcdb566c676817c2b87f5ecb8bab145dc2f2f76e07

encodes the possible choices for all parts of the snowman, including the fixed ones. Let's call this string P.

To decode it, we convert P (here treated as an array of integers) from base 256 to base 20 and replace each of the resulting integers by the corresponding character of the string M:

([ 
"_*)\-./o,>O:<=]

This results in the string T:

/(_*_)"_===_/....., /_\ 
 ,._
-.oO
-.oO
   <\  /
   >/  \
    : ] [> <
    : " "___
 ((()

The first line encodes all hat choices, the last all fixed body parts. The other lines contain the 28 variable body parts.

We split T at linefeeds and divide the strings of the resulting array into four parts of equal length. Then, we read the input from STDIN, push the array of its digits in base 10 and select the corresponding elements of the split strings. We take advantage of the fact that arrays wrap around in CJam, so the element at index 4 of an array of length 4 is actually the first element. The last divided string does not correspond to any input, so it will get selected entirely.

We handle the hat by shifting the first element out of the resulting array. The index in M of first character, read as a base 4 number, reveals the number of spaces and underscores in the first line of the hat. We print those characters, a linefeed, a space and the remainder of the shifted string. Then, we push an additional linefeed on the bottom of the stack.

For the body parts, we concatenate the string corresponding to all of them. Let's call this string S. To assemble the body parts, we perform transliteration: we take each character of the string M, compute its index in sort(M) and replace it by the corresponding character of S. We take advantage of the fact that the transliteration operator automatically pads S to match the length of sort(M) by repeating the last character of S as many times as necessary.

Finally, we divide the resulting string into substrings of length 7 and place a linefeed between each pair of substrings.

Code

Suppose that the variables M and P contain the strings M and P.

N        e# Push a linefeed.
M_$      e# Push M and a sorted copy.
P256bKb  e# Push P and convert it from base 256 to base 20.
2$       e# Push a copy of M.
f=       e# Compute T by retrieving the proper chars from M.
N/       e# Split T at linefeeds.
{_,4//}% e# Divide each string into four substrings of equal length.
r:~      e# Read a number from STDIN and push the array of its digits in base 10.
.=       e# Get the corresponding chunks from T.
((       e# Shift out the first string and that string's first character.
4$#      e# Find its index in M.
4b       e# Compute its digits in base 4.
" _
 ".*     e# Repeat the space and underscore that many times in place.
oo       e# Print the result and the shifted string.
s        e# Flatten the remainder of the array. This pushes S.
er       e# Perform transliteration.
7/       e# Split into chunks of length 7.
N*       e# Join using linefeeds.
\$\endgroup\$
60
\$\begingroup\$

JavaScript ES6, 210 208 202 bytes

s=>` 0
8(213)9
4(6)5
 (7)`.replace(/\d/g,p=>`_===_1 ___
 .....1  _
  /_\\1 ___
 (_*_)1,1.1_11.1o101-1.1o101-1<11/11>11\\11 : 1] [1> <1   1 : 1" "1___1   11\\11 11/11 `.split(1)[s[p>7?p-4:p]-1+p*4]||' ')

This is an anonymous function; you use it by executing ([function code])('42232124'). The most aggravating part of this was the arms, which take up 2 lines, so I had to include code for both top and bottom.

The Stack Snippet below has ungolfed, un-ES6-ified, commented code. And you can use it to easily test the code and try out different combinations. Edit: I'm having way too much fun with this. I've added several new features, including a way to generate a random snowman.

Thanks to Yair Rand for saving six bytes.

var f=function(s){
  return' 0\n8(213)9\n4(6)5\n (7)' // Start with a placeholder string with all the static components
    .replace(/\d/g,function(p){ // Go through each placeholder number to replace it with its value
    // The massive string below holds all the possible body parts, separated by 1 for easy splitting.
    // The two at the end are for the top of the arms
    return'_===_1 ___\n .....1  _\n  /_\\1 ___\n (_*_)1,1.1_11.1o101-1.1o101\
-1<11/11>11\\11 : 1] [1> <1   1 : 1" "1___1   11\\11 11/11 '.split(1)
    [s[p>7?p-4:p]-1 // Get the value from the input string. If the current body part
                    // is the top of the two-line arms (8 or 9), drop it down to 4 or 5
                    // Subtract 1 to account for the 0-indexed array.
     +p*4] // multiply by 4 to skip to the relevant code
     ||' ' // To save bytes in the above string, spaces are empty strings, so replace them here
  })
}

// Code for the interactive version follows
// http://codepen.io/hsl/pen/bdEgej
function updateRadios(){$('input[type="radio"]').each(function(){if($(this).is(":checked")){var t=$(this).data("p"),i=$(this).data("v");input[t]=i}}),inputS=input.join(""),update()}var input=[],inputS=$("#code").val(),update=function(){$("#p").text(f(inputS)),$("#code").val(inputS)};$('input[type="radio"]').change(updateRadios),$("#code").keyup(function(){inputS=$(this).val(),update()}),updateRadios(),$("#random").click(function(){for(var t=0;8>t;t++)$("div:eq("+t+") input:eq("+Math.floor(4*Math.random())+")").prop("checked",!0);updateRadios()});
body{font-family:sans-serif}h2{font-size:18px;font-weight:400}label{display:block}div{display:inline-block;margin:0 10px}#code{width:70px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><h2>Hat</h2><label><input type="radio" name="p1" data-p="1" data-v="1"> Straw hat</label><label><input type="radio" name="p1" data-p="1" data-v="2"> Mexican hat</label><label><input type="radio" name="p1" data-p="1" data-v="3"> Fez</label><label><input type="radio" name="p1" data-p="1" data-v="4" checked> Russian hat</label></div><div><h2>Nose/mouth</h2><label><input type="radio" name="p2" data-p="2" data-v="1"> Normal</label><label><input type="radio" name="p2" data-p="2" data-v="2" checked> Dot</label><label><input type="radio" name="p2" data-p="2" data-v="3"> Line</label><label><input type="radio" name="p2" data-p="2" data-v="4"> None</label></div><div><h2>Left eye</h2><label><input type="radio" name="p3" data-p="3" data-v="1"> Dot</label><label><input type="radio" name="p3" data-p="3" data-v="2" checked> Bigger dot</label><label><input type="radio" name="p3" data-p="3" data-v="3"> Biggest dot</label><label><input type="radio" name="p3" data-p="3" data-v="4"> Closed</label></div><div><h2>Right eye</h2><label><input type="radio" name="p4" data-p="4" data-v="1"> Dot</label><label><input type="radio" name="p4" data-p="4" data-v="2"> Bigger dot</label><label><input type="radio" name="p4" data-p="4" data-v="3" checked> Biggest dot</label><label><input type="radio" name="p4" data-p="4" data-v="4"> Closed</label></div><div><h2>Left arm</h2><label><input type="radio" name="p5" data-p="5" data-v="1"> Normal</label><label><input type="radio" name="p5" data-p="5" data-v="2" checked> Upwards</label><label><input type="radio" name="p5" data-p="5" data-v="3"> Downwards</label><label><input type="radio" name="p5" data-p="5" data-v="4"> None</label></div><div><h2>Right arm</h2><label><input type="radio" name="p6" data-p="6" data-v="1" checked> Normal</label><label><input type="radio" name="p6" data-p="6" data-v="2"> Upwards</label><label><input type="radio" name="p6" data-p="6" data-v="3"> Downwards</label><label><input type="radio" name="p6" data-p="6" data-v="4"> None</label></div><div><h2>Torso</h2><label><input type="radio" name="p7" data-p="7" data-v="1"> Buttons</label><label><input type="radio" name="p7" data-p="7" data-v="2" checked> Vest</label><label><input type="radio" name="p7" data-p="7" data-v="3"> Inward arms</label><label><input type="radio" name="p7" data-p="7" data-v="4"> None</label></div><div><h2>Base</h2><label><input type="radio" name="p8" data-p="8" data-v="1"> Buttons</label><label><input type="radio" name="p8" data-p="8" data-v="2"> Feet</label><label><input type="radio" name="p8" data-p="8" data-v="3"> Flat</label><label><input type="radio" name="p8" data-p="8" data-v="4" checked> None</label></div><br><button id="random">Randomize</button><pre id="p"></pre><input type="text" id="code">

\$\endgroup\$
  • 3
    \$\begingroup\$ +1 Very clever, so much better than mine \$\endgroup\$ – edc65 May 7 '15 at 15:02
  • 23
    \$\begingroup\$ The 'GUI' is pretty darn cool. \$\endgroup\$ – topher May 8 '15 at 15:56
  • 7
    \$\begingroup\$ Sweet, check out the 8-eyed spider snowman: 22112333 \$\endgroup\$ – Claudiu May 11 '15 at 16:57
  • 1
    \$\begingroup\$ I like the sleeping Russian owl: 41444442 \$\endgroup\$ – ETHproductions Oct 7 '15 at 16:18
  • 1
    \$\begingroup\$ You can save six bytes by removing each single space in a slot (1 1 -> 11) and adding ||' ' at the end. \$\endgroup\$ – Yair Rand Mar 25 '18 at 20:04
30
\$\begingroup\$

CJam, 164 bytes

Generates the snowman left-to-right, top-to-bottom. This eliminates the need for any kind of string joining or repositioning operations, as I just leave every piece of the snowman on the stack. And then, due to the automatic stack dump at the end of programs:

CJam wants to build a snowman!

q:Q;SS"
 _===_,___
 ....., _
  /_\,___
 (_*_)"',/0{Q=~(=}:G~N" \ "4G'(".oO-"_2G",._ "1G@3G')" / "5GN"< / "4G'(" : ] [> <   "3/6G')"> \ "5GNS'(" : \" \"___   "3/7G')

Try it online.

Bonus

Thinking outside the box! 32443333 gives a snow(wo)man bride. You've gotta try a bit to see it, but there are the inward arms, fez + downwards arms = veil, and the head is actually in the fez/veil. The generally large form is the billowy dress, and the "eyes" and "nose" are folds in the dress.

   _
  /_\
 (-.-) 
/(> <)\
 (___)

Other "eye" choices are a bit risqué...

\$\endgroup\$
  • 17
    \$\begingroup\$ To me, your bonus looks more like a KKK member than a bride. \$\endgroup\$ – ace_HongKongIndependence May 8 '15 at 23:44
26
\$\begingroup\$

Python, 276 289 bytes

V='.oO-'
def F(d):
 D=lambda i:int(d[i])-1
 print"  "+("","___"," _ ","___")[D(0)]+"\n "+\
"_. (=./_=._*=.\\__. )"[D(0)::4]+"\n"+\
" \\  "[D(4)]+"("+V[D(2)]+',._ '[D(1)]+V[D(3)]+")"+" /  "[D(5)]+'\n'+\
"< / "[D(4)]+"("+" ]> :    [< "[D(6)::4]+")"+"> \\ "[D(5)]+"\n ("+\
' "_ : _  "_ '[D(7)::4]+")"

This code has 8 extra bytes(\*4) for readability.

Builds the snowman up bit by bit.

Bonus

F("44444432") gives "sleepy russian bear":

  ___    
 (_*_)
 (- -)
 (> <)
 (" ")
\$\endgroup\$
  • 13
    \$\begingroup\$ Sleepy russian bear is now my favorite too. \$\endgroup\$ – Calvin's Hobbies May 8 '15 at 17:32
  • 1
    \$\begingroup\$ The top row underscores don't seem to be correct on the fez and russian hats. e.g. It's giving a propellor hat.. \$\endgroup\$ – Calvin's Hobbies May 9 '15 at 1:52
  • \$\begingroup\$ @Calvin'sHobbies: The russian hat was okay, but the fez hat was messed up. I fixed it now and checked all the other cases too. I must be more careful in the future! \$\endgroup\$ – Claudiu May 11 '15 at 16:53
  • \$\begingroup\$ super late to the party, but this TIO says this is 297 for me. Intellij says 299. Am I missing something? \$\endgroup\$ – snowe Apr 29 at 20:14
21
\$\begingroup\$

Python 2, 354 280 241 261 bytes

def s(g):H,N,L,R,X,Y,T,B=[int(c)-1for c in g];e='.oO-';print(' '*9+'_ _ ___ _ _\n\n\n\n    _. (=./_=._*=.\\__. )')[H::4]+'\n'+' \\  '[X]+'('+e[L]+',._ '[N]+e[R]+')'+' /  '[Y]+'\n'+'< / '[X]+"("+' ]> :    [< '[T::4]+')'+'> \\ '[Y]+'\n ('+' "_ : _  "_ '[B::4]+")"

Calling s('33232124') gives:

   _ 
  /_\ 
\(o_O) 
 (] [)>
 (   )

But my favorites are 44242123 and 41341144:

  ___      ___
 (_*_)    (_*_)
\(o -)    (O,-) 
 (] [)>  <(   )>
 (___)    (   )
\$\endgroup\$
  • 1
    \$\begingroup\$ When I do s('33232124') the fez slashes aren't drawn. In fact the bottom half of the hat is missing in a lot of cases. Also, 0 is not one of the options. \$\endgroup\$ – Calvin's Hobbies May 9 '15 at 1:49
  • \$\begingroup\$ @Calvin'sHobbies Thanks, I fixed it. \$\endgroup\$ – Cees Timmerman May 9 '15 at 13:09
20
\$\begingroup\$

CJam, 150 145 bytes

Base convert all the things!

"b8li'
U9gN;|"125:Kb8bl:~f="r  pL|P3{cR`@L1iT"Kb21b"G.HMtNY7VM=BM@$^$dX8a665V"KbFb"=_./ <[(*-oO,\":"f=_"/<[(""\>])"er+4/f=.=7/N*

SE mangles unprintables, so here is a copy on Pastebin. Make sure you copy the "RAW Paste Data" part, not the part next to line numbers. You can try it online, but the permalink may not work in some browsers.

Explanation

The "b8li'U9gN;|"125:Kb8bp part generates the array

[1 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 2 1 3 0 5 4 0 6 6 6 0 5 0 0 7 7 7 0]

which maps each digit of the input to where the digit is used. Anything which is common to all inputs (e.g. leading spaces and ()) is arbitrarily assigned a 0, except the first which is assigned 1 so that base convert can work.

l:~f= then converts each digit to an int and maps accordingly, e.g. for 14441133 we get

[2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 4 1 2 1 1 3 3 3 1 2 1 1 4 4 4 1]

"G.HMtNY7VM=BM@$^$dX8a665V"KbFb"=_./ <[(*-oO,\":"f= gives the string

"_=./  /  < /  [<(((((_. _ _     _ __*=._-.oO ,._  \"_ :   : _"

after which we duplicate, replace /<[( with \>]) and append to give a long string. Then we split the string into groups of 4 and map according to another array "r pL|P3{cR`@L1iT"Kb21b, thus getting an array of length-4 strings describing all possible options at each cell (e.g. _=./ is all possible options for the second character on the second line, starting from the Russian hat).

Finally we map the options to the inputs accordingly .=, split into rows of length 7 7/ and riffle in some newlines N*.

Test runs

11111111

 _===_ 
 (.,.) 
<( : )>
 ( : )

22222222
  ___  
 ..... 
\(o.o)/
 (] [) 
 (" ")

33333333
   _   
  /_\  
 (O_O) 
/(> <)\
 (___)

44444444
  ___  
 (_*_) 
 (- -) 
 (   ) 
 (   )
\$\endgroup\$
19
\$\begingroup\$

TI-BASIC, 397 bytes

Important: If you want to test this out, download it from here and send that file to your calculator. Do not try to copy the code below into TI-Connect CE's program editor or SourceCoder 3 or something to build and send it to your calculator; in TI-Connect's case, it'll say it has an invalid token. SC3 uses the backslash as a comment delimiter (// starts a comment in SC3; /\/, though, will export as //) and so it won't export the arms and hat and such correctly, causing the program to both display the incorrect body parts and throw an ERROR:DOMAIN every now and then. Fun stuff!

Important #2: I'm too lazy to fix the download at the moment, so when you transfer it to your calc, change the 7 on the third line from the bottom to X+6. The code below is fixed if you need to compare.

Input Str9
seq(inString("1234",sub(Str9,I,1)),I,1,length(Ans→L1
"      ___   _   ___ →Str1
"_===_..... /_\ (_*_)→Str2
",._ →Str3
"•oO-→Str4
"<\/ →Str5
">/\ →Str6
" : ] [> <   →Str7
" : ¨ ¨___   →Str8
"Str1Str2Str3Str4Str5Str6Str7Str8→Str0
For(X,3,5
Output(X,2,"(   )
End
L1
Output(3,3,sub(Str4,Ans(3),1)+sub(Str3,Ans(2),1)+sub(Str4,Ans(4),1
Ans(5
Output(4-(Ans=2),1,sub(Str5,Ans,1
L1(6
Output(4-(Ans=2),7,sub(Str6,Ans,1
L1-1
For(X,1,2
Output(X+3,3,sub(expr(sub(Str0,X+6,1)),1+3Ans(X+6),3
Output(X,2,sub(expr(sub(Str0,X,1)),1+5Ans(1),5
End

Bonus: I'm particularly fond of 12341214.

 _===_
 (O.-)/
<( : )
 (   )

Some notes:

  • It can definitely be golfed more, no question about that. I'm nearly positive that I can combine a majority, if not all, of the outputting into a single For( loop. Also, I'm pretty sure that I can merge some strings together.
  • In Str4 (the eyes) I use the "plot dot" ([2ND] → [0]CATALOG → [3]θ → scroll down, it's between ﹢ (small plus) and · (interpunct)) as opposed to a period so that the eyes don't line up with the comma, because that looks weird as hell.
  • In Str8 (base) I had to use a diaeresis (¨) instead of double quotes because there's no way to escape characters in TI-BASIC, and double quotes are used to start/end strings.
  • In TI-BASIC, there's no need to close parentheses and brackets if they're followed by a colon, newline or → (used for var assignment), and double quotes (strings) can stay unclosed when followed by a newline or →.
\$\endgroup\$
  • 1
    \$\begingroup\$ First, in the second line, length(Ans should be length(Str9; second, have you tried combining Str3 through Str6 into a single string? \$\endgroup\$ – lirtosiast May 17 '15 at 17:31
  • \$\begingroup\$ Oh, whoops! I think that's fixed in the download, though. Besides that, I haven't looked at this much since I made it, but I did mention that I could probably merge some strings together; I'll look into that sometime today/this week. \$\endgroup\$ – M. I. Wright May 17 '15 at 17:35
18
\$\begingroup\$

C, 280 272 264 bytes

Only partially golfed at this point, but this is a fun challenge.

#define P(n)[s[n]&3],
f(char*s){printf("  %.3s\n %.5s\n%c(%c%c%c)%c\n%c(%.3s)%c\n (%.3s)",
"___   ___ _"+*s%4*3,"(_*_)_===_..... /_\\"+*s%4*5,"  \\ "P(4)"-.o0"P(2)    
" ,._"P(1)"-.o0"P(3)"  /"P(5)" < /"P(4)"    : ] [> <"+s[6]%4*3," > \\"P(5)
"    : \" \"___"+s[7]%4*3);}

(With some extra \n for readability.) I expect the define should go away with further golfing.

A more readable version is

#define P(n)[s[n]&3],
f(char *s) {
  printf("  %.3s\n"
         " %.5s\n"
         "%c(%c%c%c)%c\n"
         "%c(%.3s)%c\n"
         " (%.3s)",
         "___   ___ _"+*s%4*3,                  /* Top of hat. */
         "(_*_)_===_..... /_\\"+*s%4*5,         /* Lower hat. */
         "  \\ "P(4)                            /* Upper left arm. */
         "-.o0"P(2)                             /* Left eye. */
         " ,._"P(1)                             /* Nose. */
         "-.o0"P(3)                             /* Right eye. */
         "  /"P(5)                              /* Upper right arm. */
         " < /"P(4)                             /* Lower left arm. */
         "    : ] [> <"+s[6]%4*3,               /* Torso. */
         " > \\"P(5)                            /* Lower right arm. */
         "    : \" \"___"+s[7]%4*3              /* Base. */
         );
}
\$\endgroup\$
12
\$\begingroup\$

C, 212 bytes

d;main(){char*t="##3#b#b3#bbb3#b#b##\r#3b1#+3@12b3@1b-3@1_b3b1#,#\r7#_##+51rR04/1b#61rR0,8#2##\r7?#2#+9#`A#9=###9#^?#,8A#_#\r#+:#%b#:=#b#:#%b#,#",p[9];for(gets(p);d=*t++;putchar(d-3))d=d<51?d:(p[d-51]-53)[t+=4];}

A readable version:

d;
main()
{
    char *t = "##3#b#b3#bbb3#b#b##\r"
              "#3b1#+3@12b3@1b-3@1_b3b1#,#\r"
              "7#_##+51rR04/1b#61rR0,8#2##\r"
              "7?#2#+9#`A#9=###9#^?#,8A#_#\r"
              "#+:#%b#:=#b#:#%b#,#",
        p[9]; // 9 bytes is just enough for the input string of length 8

    for (gets(p); d = *t++; putchar(d-3))
        d = d < 51 ? d : (p[d - 51] - 53)[t += 4];
}

I took the idea from the answer by Reto Koradi. There were several fun improvements I did, which may warrant posting a separate answer:

  • Converted from function to program (+10)
  • Moved newlines into the control string (-7)
  • Added 3 to all character codes to have fewer escaped chars like \" (-3)
  • Reading from the string with autoincrement; also replaced t[i++] by *t++ (-4)
  • Replaced while by for; removed {} (-4)
  • Simplified loop termination: reading until \0 (-9)
  • Transformed t[...],t+=4 to (...)[t+=4] to eliminate the comma operator (-1)

Why all that trouble? To share my favorite one, snow ghost:

   _
  /_\
\(. .)/
 (   )
 (___)
\$\endgroup\$
  • \$\begingroup\$ Can put d in the parens behind main \$\endgroup\$ – ceilingcat Dec 17 '18 at 17:48
10
\$\begingroup\$

JavaScript, 489 (without newlines and tabs)

x=' ';
d="   ";
h=['\n_===_',' ___ \n.....','  _  \n /_\\ ',' ___ \n(_*-)'];
n=[',','.','_',x];
e=['.','o','O','-'];
y=['>',,'\\',x];
u=['<',,'/',x];
t=[' : ','[ ]','> <',d;
b=[' : ','" "',"___",d];

j=process.argv[2].split('').map(function(k){return parseInt(k)-1});
q=j[4]==1;
w=j[5]==1;

console.log([
    h[j[0]].replace(/(.*)\n(.*)/g, " $1\n $2"),
    (q?'\\':x)+'('+e[j[2]]+n[j[1]]+e[j[3]]+')'+(w?'/':x),
    (!q?u[j[4]]:x)+'('+t[j[6]]+')'+(!w?y[j[5]]:x),
    x+'('+b[j[7]]+')'].join('\n'));

run with node snowman.js 33232124

\$\endgroup\$
  • 6
    \$\begingroup\$ Welcome to Code Golf! A few pointers: You may not need a parseInt call, since subtraction automatically tries to cast string operands to numbers. Also, you can get rid of the function wrapping and just lead with i=process.argv[2], unless you're using it for recursion or variable scoping. Additionally, you can get rid of s entirely and just do console.log([ ... ].join('\n')). \$\endgroup\$ – apsillers May 6 '15 at 12:55
  • 3
    \$\begingroup\$ Actually, you could do away with the input string-to-array conversion entirely if you put a leading comma in each of your arrays to increase the index of each item. It adds 7 , characters, but it allows you to remove more than 50. Finally, one very finicky optimization would be using q=j[4]-1 instead of q=j[4]==1 (and then flipping your use of q and !q). This will cause q to be 0 (a falsey value) when j[4] is 1, and otherwise a truthy nonzero value. This is the exact opposite of your current true/false values, so you simply switch q and !q. \$\endgroup\$ – apsillers May 6 '15 at 13:15
  • \$\begingroup\$ Sorry for the mound of feedback on your first answer! I personally find revising my submissions to be one of the most fun parts of golfing; my apologies if you don't share my feeling. :) \$\endgroup\$ – apsillers May 6 '15 at 13:18
  • \$\begingroup\$ @apsillers your feedback is greatly appreciated! I was about to go to sleep last night and then wrote this for fun with the full intention of widding it down to the simplest possible later. I'll be doing some edits tonight! \$\endgroup\$ – Christopher Reid May 6 '15 at 19:24
9
\$\begingroup\$

Pyth, 203 bytes

M@GCHgc"  ___

  ___
   _"bhzgc" (_*_)
 _===_
 .....
  /_\\"bhzs[g"  \ "@z4\(g"-.oO"@z2g" ,._"@z1g"-.oO"@z3\)g"  / "@z5)s[g" < /"@z4\(gc"   
 : 
] [
> <"b@z6\)g" > \\"@z5)++" ("gc"   
 : 
\" \"
___"bez\)

Lol. Try it online: Pyth Compiler/Executor

Explanation

First I define a helper function g, which takes a list and a char as input, converts the char into its ASCII-value and takes correspondent element (modular wrapping).

M@GCH  def g(G,H): return G[ord(H)]

The other things is just printing line by line. For instance the first line is:

 c"  ___\n\n  ___\n   _"b     split the string "  ___\n\n  ___\n   _" at "\n"
                         hz   first char in input
g                             apply g and print

Btw. I experimented a little bit with .F"{:^7}", which centers a string. Using it, I could save a few spaces in my code, but it doesn't save any bytes at the end.

\$\endgroup\$
9
\$\begingroup\$

R, 436 437 bytes

Here's my first try on , using R which isn't the shortest but still fun. At least I'm beating JavaScript (for now)...

H=c("_===_"," ___\n .....","  _\n  /_\\"," ___\n (_*_)")
N=c(",",".","_"," ")
L=c(".","o","O","-")
X=c(" ","\\"," "," ")
S=c("<"," ","/"," ")
Y=c(" ","/"," ","")
U=c(">"," ","\\","")
T=c(" : ","] [","> <","   ")
B=c(" : ","\" \"","___","   ")
f=function(x){i=as.integer(strsplit(x,"")[[1]]);cat(" ",H[i[1]],"\n",X[i[5]],"(",L[i[3]],N[i[2]],L[i[4]],")",Y[i[6]],"\n",S[i[5]],"(",T[i[7]],")",U[i[6]],"\n"," (",B[i[8]], ")",sep="")}

Testing:

> f("12344321")
 _===_
 (O.-) 
 (] [)\
 ( : )

I actually struggled with X and Y being multilined but with stuff in between, ended up separating each line in (X, S) and (Y, U).

function and conversion from string to integer are also very verbose.

Edit 436 => 437

Had to fix a missing empty space noticed by @OganM

I could reduce to 428 replacing the line breaks between variables with ;, but the "one-lined" code looks so bad and unreadable I won't be that greedy.

\$\endgroup\$
  • \$\begingroup\$ you need and extra char for the 4th hat \$\endgroup\$ – OganM May 7 '15 at 18:54
  • \$\begingroup\$ @OganM Thanks for that extra byte! :( Fixed. \$\endgroup\$ – Molx May 7 '15 at 19:16
  • \$\begingroup\$ When doing codegolf we generally count each new line as one character (as it is on *nix) as opposed to two (as in Windows). So it shouldn't matter whether you use semicolon or new line. \$\endgroup\$ – ace_HongKongIndependence May 8 '15 at 23:54
  • \$\begingroup\$ @ace Thanks for the tip, good to know! \$\endgroup\$ – Molx May 9 '15 at 2:56
8
\$\begingroup\$

Haskell, 361 306 289 bytes

o l a b=take a$drop((b-1)*a)l
n="\n"
p i=id=<<["  ",o"    \n _===____ \n ..... _  \n  /_\\ ___ \n (_*_)"11a,n,o" \\  "1e,o"(.(o(O(-"2c,o",._ "1 b,o".)o)O)-)"2d,o" /  "1f,n,o"< / "1e,o"( : )(] [)(> <)(   )"5g,o"> \\ "1f,n," (",o" : )\" \")___)   )"4h]where[a,b,c,d,e,f,g,h]=map(read.(:[]))i

Usage:

putStrLn $ p "12333321"

 _===_
 (O.O) 
/(] [)\
 ( : )

How it works: index every element of the list of [hat options, left upper arm options, left eye options, ..., base options] with the corresponding input number and concatenate it into a single list. I've split the left and right arm into an upper and lower part, so that I can build the snowman line by line.

My favorite is the classic 11112211.

Edit: switched from list of strings to strings for the parts (hat, eye, ...). Needs a second parameter, the length of the substring to take.

Edit II: extracted common substrings

\$\endgroup\$
8
\$\begingroup\$

C, 233 230 bytes

char*t="  0 _ _0 ___0 _ _   0_. (0=./_0=._*0=.\\_0_. ) 4 \\  (2.oO-1,._ 3.oO-)5 /  4< / (6 ]> 6:   6 [< )5> \\  (7 \"_ 7: _ 7 \"_ ) ";i,r,d;f(char*p){while(r++<35){d=t[i]-48;putchar(t[d<0?i:i+p[d]-48]);i+=d<0?1:5;r%7?0:puts("");}}

With newlines and whitespace for better readability:

char* t = "  0 _ _0 ___0 _ _   0_. (0=./_0=._*0=.\\_0_. ) 4 \\  (2.oO-1,._ 3.oO-)5 /  4< / (6 ]> 6:   6 [< )5> \\  (7 \"_ 7: _ 7 \"_ ) ";
i, r, d;
f(char* p)
{
    while (r++ < 35)
    {
        d = t[i] - 48;
        putchar(t[d < 0 ? i : i + p[d] - 48]);
        i += d < 0 ? 1 : 5;
        r % 7 ? 0 : puts("");
    }
}

The whole thing is fairly brute force. It uses a table that contains one entry for each of the 35 (5 lines with length 7) characters. Each entry in the table is either:

  • A constant character: , (, ). Length of table entry is 1 character.
  • Index of body part, followed by the 4 possible characters depending on the part selection in the input. Length of table entry is 5 characters.

The code then loops over the 35 characters, and looks up the value in the table.

\$\endgroup\$
8
\$\begingroup\$

R 414 Bytes

Slightly modified version of Molx's version

W =c("_===_"," ___\n .....","  _\n  /_\\"," ___\n (_*_)",",",".","_"," ",".","o","O","-"," ","\\"," "," ","<"," ","/"," "," ","/"," ","",">"," ","\\",""," : ","] [","> <","   "," : ","\" \"","___","   ")
f=function(x){i=as.integer(strsplit(x,"")[[1]]);cat(" ",W[i[1]],"\n",W[i[5]+12],"(",W[i[3]+8],W[i[2]+4],W[i[4]+8],")",W[i[6]+20],"\n",W[i[5]+16],"(",W[i[7]+28],")",W[i[6]+24],"\n"," (",W[i[8]+32], ")",sep="")}

Just merged the seperate variables into one. Shawing of some space that was used for X=c( routine.

\$\endgroup\$
7
\$\begingroup\$

CJam, 200 191 bytes

This can surely be golfed a lot. (Specially if I base encode it). But here goes for starters:

7S*"_===_  ___  .....   _    /_\   ___  (_*_)"+6/2/Nf*",._ "1/".oO-"1/_" <\  /   >/  \  "2/4/~" : ] [> <    : \" \"___   "3/4/~]l~Ab:(]z::=:L0=N4{L=}:K~0='(2K1K3K')5K0=N4K1='(6K')5K1=NS'(7K')

Input goes into STDIN. For example, input 23232223 gives:

  ___ 
 .....
\(o_O)/
 (] [) 
 (___)

Try it online here

\$\endgroup\$
7
\$\begingroup\$

Haskell, 333 bytes

My first submission! Builds the snowman from top to bottom, left to right. I split the arms into two functions for each arm, the part next to head and the part next to the body.

The function s takes a list of integers and concatenates the output of the functions which produce the body parts given correct sublists of the input.

a=y["\n _===_\n","  ___ \n .....\n","   _  \n  /_\\ \n","  ___ \n (_*_)\n"]
d=y",._ "
c=y".oO-"
e=y"< / "
j=y" \\  "
f=y"> \\ "
k=y" /  "
y w n=w!!(n-1)
h=y[" : ","] [","> <","   "]
b=y[" ( : ) \n"," (\" \") \n"," (___) \n"," (   ) \n"]
s(m:x:o:p:n:q:t:l:_)=putStr$a m++j x:'(':c o:d n:c p:')':k q:'\n':e x:'(':h t++')':f q:'\n':b l

It relies on the function

y :: [a] -> Int -> a
y w n=w!!(n-1)

which returns the nth element of the list it is given. This allows for the list of hats in a, as well as things like

k=y" /  "

all of these functions use a beta reduction so their argument is passed as the index to the y function.

Output:

λ> s $ repeat 1

 _===_
 (.,.) 
<( : )>
 ( : ) 

λ> s $ repeat 2
  ___ 
 .....
\(o.o)/
 (] [) 
 (" ") 

λ> s $ repeat 3
   _  
  /_\ 
 (O_O) 
/(> <)\
 (___) 

λ> s $ repeat 4
  ___ 
 (_*_)
 (- -) 
 (   ) 
 (   ) 
\$\endgroup\$
  • \$\begingroup\$ @Calvin'sHobbies Thanks, I think I've fixed that now. \$\endgroup\$ – Craig Roy May 7 '15 at 19:23
7
\$\begingroup\$

Python 3, 349 336 254 251 bytes

So much for doing my thesis.

Here's the content of the file snowman.py:

l='_===_| ___\n .....|  _\n  /_\| ___\n (_*_)| : |] [|> <|   |>| |\| | : |" "|___|   '.split('|')
l[4:4]=' \  .oO-,._ .oO- /  < / '
def s(a):print(' {}\n{}({}{}{}){}\n{}({}){}\n ({})'.format(*[l[4*m+int(a[int('0421354657'[m])])-1]for m in range(10)]))

And this is how I conjure my favourite snowman:

s('11112311')

 _===_ 
\(.,.) 
 ( : )\
 ( : ) 

Explanation

# Create a list containing the 4 * 10 body parts of the snowman in order of drawing:
#   hats,
#   upper left arms, left eyes, noses, right eyes, upper right arms,
#   lower left arms, torso's, lower right arms,
#   bases
l='_===_| ___\n .....|  _\n  /_\| ___\n (_*_)| : |] [|> <|   |>| |\| | : |" "|___|   '.split('|')
l[4:4]=' \  .oO-,._ .oO- /  < / '
# This is the function that draws the snowman
# All the lines of this function are golfed in a single statement, but seperated here for clearity
def s(a):
    # In this list comprehension I put the elements of l that are chosen according to the parameters
    list_comprehension = []
    # m is the number of the body part to draw
    for m in range(10):
        # Get the index for the choice of the m-th bodypart
        # (example: the 2nd bodypart (m = 1: the upper left arm) is in the 4th place of the arguments list)
        choice_index = int('0421354657'[m])
        # n is the parameter of the current bodypart
        n = int(a[choice_index]) - 1
        # Add the body part from list l to the list comprehenseion
        list_comprehension.append( l[4 * m + n] )
    # Print the list comprehension with the static parts
    print(' {}\n{}({}{}{}){}\n{}({}){}\n ({})'.format(*list_comprehension))
\$\endgroup\$
  • \$\begingroup\$ You can remove the space in line 2 between [int(i)] and for. Similarly you can remove the space in line 7 between f(int(i)) and for. Also, in your print() statement you don't need to print the final space - it is not part of the snowman. Finally, change your print() call to a single-line print("{}\n{}({}{}{}){}\n{}({}){}\n ({})".format(*c)). Each of these should save you 1 byte, saving a total of 4 bytes :) \$\endgroup\$ – ace_HongKongIndependence May 9 '15 at 0:06
  • 1
    \$\begingroup\$ Also, instead of using the global variable n, you can define an attribute of function f. So you can replace lines 5-6 with: def f(m):f.n+=1;return l[4*m+int(b[f.n])-1] <newline> f.n=-1. This reduces 3 more bytes. \$\endgroup\$ – ace_HongKongIndependence May 9 '15 at 0:14
  • 1
    \$\begingroup\$ @ace Thanks, never heared of the function attribute before, learned something new! \$\endgroup\$ – Matty May 9 '15 at 13:01
6
\$\begingroup\$

PowerShell, 199 bytes

Inspired by Reto Koradi and anatolyg.

for($t='  0 _ _0 ___0 _ _
 0_. (0=./_0=._*0=.\_0_. )
4 \  (2.oO-1,._ 3.oO-)5 /  
4< / (6 ]> 6:   6 [< )5> \ 
 (7 "_ 7: _ 7 "_ )';$d=$t[$i++];$r+="$d"){if($d-ge48){$d=$t[$i+"$args"["$d"]-49]
$i+=4}}$r

Try it online!

Note: The line 3 has 2 trail spaces, line 4 has a trail space.

My favorite is 44444444 "sleepy russian guard":

 ___
(_*_)
(- -)
(   )
(   )
\$\endgroup\$
5
\$\begingroup\$

JavaScript (ES6), 247

Not as good ad @NinjaBearMonkey's :(

Test in snippet (with Firefox)

S=p=>([h,n,c,d,l,r,t,b,e,x]=[...p,' .oO-',`1_===_1 ___
 .....1  _
  /_\\1 ___
 (_*_)1 : 1] [1> <1   1 : 1" "1___1   `.split(1)],` ${x[h]}
${'  \\  '[l]}(${e[c]+' ,._ '[n]+e[d]})${'  /  '[r]}
${' < / '[l]}(${x[3-~t]})${' > \\ '[r]}
 (${x[7-~b]})`)

// TEST // 

function go()
{
  var n=N.value
  if (/^[1-8]{8}$/.test(n)) {
    s=S(n)
    OUT.innerHTML = s+'\n'+n+'\n\n'+ OUT.innerHTML
  }
  else N.focus()
}
  
<input id=N maxlength=8><button onclick="go()">Test</button>
<pre id=OUT></pre>

\$\endgroup\$
3
\$\begingroup\$

05AB1E, 137 135 128 122 bytes

…( )7ÝJ»•αγʒδÓ₂©8¥ŽQxΣxêÿ•12вèJIvN”</[(
._-=:"ÆŸ,*”º•DùÙÂ+;Èγтáì³ÓW©ÎÂ_`ƒ≠îj*ΓçÊ~ÞÒ¸β¦oåb/õ47/vÎΓ”›≠øØZµλݺ•20в趡Nè4äyè.;

-6 bytes thanks to @Grimy.

Try it online or verify a few more test cases.

Explanation:

We first create the template-string:

…( )         # Push string "( )"
7ÝJ          # Push a list in the range [0,7] joined together: "01234567"
»            # Join both by a newline: "( )\n01234567"
•αγʒδÓ₂©2°ćì₂òη₆½•
             # Push compressed integer 80545642885242518310229085147411483894
 12в         # Convert it to Base-12 as list: [1,4,4,4,4,4,3,1,4,4,4,4,4,3,8,0,6,5,7,2,9,3,8,0,10,10,10,2,9,3,1,0,11,11,11,2]
    è        # Index each into the string: [" ","0","0","0","0","0","\n"," ","0","0","0","0","0","\n","4","(","2","1","3",")","5","\n","4","(","6","6","6",")","5","\n"," ","(","7","7","7",")"]
     J       # And join it to a single string: " 00000\n 00000\n4(213)5\n4(666)5\n (777)"

Which looks like this:

 00000
 00000
4(213)5
4(666)5
 (777)

Then I loop over the digits of the input:

I            # Get the input
 v           # Loop `y` over each of its digits:

And do the following:
Push the (0-indexed) index N of the list:

  N          # Push the index of the loop

Push all possible parts as a list of character lists:

  ”</[(
  ._-=:"ÆŸ,*”
            "# Push dictionary string "</[(\n._-=:" Oo,*"
   º         # Mirror each line: "</[()]\>\n._-=:" Oo,**,oO ":=-_."
  •DùÙÂ+;Èγтáì³ÓW©ÎÂ_`ƒ≠îj*ΓçÊ~ÞÒ¸β¦oåb/õ47/vÎΓ”›≠øØZµλݺ•
             # Push compressed integer 492049509496347122906361438631265789982480759119518961177677313610613993948059787418619722816092858096158180892708001681647316210
   20в       # Convert it to Base-20 as list: [15,10,10,10,15,3,10,19,10,4,15,15,15,15,15,10,12,12,12,10,15,10,10,10,15,9,9,9,9,9,15,15,10,15,15,15,1,10,6,15,8,15,18,9,10,8,11,9,17,16,8,11,9,17,16,8,15,15,15,0,6,15,15,1,8,15,15,15,7,1,15,15,6,8,15,15,15,15,13,15,5,15,2,7,15,0,8,15,15,15,15,13,15,14,15,14,10,10,10]
      è      # Index each into the string: [" ","_","_","_"," ","(","_","*","_",")"," "," "," "," "," ","_","=","=","=","_"," ","_","_","_"," ",".",".",".",".","."," "," ","_"," "," "," ","/","_","\"," ","\n"," ",",",".","_","\n","-",".","o","O","\n","-",".","o","O","\n"," "," "," ","<","\"," "," ","/","\n"," "," "," ",">","/"," "," ","\","\n"," "," "," "," ",":"," ","]"," ","[",">"," ","<","\n"," "," "," "," ",":"," ","""," ",""","_","_","_"]
       ¶¡    # Split it by the newline character: [[" ","_","_","_"," ","(","_","*","_",")"," "," "," "," "," ","_","=","=","=","_"," ","_","_","_"," ",".",".",".",".","."," "," ","_"," "," "," ","/","_","\"," "],[" ",",",".","_"],["-",".","o","O"],["-",".","o","O"],[" "," "," ","<","\"," "," ","/"],[" "," "," ",">","/"," "," ","\"],[" "," "," "," ",":"," ","]"," ","[",">"," ","<"],[" "," "," "," ",":"," ","""," ",""","_","_","_"]]

Use the loop index N to get the character-list of the part we are currently working with:

  Nè         # Index the loop index into it
             #  i.e. 6 → [" "," "," "," ",":"," ","]"," ","[",">"," ","<"]

Then split the character list into four equal part, and use the input-digit y (which is 1-indexed) to index into it. (NOTE: Since 05AB1E is 0-indexed, but the input is 1-indexed, it would be logical to decrease the digit by 1 before indexing. However, since 05AB1E has automatic wraparound (i.e. indexing 3 in list [1,3,5] will result in 1), I simply rotated the parts once so parts with nr 4 in the challenge description, are at the front of the lists.)

    4ä       # Split it into 4 equal parts
             #  i.e. [[" "," "," "],[" ",":"," "],["]"," ","["],[">"," ","<"]]
      yè     # Index the input-digit `y` into it (with automatic wraparound)
             #  i.e. 4 → [" "," "," "]

And then replace the 0-indexed index of the loop we pushed at first, one by one with the part-characters:

  .;         # Replace first; every index of the loop `N` in the template-string
             # is replaced one by one with the characters

And in the end the result is output implicitly.

See this 05AB1E tip of mine (section How to compress large integers? and How to compress integer lists?) to understand how the compression parts work.


As for my favorite, it's still the same 'snow rabbit' as 1.5 year ago when I posted my Java solution:

44114432:
   _  
 (_*_)
 (. .) 
 (> <) 
 (" ")
\$\endgroup\$
  • \$\begingroup\$ -4, just enough to beat CJam! \$\endgroup\$ – Grimmy Sep 11 at 15:15
  • 1
    \$\begingroup\$ Down to 122, and also closer to what you originally had. \$\endgroup\$ – Grimmy Sep 11 at 15:38
  • \$\begingroup\$ @Grimy Your 122 byte version has a 0 between its eyes. :) \$\endgroup\$ – Kevin Cruijssen Sep 11 at 16:40
  • \$\begingroup\$ Just a base-12 encoding mistake, should be easy enough to fix! \$\endgroup\$ – Grimmy Sep 11 at 16:45
  • \$\begingroup\$ @Grimy You're right. I didn't had a lot of time yesterday, but it's indeed a simple fix in the list. Thanks for the -6! :) \$\endgroup\$ – Kevin Cruijssen Sep 12 at 5:50
2
\$\begingroup\$

Java 8, 548 545 432 401 399 bytes

a->{int q=50,H=a[0]-49,N=a[1],L=a[2],R=a[3],X=a[4],Y=a[5];return"".format(" %s%n %s%n%c(%c%c%c)%c%n%c(%s)%c%n (%s)",H<1?"":H%2<1?" ___":"  _","_===_s.....s /_\\s(_*_)".split("s")[H],X==q?92:32,L<q?46:L<51?111:L<52?79:45,N<q?44:N<51?46:N<52?95:32,R<q?46:R<51?111:R<52?79:45,Y==q?47:32,X<q?60:X%2<1?32:47,"   s : s] [s> <".split("s")[a[6]%4],92-(Y%3+Y%6/4)*30,"   s : s\" \"s___".split("s")[a[7]%4]);}

Try it here.

Explanation:

a->{             // Method with character-array parameter and String return-type
  int q=50,      //  Temp integer with value 50 to reduce the byte-count
      H=a[0]-49, //  The hat-character as unicode value minus 49: 1=0; 2=1; 3=2; 4=3
      N=a[1],L=a[2],R=a[3],X=a[4],Y=a[5];
                 //  Most of the other characters as unicode values: 1=49; 2=50; 3=51; 4=52
  return"".format(" %s%n %s%n%c(%c%c%c)%c%n%c(%s)%c%n (%s)",
                                               // Return the snowman with:
    H<1?"":H%2<1?" ___":"  _",                 //  The top of the hat
    "_===_s.....s /_\\s(_*_)".split("s")[H],   //  + the bottom of the hat
    X==q?92:32,                                //  + the top of the left arm
    L<q?46:L<51?111:L<52?79:45,                //  + the left eye
    N<q?44:N<51?46:N<52?95:32,                 //  + the nose
    R<q?46:R<51?111:R<52?79:45,                //  + the right eye
    Y==q?47:32,                                //  + the top of the right arm
    X<q?60:X%2<1?32:47,                        //  + the bottom of the left arm
    "   s : s] [s> <".split("s")[a[6]%4],      //  + the torso
    92-(Y%3+Y%6/4)*30,                         //  + the bottom of the right arm
    "   s : s\" \"s___".split("s")[a[7]%4]);}  //  + the feet

My favorite:

44114432:
   _  
 (_*_)
 (. .) 
 (> <) 
 (" ")

I don't know why, but it looks kinda cute. Like a bunny with a Russian hat instead of ears.

\$\endgroup\$
1
\$\begingroup\$

F#, 369 bytes

let f(g:string)=
 let b=" "
 let p=printfn
 let i x=int(g.[x])-49
 p"  %s  "["";"___";" _ ";"___"].[i 0]
 p" %s "["_===_";".....";" /_\ ";"(_*_)"].[i 0]
 p"%s(%c%c%c)%s"[b;"\\";b;b].[i 4]".oO-".[i 2]",._ ".[i 1]".oO-".[i 3][b;"/";b;b;b].[i 5]
 p"%s(%s)%s"["<";b;"/";b].[i 4][" : ";"] [";"> <";"   "].[i 6][">";b;"\\";b].[i 5]
 p" (%s) "[" : ";"\" \"";"___";"   "].[i 7]

Try it online!

Because g uses an array accessor, I need to explicitly specify the type in the function definition as a string, which is why the function definition has (g:string).

Apart from that, it's usually an array of strings accessed by an index. The hat, left and right arms which would go on separate lines are split into separate top and bottom arrays. The i function changes a number in the argument g into the array index. And the letter b replaces the one-space strings in the arrays.

Great challenge! My favourite snowman is probably 242244113:

  ___  
 ..... 
 (o o) 
 ( : ) 
 ( : ) 

im watching you

\$\endgroup\$
1
\$\begingroup\$

PHP, 378 bytes

<?$f=str_split;$r=$f($argv[1]);$p=[H=>'   _===____..... _  /_\ ___(_*_)',N=>',._ ',L=>'.oO-',R=>'.oO-',X=>' <\  /  ',Y=>' >/  \  ',T=>' : ] [> <   ',B=>' : " "___   '];echo preg_replace_callback("/[A-Z]/",function($m){global$A,$p,$r,$f;$g=$m[0];return$f($f($p[$g],strlen($p[$g])/4)[$r[array_search($g,array_keys($p))]-1])[(int)$A[$g]++];},'  HHH
 HHHHH
X(LNR)Y
X(TTT)Y
 (BBB)');

Try it online!

I like wise Mr. Owl 31333342

   _ 
  /_\ 
 (O,O) 
/(   )\
 (" ")
\$\endgroup\$
1
\$\begingroup\$

Python 2.7, 257 bytes (i think)

H,N,L,R,X,Y,T,B=map(int,i)
l='\n'
s=' '
e=' .o0-'
F='  \  / '
S=' < / \ >'
o,c='()'
print s+'      _ _ ___ _ _\n\n\n\n    _. (=./_=._*=.\__. )'[H::4]+l+F[X]+o+e[L]+' ,._ '[N]+e[R]+c+F[-Y]+l+S[X]+o+'  ]> :    [< '[T::4]+c+S[-Y]+l+s+o+'  "_ : _  "_ '[B::4]+c

where 'i' is the input as an string (e.g "13243213")

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to PPCG! As it happens, it is 256 bytes. Unfortunately, you cannot assume the input is stored in a variable. You can however replace i for input() for a total of 262 bytes \$\endgroup\$ – H.PWiz May 29 '18 at 19:19
0
\$\begingroup\$

Dart, 307 bytes

f(i,{r='.o0-',s=' : '}){i=i.split('').map((j)=>int.parse(j)-1).toList();return' ${['_===_',' ___ \n.....',' /_\\ ',' ___ \n (_*_)'][i[0]]}\n${' \\  '[i[4]]}(${r[i[2]]+',._ '[i[1]]+r[i[3]]})${' /  '[i[5]]}\n${'< /  '[i[4]]}(${[s,'] [','> <','  '][i[6]]})${'> \\ '[i[5]]}\n (${[s,'" "','___','   '][i[7]]})';}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Zsh, 247 bytes

try it online!!

(){H='_===_h ___
 .....h  _
  /_\h ___
 (_*_)'
W=' \  ' L=.oO- N=,._\  Y=' /  '
X='< / ' T=' : ] [> <   ' Z='> \ '
B=' : " "___   '
<<<" ${H[(ws:h:)$1]}
$W[$5]($L[$3]$N[$2]$L[$4])$Y[$6]
$X[$5](${T:3*($7-1):3})$Z[$6]
 (${B:3*($8-1):3})"
} ${(s::)1}

fav snowman:

43232122 Cossack dancer
  ___
 (_*_)
\(o_O) 
 (] [)>
 (" ")
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.