15
\$\begingroup\$

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.
asked Oct 31, 2019 at 18:54
\$\endgroup\$
2
  • 3
    \$\begingroup\$ Quite similar to Do you want to code a snowman?. \$\endgroup\$ Commented Oct 31, 2019 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\$ Commented Oct 31, 2019 at 19:11

8 Answers 8

5
\$\begingroup\$

Add++, 56 bytes

L,"&|\/^.oOv.oO ((("4$Tz£:BF"("+@32C3*$+Bh2ドルD-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 = ['((' '.' '^']
 2ドルD - 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
answered Nov 1, 2019 at 0:25
\$\endgroup\$
0
4
\$\begingroup\$

JavaScript (ES6), 78 bytes

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

Try it online!

answered Oct 31, 2019 at 21:03
\$\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

caird coinheringaahing
50.9k11 gold badges133 silver badges364 bronze badges
answered Oct 31, 2019 at 19:10
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is the 1* necessary in (2+1*w)? \$\endgroup\$ Commented Oct 31, 2019 at 20:49
  • \$\begingroup\$ @79037662 no :D thanks, i didn't see it when i changed it... \$\endgroup\$ Commented Oct 31, 2019 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!

answered Oct 31, 2019 at 22:16
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 28 bytes

↙§&×ばつ(⊕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.

answered Nov 1, 2019 at 0:46
\$\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!

answered Nov 1, 2019 at 8:14
\$\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!

answered Nov 1, 2019 at 12:35
\$\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!

answered Nov 1, 2019 at 11:43
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.