Draw an ASCII-O'-Lantern for Halloween

28

2

Halloween is almost here, the holiday after which most people need to wean themselves off a hollow diet of sugar.

Write a program that takes in a positive integer. If the integer is less than 31 (1 through 30), output this ASCII-art jack-o'-lantern, looking to the right as if looking forward to Halloween:

 _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

If the input is 31 (the October date Halloween is on), output the same ASCII-o'-lantern, but looking left:

 _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

If the input is greater than 31, output a bloated-looking ASCII-o'-lantern who probably ate too much candy. He can face either left or right since queasyness can be disorientating. So output:

 _____I_____
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|

or

 _____I_____
| | | | | | |
| | |o| |o| |
| | | |^| | |
| | |XXXXX| |
|_|_|_|_|_|_|

Whichever you prefer. It may even be different for different numbers above 31.

The shortest code in bytes wins.

Calvin's Hobbies

Posted 2016-10-24T23:11:21.113

Reputation: 84 000

Answers

8

JavaScript (ES6), 185 142 140 136 bytes

Now you can tweet-a-pumpkin!

n=>` _____I_____
0 4 1
02421
0 |^| 1
031
|_|_|_|_|_|_|`.replace(/\d/g,x=>x-2?x-3?x^n>30?"| |":"| | |":n>31?"XXXXX":"VvVvV":n>31?"o":"^")

Probably still room for improvement...

ETHproductions

Posted 2016-10-24T23:11:21.113

Reputation: 47 880

That x^n>30 trick had me confused at first but when I worked out what was going on I shamelessly stole it to improve my answer. As compensation I'm giving you an upvote for it anyway. – Neil – 2016-10-27T13:44:18.023

8

아희(Aheui), 914 bytes

붕빠뿌빠삮빠싸빠받따싼사주따반따퍄속맣이
숚뽀빠소뚜번범뻐터번선야챠슊산받발따다뿌
분뽀더번투빠뿌삮뿌다뿌쑬섣뽀빠뼈ㅇ뚜범쑬
받발따또싾솒빠쏟싿솓아삲쏠쑧뽀터벋터볼설
뿌뻐뻐뻐선썬뻐퍼섟썫선뻐퍼샧셗뺘쎣뺘뼈선
받따반타파빠빠받따받반타타싾삲빠빠빠빠뿌
숟썭뻐선썭뻐섣썭뻐선썭뻐섣썯터범떠범뻐선
빠싽술빠싽산빠싽삳빠싽숟삮쎨뿌서탸쥬싸셔
쀼이썭솓쀼섣싻이연우섞빠쏠뱐선반노쌹뻐숛
손빠쓞유삯쏢으산뽀쌹쏡야뼈섣싺이셗처솓썱
아솓썲솑쏢삱쏜빠쌄숞뚜범범섩뻐분터뿌뻐튜
번이손쎫ㅇ야샨우쌃이쀼뱔뿌떠뽀투또뿌뽀노
본떠벋뻐떠번떠숃볌쎬볌섩뿌빠뽀펴봄벌뽀뻐
샯이멓삭뭏ㅇㅇ이멓샥뎌뵥뿌븀범이멓삭뭏맣
맣이ㅇ몋섨희ㅇㅇㅇㅇㅇ먛뻐살뽀ㅇ솕멓샮속

Try it here! (please copy and paste the code manually)

Aheui might not be for golfing, but it's fun nonetheless. :)

Outputs:

N = 10

 _____I_____ 
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

N = 31

 _____I_____ 
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

N = 40

 _____I_____ 
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|

JungHwan Min

Posted 2016-10-24T23:11:21.113

Reputation: 13 290

4

Jelly, 73 bytes

“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’b8ị“ I|o^Xv_”
<32ị“o^XV“vX”y¢s13µ¹U31=³¤?Y

Full program
TryItOnline!

Might be possible to golf this with the aid of bounce, ŒḄ.

How?

“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’b8ị“ I|o^Xv_” - Link 1, Jack construction
“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’              - a base 250 integer
                               b8            - convert to base 8
                                 ị           - index into
                                  “ I|o^Xv_” - literal " I|o^Xv_"
                                             - makes this, without the line feeds:
                                                _____I_____ 
                                               | | | | | | |
                                               | |o| |o| | |
                                               | | |^| | | |
                                               | |XvXvX| | |
                                               |_|_|_|_|_|_|

<32ị“o^XV“vX”y¢s13µ¹U31=³¤?Y - Main link: n
<32                          - 1 if n is less than 32 else 0
   ị                         - index into
    “o^XV“vX”                - list of strings, ["o^XV","vX"]
             y               - map those characters (o->^ and X->V OR v->X) in string:
              ¢              -    call last link (1) as a nilad
               s13           - split into chunks of length 13
                  µ          - monadic chain separation
                          ?  - ternary if:
                         ¤   -     nilad and links as a nilad
                     31=³    -         31 equals first argument
                   ¹         -     identity (do nothing if true)
                    U        -     upend (reverse each if false)
                           Y - join with line feeds

Jonathan Allan

Posted 2016-10-24T23:11:21.113

Reputation: 67 804

3

Ruby, 137 bytes

Face points left on and after the 31st.

->n{puts ' _____I_____',(0..4).map{|i|s=[?|]*7*' _'[i/4]
s[5-n/31*2,5]=' | | o| |o |^| VvVvV_|_|_'[i*5,5];s.tr('ovV','^vVoX'[n/32*3,3])}}

Ungolfed in test program

f=->n{
  puts ' _____I_____',                                #Draw top of pumpkin
  (0..4).map{|i|                                      #then 5 more lines
    s=[?|]*7*' _'[i/4]                                #of 7 | separated by space or _ .
    s[5-n/31*2,5]=' | | o| |o |^| VvVvV_|_|_'[i*5,5]  #Add a line of face with 'o' eyes and 'VvVvV' mouth.
    s.tr('ovV','^vVoX'[n/32*3,3])                     #Substitute characters as necessary.
  }
}

f[gets.to_i]

Level River St

Posted 2016-10-24T23:11:21.113

Reputation: 22 049

3

Charcoal, 71 bytes

NβA‹β³²τA§o^τεA§XVτφA§XvτθF³«P↑⁵|_»↑⁵←I←×_⁵‖O→↙↙←←ε↙←^↖↓ε↓→φθφθφ¿⁼β³¹‖←

Note: This code does not work in the most recent commit as of posting, because string indexing is broken. It should, however, work in this version from October 25. It also runs successfully on the version currently on Try It Online.

Explanation

Charcoal is a language designed for ASCII-art. Output is put onto a canvas, which is printed at the end of the program.

Setup

Get input and calculate face characters:

Nβ        Input number into beta
A‹β³²τ    Assign beta<32 to tau for easy reuse
A§o^τε    Assign appropriate eye character (selected via indexing into "o^") to epsilon
A§XVτφ    Assign outside and middle mouth character to phi
A§Xvτθ    Assign other mouth character to theta

Draw the pumpkin

F³«  »    Do this three times:
P↑⁵       Draw a 5-character line upward (using | by default); don't move the cursor
|_         Draw that string, rightward

After this loop, we have

| | | 
| | | 
| | | 
| | | 
|_|_|_

Next:

↑⁵         Draw a 5-character line upward
←I         Draw the stem leftward
←×_⁵       Draw 5 underscores leftward
‖O→       Reflect the canvas rightward, overlapping in the middle

Result:

 _____I_____ 
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
|_|_|_|_|_|_|

Draw the face

We will draw the face looking rightward and change it later if necessary.

↙↙←←ε      Move to the correct spot and draw the right eye (our right, pumpkin's left)
↙←^        Move to the correct spot and draw the nose
↖↓ε        Move to the correct spot and draw the left eye
↓→φθφθφ    Move to the correct spot and draw the mouth with alternating characters

Result (for input 31):

 _____I_____ 
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

Reflect if it's Halloween:

¿⁼β³¹      If beta equals 31:
‖←         Reflect canvas leftward

Final output:

 _____I_____ 
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

DLosc

Posted 2016-10-24T23:11:21.113

Reputation: 21 213

2

Pyth - 84 bytes

Manual base compression.

+dj\Im*5\_2Xjb@_MBsMc5@L"^|_V ve"jC"mËÝ8|0càvll+DzSïë¬Ê"7qQ31"Vve"?>Q31"XXo""Vv^

Test Suite.

Maltysen

Posted 2016-10-24T23:11:21.113

Reputation: 25 023

2

PHP, 178 176 171 bytes

$e="| | ";$b=($n=$argv[1]-31)?" |^":"^| ";$c=$n<1?VvVvV:XXXXX;$a=$n<1?$b:" |o";echo" _____I_____\n$e$e$e|\n| |$a|$a$e\n$e|$b$e|\n| |",$n?" |$c":"$c| ","$e\n|_|_|_|_|_|_|";

could save 5 bytes with physical linebreaks. Run with -r.

Titus

Posted 2016-10-24T23:11:21.113

Reputation: 13 814

1

JavaScript (ES6), 163 125 bytes

f=
n=>` _____I_____
3 5 4
30504
3 |^| 4
3121214
|_|_|_|_|_|_|`.replace(/\d/g,c=>(n>31?`oXX`:`^Vv`)[c]||(c-3^n>30?`| |`:`| | |`))
;
<input type=number oninput=o.textContent=f(this.value)><pre id=o>

Now shamelessly stealing @ETHproduction's trick for positioning the face. Encoding: 0 is an eye, 1 and 2 are teeth, 3 is the left side, 4 is the right side and 5 is the bridge of the nose.

Neil

Posted 2016-10-24T23:11:21.113

Reputation: 95 035

1

V, 97 bytes

é|6i| Y5PÒ_r $.7|rIGÓ /_
3G3f r^jll.kll.5G3f RVvVvVLá
Àé*ñ30|l2GGkld$PñGñ31|l3GÓÞ/o
5GÓãv/Xñͪ

Try it online!

I'm dissapointed with how long this turned out. It is more convoluted than usual since V can barely handle numbers, a lot of bytes come from creating hacky conditionals. I would post a detailed explanation, but it took a long time to come up with, so I might get around to it later. Here is a hexdump:

0000000: e97c 3669 7c20 1b59 3550 d25f 7220 242e  .|6i| .Y5P._r $.
0000010: 377c 7249 47d3 202f 5f0a 3347 3366 2072  7|rIG. /_.3G3f r
0000020: 5e6a 6c6c 2e6b 6c6c 2e35 4733 6620 5256  ^jll.kll.5G3f RV
0000030: 7656 7656 1b4c e10a c0e9 2af1 3330 7c6c  vVvV.L....*.30|l
0000040: 3247 1647 6b6c 6424 50f1 47f1 3331 7c6c  2G.Gkld$P.G.31|l
0000050: 3347 d3de 2f6f 0a35 47d3 e376 2f58 f1cd  3G../o.5G..v/X..
0000060: aa                                       .

FYI this will run very slowly. It will take about 10 seconds. I know why this happens, and I'm looking into fixes.

James

Posted 2016-10-24T23:11:21.113

Reputation: 54 537

1

Pyth, 76 bytes

+dX*11\_5\IjbmX.<.[14d"| "yqQ31<G3?>Q31"XXo""Vv^"c"
|c| |c
|^
|ababa"bt*7"_|

Try it online.

Uses no compression. (I tried using some to a version of the face data string, but it ended up the same length.)

PurkkaKoodari

Posted 2016-10-24T23:11:21.113

Reputation: 16 699

1

Java 7, 237 bytes

String c(int n){char a=n==31?94:n>31?'o':32,b=n<31?'^':32;return(" _____I_____ \n~~~~~~|\n~|"+a+"|"+b+"|"+a+"|"+b+"~|\n~~|"+(n>31?94:a)+"|"+b+"~~|\n~"+(n<31?"~|VvVvV|":n==31?"|VvVvV~|":"|XXXXX~|")+" |\n|_|_|_|_|_|_|").replace("~","| ");}

Ungolfed & test code:

Try it here.

class M{
  static String c(int n){
    char a = n == 31
              ? 94
              : n > 31
                 ? 'o'
                 : 32,
         b = n < 31
              ? '^'
              : 32;
    return (" _____I_____ \n~~~~~~|\n~|"+a+"|"+b+"|"+a+"|"+b+"~|\n~~|"
        +(n > 31
           ? 94
           :a)
        +"|"+b+"~~|\n~"
        +(n < 31
           ? "~|VvVvV|"
           : n == 31
              ? "|VvVvV~|"
              : "|XXXXX~|")
        +" |\n|_|_|_|_|_|_|")
      .replace("~", "| ");
  }

  public static void main(String[] a){
    System.out.println(c(12));
    System.out.println();
    System.out.println(c(31));
    System.out.println();
    System.out.println(c(100));
  }
}

Output:

 _____I_____ 
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

 _____I_____ 
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

 _____I_____ 
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|

Kevin Cruijssen

Posted 2016-10-24T23:11:21.113

Reputation: 67 575

Isn't your golfed code only a function, not a full program? – Angzuril – 2016-10-25T15:37:39.757

ETHproductions's JavaScript solution is only a function, I don't see why it would be different for Java – brianush1 – 2016-10-26T12:37:07.760

1

Groovy Script, 273 265 216 202 198 bytes

i=args[0]as int
a=i<32?'^| |^':'o| |o'
b=i<32?'VvVvV':'XXXXX'
j=i>30
print" _____I_____\n| | | | | | |\n| |${j?"$a| ":" |$a"}| |\n| | |${j?'^| ':' |^'}| | |\n| |${j?"$b| ":" |$b"}| |\n|_|_|_|_|_|_|"

Ungolfed version

i = args[0] as int
a = i < 32 ? '^| |^' : 'o| |o'
b = i < 32 ? 'VvVvV' : 'XXXXX'
j = i > 30
print """ _____I_____
| | | | | | |
| |${j ? "$a| " : " |$a"}| |
| | |${j ? '^| ' : ' |^'}| | |
| |${j ? "$b| " : " |$b"}| |
|_|_|_|_|_|_|"""

Try it here

Edit

As Titus mentioned, I can save some size with i < 32 instead of i in 1..31

Edit 2

Removed all possible spaces around operators... Forgot to do so in the beginning

Edit 3

Rewrote ternary conditions to use the saved variable, replaced ; with newlines, removed explicit variable definition

Edit 4

As Otávio mentioned, I can save another 4 bytes if I switch from | |${j ? ' |^| | ' : ' | |^| '}| | to | | |${j ? '^| ' : ' |^'}| | |

Victor A.

Posted 2016-10-24T23:11:21.113

Reputation: 21

How about i < 32 instead of i in 1..31? – Titus – 2016-10-25T11:55:45.640

You can't get rid of the spaces around the operators? – Fund Monica's Lawsuit – 2016-10-26T06:22:01.787

Yes, I can... Totally forgot about this, thank you – Victor A. – 2016-10-26T07:43:05.613

As Groovy statements can be separated either by newline or ; and both are 1 character long, I would suggest to prefer the newline for readability. And give up with good coding habits, get rid of those int and def. – manatwork – 2016-10-26T07:56:31.677

In print's 1st ternary save the condition in a variable as (j=i>30), then in the next 2 use just j instead of repeating the same i>30 condition. – manatwork – 2016-10-26T08:03:33.343

You can save 4 bytes by changing the line | |${j ? ' |^| | ' : ' | |^| '}| | to | | |${j ? '^| ' : ' |^'}| | | – Otávio – 2016-10-27T03:33:15.420

You can do 'X'*5 for the mouth, probably for other repetition cases too. – Otávio – 2016-10-28T08:05:57.183

1

C++, 222 204 194 bytes

-18 bytes thanks to Kevin Cruijssen and -10 bytes for explicit top part

using S=std::string;S f(int n){char L[80],o=2*(n>30),i=-1;while(i++<80)L[i]=47<i&i<53?88:i%2?'|':i==20|i==24|i==36?n<32|i>35?94:'o':(i-o)%14?i-o<55?32:95:10;return" _____I_____ "+S(L+o,L+70+o);}

Ungolfed

#include <string>

using S=std::string;
S f(int n){
 char L[80];
 int o=2*(n>30);
 for (int i=0;i<80;i++){
  L[i]=
   (47<i && i<53) ?
   'X' :
   (
    (i%2) ?
    '|' :
    (
     i==20||i==24||i==36 ?
     (n<32||i>35?'^':'o') :
     ((i-o)%14?(i-o<55?' ':'_'):'\n')
    )
   );
 }
 return " _____I_____ " + S(L+o,L+70+o);
}

Karl Napf

Posted 2016-10-24T23:11:21.113

Reputation: 4 131

1I've only programmed in C++ once many years ago so I can't really remember much of it, but are parenthesis mandatory for ternary checks? If not, you could remove a lot of them. Also, is it possible to change the && to & and || to |? As summary, does using S=std::string;S f(int n){char L[80],o=2*(n>30),i=-1;while(i++<80)L[i]=47<i&i<53?88:i%2?'|':i==20|i==24|i==36?n<32|i>35?94:'o':i-o%14?i-o<55?32:95:10;S t(5,95);return' '+t+'I'+t+' '+S(L+o,L+70+o);} (202 bytes) compile & run? – Kevin Cruijssen – 2016-10-25T14:13:01.510

1@KevinCruijssen Yes you are right. Only the parenthesis around i-o is mandatory, so 204 bytes, – Karl Napf – 2016-10-25T14:22:49.160

1

PHP, 222 Bytes

for($s=" ".str_pad("I",11,_,2)." \n";$i<5;$i++)$s.=str_pad("",13,$i<4?"| ":"|_")."\n";$p=($a=$argv[1])<31||!($a%2)?2:0;$s=substr_replace($s,$a>31?XXXXX:VvVvV,$p+59,5);$s[$p+31]=$s[$p+35]=($a>31?o:"^");$s[$p+47]="^";echo$s;

Output

input:29
 _____I_____ 
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

input:30
 _____I_____ 
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

input:31
 _____I_____ 
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

input:32
 _____I_____ 
| | | | | | |
| | |o| |o| |
| | | |^| | |
| | |XXXXX| |
|_|_|_|_|_|_|

input:33
 _____I_____ 
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|

input:34
 _____I_____ 
| | | | | | |
| | |o| |o| |
| | | |^| | |
| | |XXXXX| |
|_|_|_|_|_|_|

input:35
 _____I_____ 
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|

Jörg Hülsermann

Posted 2016-10-24T23:11:21.113

Reputation: 13 026

0

Ruby, 168 bytes

->i{s=(Zlib.inflate Base64.decode64 "eJxTiAcBTzDJVaOABCG8OCiGycUhyYWVASGYF48EuRTwGhmHZkgckhzMQBKNzIdibEZGgAA2IwFZA1N4").lines;puts i<31?s[0..5]:i<32?s[6..11]:s[12..17]}

Probably far from optimal. Requires the base64 and zlib libraries.

Call as a lambda function.

dkudriavtsev

Posted 2016-10-24T23:11:21.113

Reputation: 5 781

0

Python 2, 167 bytes

i=input()
b='| |';e='^o'[i>31]+b;print'\n'.join(x[::[1,-1][i>30]]for x in[' _____I_____ ','| '*5+b,b+' |'+e+e,b+' | |^| '+b,b+' |'+['VvVvV','X'*5][i>31]+b,'|_'*6+'|'])

TFeld

Posted 2016-10-24T23:11:21.113

Reputation: 19 246

-1

C# 6, 223 215 bytes

int d=int.Parse(args[0]);var x="| | |\n| |";var s=d<31?" |^| |^| |\n| | | |^"+x+" |VvVvV":(d==31?"^| |^"+x+" |^| "+x+"VvVvV| ":"o| |o"+x+" |^| "+x+"XXXXX| ");Write(" _____I_____\n| | | | "+x+s+"| |\n|_|_|_|_|_|_|");

Entire program ungolfed:

using static System.Console;
namespace Halloween
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int d = int.Parse(args[0]);
            var x = "| | |\n| |";
            var s = d < 31 ? " |^| |^| |\n| | | |^" + x + " |VvVvV" 
                           : (d == 31 ? "^| |^" + x + " |^| " + x + "VvVvV| " 
                                      : "o| |o" + x + " |^| " + x + "XXXXX| ");
            Write(" _____I_____\n| | | | " + x + s + "| |\n|_|_|_|_|_|_|");
        }
    }
}

IonutC

Posted 2016-10-24T23:11:21.113

Reputation: 101

2This is just some code not a function or program, you can compile it to a Func<int, string> which is usually the shortest way of doing it. – TheLethalCoder – 2016-10-25T12:47:39.013

1I bet you can save some bytes by moving the conditions to the Write instead of declaring and defining s. – Titus – 2016-10-25T14:06:16.113

2And why \r\n instead of just \n? – Titus – 2016-10-25T14:07:39.410

no one stops you to do it better – IonutC – 2016-10-26T05:47:57.390

3They are just helping you! – MrPaulch – 2016-10-26T09:00:12.567