14
\$\begingroup\$

This question already has an answer here:

Today is Halloween and it's time to carve some pumpkins!

   &
((^.^))

Given an input integer, string, list of integers, etc., output the corresponding pumpkin. The input will always be of the form Stem, Eyes, Mouth, Width. For example, 2331 would be a valid input.

The pumpkin takes the form:

   S
((EME))

where S is the stem, E are the eyes, M is the mouth, and the parens form the body.

Definitions

Stem:
0 for a curl &
1 for a straight |
2 for a slant left \
3 for a slant right /

Eyes:
0 for angled ^
1 for small dots .
2 for medium dots o
3 for large dots O

Mouth:
0 for angled v
1 for small dot .
2 for medium dot o
3 for large dot O

Width:
0 for a skinny pumpkin (only one pair of parens)
1 for a fat pumpkin (two pairs of parens)

Examples

0011
   &
((^.^))

3100
   /
 (.v.)

2331
   \
((OOO))

1200
   |
 (ovo)

Rules

  • Input/output can be given by any convenient method.
  • You can print it to STDOUT or return it as a function result.
  • Either a full program or a function are acceptable.
  • Any amount of extraneous whitespace is permitted, provided the characters line up appropriately.
  • You must use the numbering and ordering of the pumpkin carvings as they are described above.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
\$\endgroup\$

marked as duplicate by pppery, A _, caird coinheringaahing, HyperNeutrino code-golf Nov 1 at 12:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    \$\begingroup\$ Quite similar to Do you want to code a snowman?. \$\endgroup\$ – manatwork Oct 31 at 19:06
  • \$\begingroup\$ @manatwork Hmm, that is kinda similar. I'll leave it up to the community to determine if that's a dupe target or not. \$\endgroup\$ – AdmBorkBork Oct 31 at 19:11
5
\$\begingroup\$

Add++, 56 bytes

L,"&|\/^.oOv.oO ((("4$Tz£:BF"("+@32C3*$+Bh$2D-1A:1+")"*J

Try it online!

Add++ is not the best at string manipulation challenges

How it works

We create an lambda function that takes a single argument - a list of integers - and outputs the final pumpkin.

L,                    - Define our function. Takes in a four element list e.g. [0 0 1 1]
                                                       STACK = [[0 0 1 1]]
  "&|\/^.oOv.oO ((("  - Push this string               STACK = [[0 0 1 1] '&|\/^.oOv.oO (((']
  4$T                 - Split it into 4 pieces         STACK = [[0 0 1 1] ['&|\/' '^.oO' 'v.oO' ' (((']
  z                   - Zip the lists together         STACK = [[['&|\\/' 0] ['^.oO' 0] ['v.oO' 1] [' (((' 1]]]
  £:                  - Index into each string         STACK = [['&' '^' '.' '(']]
  BF                  - Flatten the stack              STACK = ['&' '^' '.' '(']
  "("+                - Append a "(" to last element   STACK = ['&' '^' '.' '((']
  @                   - Reverse stack                  STACK = ['((' '.' '^' '&']
  32C3*$+             - Prepend 3 spaces to stalk      STACK = ['((' '.' '^' '   &']
  Bh                  - Output stack with newline      STACK = ['((' '.' '^']
  $2D                 - Push from under                STACK = ['((' '^' '.' '^']
  -1A:1+              - Add one the the last argument  STACK = ['((' '^' '.' '^' 2]
  ")"*                - Repeat ")" that many times     STACK = ['((' '^' '.' '^' '))']
  J                   - Join together                  STACK = ['((^.^))']
                      - Implicitly output
\$\endgroup\$
4
\$\begingroup\$

JavaScript (ES6), 78 bytes

(s,e,m,w)=>`   ${'&|\\/'[s]}
${' ('[w]}(${(e='^.oO'[e])+'v.oO'[m]+e})`+' )'[w]

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Python 3, 96 87 86 84 bytes

lambda s,e,m,w,a="^.oO":" "*(2+w)+"&|\/"[s]+"\n"+"("*-~w+a[e]+"v.oO"[m]+a[e]+")"*-~w

Try it online!

Thanks to:
- @79037662 for saving me 2 bytes

\$\endgroup\$
  • 1
    \$\begingroup\$ Is the 1* necessary in (2+1*w)? \$\endgroup\$ – 79037662 Oct 31 at 20:49
  • \$\begingroup\$ @79037662 no :D thanks, i didn't see it when i changed it... \$\endgroup\$ – Delta Oct 31 at 20:54
1
\$\begingroup\$

Wren, 98 90 bytes

A naive approach. I could have used a lookup table, it golfs out 8 bytes.

Fn.new{|a,b,c,d|" "*3+"&|\\/"[a]+"\n"+" ("[d]+"("+"^.oO"[b]+"v.oO"[c]+"^.oO"[b]+")"*(d+1)}

Try it online!

Wren, 148 144 bytes

An even worse solution, yet I'd like to share it. Does a bunch of replaces on the specified string

Fn.new{|a,b,c,d|"   S\nW(EME)w".replace("S","&|\\/"[a]).replace("W"," ("[d]).replace("w"," )"[d]).replace("E","^.oO"[b]).replace("M","v.oO"[c])}

Try it online!

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

Charcoal, 28 bytes

↙§&|\/N§^.oON←§v.oON←←×(⊕N‖B

Try it online! Link is to verbose version of code. Taking the inputs in a better order would save 2 bytes. Explanation:

↙§&|\/N

Input the stem and output the appropriate character, then move to the left eye.

§^.oON

Input the eyes and output the appropriate character.

←§v.oON←

Input the nose and output the appropriate character, then move to the left of the left eye.

←×(⊕N

Input the width and output the appropriate number of (s.

‖B

Reflect to complete the pumpkin.

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

PHP (7.4), 91 bytes

Generates the output string using a template string and strtr array replacement mode.

fn($s,$e,$m,$w)=>strtr('   0
3(121)4',['&|\/'[$s],'^.oO'[$e],'v.oO'[$m],' ('[$w],' )'[$w]])

Try it online!


PHP (7.4), 93 bytes

Generates the output string as it goes on.

fn($s,$e,$m,$w)=>'   '.'&|\/'[$s].'
'.' ('[$w].'('.($y='^.oO'[$e]).'v.oO'[$m]."$y)".' )'[$w];

Try it online!

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

Icon, 121 bytes

procedure f(s,e,m,w)
return map("   s\nw(eme)u","semwu","&|\\/"[s+1]||"^.oO"[e+1]||"v.oO"[m+1]||" ("[w+1]||" )"[w+1])
end

Try it online!

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

Red, 135 bytes

func[s e m w][a:["&|\/""^^.oO""v.oO"" ("" )"]rejoin["   "a/1/(s + 1) lf a/4/(t: w + 1) "("a/2/(u: e + 1) a/3/(m + 1) a/2/:u ")"a/5/:t]]

Try it online!

\$\endgroup\$

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