title: Scoop me an icecream please

text:
# Question
Title: Scoop me an icecream please
**Make me an icecream cone please**

We have a ton of great ice cream places here in New England. Most of them are closed for the winter now, so...

```
   .-@@-.
  (======)
 (--------)
(==========)
(__________)
 \/\/\/\/\/
  \/\/\/\/
   \/\/\/
    \/\/
     \/

```

**GOAL** Output the above icecream cone exactly. (or return it from a function)

This is code golf so shortest answer wins

# Answer
# SOGL V0.12, 24 bytes

```
u%⅝⁾⁷‰┘Η:⅛6s⁹№K⌠RΝīL°‘§╬

```

Try it Here!

A simple compression solution:

```
....‘    push "@-.¶===(¶----(¶=====(¶_____(¶\/\/\¶/\/\¶\/\¶/\¶\"
     §   pad with spaces and reverse horizontally
      ╬  palindromize with 0 overlap and mirroring the characters

```

No compression version \- way longer as SOGLs compression works nice for this
> 10 votes

# Answer
# Python 2, 95 bytes

```
i=9;print'   .-@@-.'
while i:print['('+~i*3/4*2%22*'-=_='[i%4]+')','\/'*i][i<6].center(12);i-=1

```

Try it online!
> 10 votes

# Answer
# PowerShell, 85 bytes

```
"   .-@@-.
  (======)
 (--------)
($('='*10))
($('_'*10))"
1..5|%{" "*$_+'\/'*(6-$_)}

```

Try it online!

OR

# PowerShell, 85 bytes

```
"   .-@@-.
  (======)
 (--------)"
'=','_'|%{"($($_*10))"}
1..5|%{" "*$_+'\/'*(6-$_)}

```

Try it online!

Take your pick. In both cases, the first three lines don't have enough bytes to do any sort of compression in PowerShell.

The first case uses string multiplication to produce each of the 10-length `=` and `_` lines, while the second uses a loop and string multiplication. In either case, the last line forms the cone, looping from `1` to `5` and each iteration outputting the appropriate number of spaces followed by the appropriate number of cone pieces.

All of those strings are left on the pipeline, and the implicit `Write-Output` at program completion gives us a newline between elements for free.
> 8 votes

# Answer
# , ~~48~~ 46 bytes

```
i\/5ñ>GÄXa/\ñS³ .-@@-.
  (¶=)
 (¸-)
(±=)
(±_)

```

Try it online!

Hexdump:

```
00000000: 695c 2f1b 35f1 3e47 c458 612f 5cf1 53b3  i\/.5.>G.Xa/\.S.
00000010: 202e 2d40 402d 2e0a 2020 28b6 3d29 0a20   .-@@-..  (.=).
00000020: 28b8 2d29 0a28 b13d 290a 28b1 5f29       (.-).(.=).(._)

```
> 7 votes

# Answer
# Charcoal, 29 bytes

```
@-.⸿Ｅ=-=⁺×ι⁺³κ)×_⁵Ｐ↙⁶)⸿‖Ｍ←¤/\

```

Try it online! Link is to verbose version of code. Explanation:

```
@-.⸿

```

Print the right half of the first line.

```
Ｅ=-=⁺×ι⁺³κ)

```

For each of the characters `=-=`, repeat 3 times for the first and an additional time for each subsequent character, then append a `)`, printing each result on its own line.

```
×_⁵

```

Print 5 `_`s.

```
Ｐ↙⁶

```

Print the edge of the cone.

```
)⸿

```

Print the final `)` and position the cursor inside the cone.

```
‖Ｍ←

```

Mirror the half cone.

```
¤/\

```

Fill the body of the cone.
> 7 votes

# Answer
# Python 2, 86 bytes

```
n=10
while n:print['\/'*n,'('+35/n*2*'-=_='[n%4]+')','.-@@-.'][-2%n/4].center(12);n-=1

```

Try it online!

Working off Lynn's solution.
> 7 votes

# Answer
# Perl 6, ~~115 95 94 92~~ 90 bytes

*3 bytes saved by AlexDaniel in #perl6 on irc.freenode.net*

```
say "   .-@@-.
  (======)
 (--------)
({"="x 10})
({"_"x 10})";say(' 'x++$,'\/'x$--+5)xx 5

```

Try it online!
> 5 votes

# Answer
# 05AB1E, 42 bytes

```
•3[ÜAʒg‰ŽÎ<\¦•6¡εS"-.@(=_"sèJ∞}'\∞5LR×‚˜.C

```

Try it online!

---

1026344463000063444446355555 is now the Icecream Number b/c nobody else has used it.

---

```
Full program: •3[ÜAʒg‰ŽÎ<\¦•6¡εS"-.@(=_"sèJ∞}'\∞5LR×‚˜.C
current >> •  ||  stack: []
current >> 6  ||  stack: [1026344463000063444446355555]
current >> ¡  ||  stack: [1026344463000063444446355555, '6']
current >> ε  ||  stack: [['102', '3444', '30000', '344444', '355555']]
For each: S"-.@(=_"sèJ∞
Full program: S"-.@(=_"sèJ∞
current >> S  ||  stack: ['102']
current >> "  ||  stack: [['1', '0', '2']]
current >> s  ||  stack: [['1', '0', '2'], '-.@(=_']
current >> è  ||  stack: ['-.@(=_', ['1', '0', '2']]
current >> J  ||  stack: [['.', '-', '@']]
current >> ∞  ||  stack: ['.-@']
stack > ['.-@@-.']
Full program: S"-.@(=_"sèJ∞
current >> S  ||  stack: ['3444']
current >> "  ||  stack: [['3', '4', '4', '4']]
current >> s  ||  stack: [['3', '4', '4', '4'], '-.@(=_']
current >> è  ||  stack: ['-.@(=_', ['3', '4', '4', '4']]
current >> J  ||  stack: [['(', '=', '=', '=']]
current >> ∞  ||  stack: ['(===']
stack > ['(======)']
Full program: S"-.@(=_"sèJ∞
current >> S  ||  stack: ['30000']
current >> "  ||  stack: [['3', '0', '0', '0', '0']]
current >> s  ||  stack: [['3', '0', '0', '0', '0'], '-.@(=_']
current >> è  ||  stack: ['-.@(=_', ['3', '0', '0', '0', '0']]
current >> J  ||  stack: [['(', '-', '-', '-', '-']]
current >> ∞  ||  stack: ['(----']
stack > ['(--------)']
Full program: S"-.@(=_"sèJ∞
current >> S  ||  stack: ['344444']
current >> "  ||  stack: [['3', '4', '4', '4', '4', '4']]
current >> s  ||  stack: [['3', '4', '4', '4', '4', '4'], '-.@(=_']
current >> è  ||  stack: ['-.@(=_', ['3', '4', '4', '4', '4', '4']]
current >> J  ||  stack: [['(', '=', '=', '=', '=', '=']]
current >> ∞  ||  stack: ['(=====']
stack > ['(==========)']
Full program: S"-.@(=_"sèJ∞
current >> S  ||  stack: ['355555']
current >> "  ||  stack: [['3', '5', '5', '5', '5', '5']]
current >> s  ||  stack: [['3', '5', '5', '5', '5', '5'], '-.@(=_']
current >> è  ||  stack: ['-.@(=_', ['3', '5', '5', '5', '5', '5']]
current >> J  ||  stack: [['(', '_', '_', '_', '_', '_']]
current >> ∞  ||  stack: ['(_____']
stack > ['(__________)']
current >> '  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)']]
current >> ∞  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], '\\']
current >> 5  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], '\\/']
current >> L  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], '\\/', '5']
current >> R  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], '\\/', [1, 2, 3, 4, 5]]
current >> ×  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], '\\/', [5, 4, 3, 2, 1]]
current >> ‚  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], ['\\/\\/\\/\\/\\/', '\\/\\/\\/\\/', '\\/\\/\\/', '\\/\\/', '\\/']]
current >> ˜  ||  stack: [[['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)'], ['\\/\\/\\/\\/\\/', '\\/\\/\\/\\/', '\\/\\/\\/', '\\/\\/', '\\/']]]
current >> .  ||  stack: [['.-@@-.', '(======)', '(--------)', '(==========)', '(__________)', '\\/\\/\\/\\/\\/', '\\/\\/\\/\\/', '\\/\\/\\/', '\\/\\/', '\\/']]
   .-@@-.
  (======)
 (--------)
(==========)
(__________)
 \/\/\/\/\/
  \/\/\/\/
   \/\/\/
    \/\/
     \/
stack > ['   .-@@-.\n  (======)\n (--------)\n(==========)\n(__________)\n \\/\\/\\/\\/\\/\n  \\/\\/\\/\\/\n   \\/\\/\\/\n    \\/\\/\n     \\/']

```

---

```
•3[ÜAʒg‰ŽÎ<\¦•               | Pushes 1026344463000063444446355555 to the stack.
-----------------------------+-------------------------------------------------
6¡                           | Split on 6's.
-----------------------------+-------------------------------------------------
  ε             }            | Loop on each piece to create the top of the icecream...
   S                         | Split into single chars.
    "-.@(=_"sè               | Substitute in the correct symbol for each number.
              J∞             | Join, then mirror.
-----------------------------+-------------------------------------------------
                 '\∞         | Push \/.
                    5LR      | Push [5,4,3,2,1]
                       ×     | Multiply '\/' by each 5,4,3,2 and 1.
                        ‚˜   | Join top to bottom.
                          .C | Center w/ newlines.

```
> 5 votes

# Answer
# Bubblegum, 50 bytes

```
00000000: 5350 50d0 d375 70d0 d5e3 5250 d0b0 0503  SPP..up...RP....
00000010: 4d2e 050d 5d28 d0e4 020b c224 34e2 e100  M...](.....$4...
00000020: a82a 461f 0681 9a91 980a 0896 0284 0161  .*F............a
00000030: 0100                                     ..

```

Try it online!
> 3 votes

# Answer
# C, 171 bytes

```
i;p(c,n,o){for(printf("%*c",o,i?32:40);n--;)printf(c);puts(i?"":")");}f(){p(".-@@-.",i=1,3);--i;p("=",6,3);p("-",8,2);p("=",10,1);p("_",10,1);for(i=6;--i;)p("\\/",i,6-i);}

```

Try it online!

# C, 146 bytes

```
f(){puts("   .-@@-.\n  (======)\n (--------)\n(==========)\n(__________)\n \\/\\/\\/\\/\\/\n  \\/\\/\\/\\/\n   \\/\\/\\/\n    \\/\\/\n     \\/");}

```

Just prints the hardcoded string.

Try it online!
> 3 votes

# Answer
# Python 2, ~~125~~ ~~120~~ ~~119~~ ~~116~~ 106 bytes

* Saved three bytes thanks to AdmBorkBork; golfed `in range(5,0,~0)` to `in[5,4,3,2,1]`.

```
print"   .-@@-.\n  (======)\n "+"(%s)\n"*3%("-"*8,"="*10,"_"*10),
for _ in 5,4,3,2,1:print" "*(6-_)+_*"\/"

```

Try it online!
> 2 votes

# Answer
# Python 2, 104 bytes

Borrowed a trick from Jonathan Frech's answer, and thanks to him for saving me some bytes too.

```
print"   .-@@-.\n  (======)\n "+"(%s)\n"*3%("-"*8,"="*10,"_"*10),
i=5
while i:print(6-i)*" "+"\/"*i;i-=1

```

Try it online!

---

### Python 2, 108 bytes

```
print"""   .-@@-.
  (======)
 (--------)
(==========)
(__________)"""
i=5
while i:print(6-i)*" "+"\/"*i;i-=1

```

Try it online!
> 2 votes

# Answer
# Japt, 50 bytes

```
5õ_ç"\\/"
c[AA8,6]£"({Xç"_=-="gY})"Ãp".-@"ê1¹w û ·

```

Try it online!
> 2 votes

# Answer
# Perl 5, 92 bytes

```
say'   .-@@-.
  (======)
 (--------)
(==========)
(__________)';$_='\/'x6;say while s%\\/% %

```

Try it online!
> 2 votes

# Answer
# Ruby, 97 bytes

```
i=-1
puts ['   .-@@-.']+123455543.digits.map{|n|(i+=1;i<4?"(#{'=-=_'[i]*n*2})":'\/'*n).center 12}

```

Try it online!

First time ever using Ruby, so tips are very welcome.
> 2 votes

# Answer
# Python 3, 202 bytes

This is pretty terrible, its more bytes than just defining the string and printing that even.

```
print("   .-@@-.")
print("  ("+"="*6+")")
print(" ("+"-"*8+")")
print("("+"="*10+")")
print("("+"_"*10+")")
print(" "+"\/"*5)
print("  "+"\/"*4)
print("   "+"\/"*3)
print("    "+"\/"*2)
print("     \/")

```

Try It Online
> 1 votes

# Answer
# Jelly, ~~74~~ 72 bytes

```
5RU⁾\/ẋ
5R×⁶ż¢Y
3,6,8,10,10j1ż“ “.-@@-.¶  (“=“)¶ (“-“)¶(“=“)¶(“_“)¶”P€;¢

```

Try it online!

**Explanation:**

```
5RU⁾\/ẋ    Link 1. Generate list of "\/"s for cone.
5RU        Range 5, reverse. Gets [5,4,3,2,1].
   ⁾\/     Literal string "\/".
      ẋ    Repeat. Gets ["\/\/\/\/\/","\/\/\/\/","\/\/\/","\/\/","\/"].

5R×⁶ż¢Y    Link 2. Generate rest of cone.
5R         Range 5. Gets [1,2,3,4,5].
  ×⁶       Repeat " " that many times. Gets [" ","  ","   ","    ","     "]
    ż¢     Zip that with the ¢ones. Gets a list of alternating space and cones.
      Y    Join with newlines. This puts it all together for the big cone.

3,6,8,10,10j1ż“ “.-@@-.¶  (“=“)¶ (“-“)¶(“=“)¶(“_“)¶”P€;¢    Link 3. Generate the top and put it on the cone.
10,10,8,6j1;1U                                                Generate list 3,1,6,1,8,1,10,1,10. Does this by joining [10,10,8,6] with ones, appending a one, and reversing.
               “   .-@@-.¶  (“=“)¶ (“-“)¶(“=“)¶(“_“)¶”        List of strings. This separates the completed parts from the non completed parts.
              ż                                               Zip 'em together. Gets [number, string, number, string, ...]
                                                      P€      Get the product of €ach. This completes the non completed strings by repeating them.
                                                        ;¢    Attach the ¢one to the end.

```
> 1 votes

# Answer
# Mathematica, 117 bytes

```
Column[Join[{".-@@-."},"("<>#<>")"&/@{"="~(T=Table)~6,"-"~T~8,"="~T~10,"_"~T~10},T[""<>T["\/",i],{i,5,1,-1}]],Center]

```

Outputs

you can test it on wolfram sandbox (although the fonts they use may destort the result a little)
> 1 votes

# Answer
# Pyth, 58 bytes

```
jm.[12@,*d"\/"@,".-@@-."j@*Vj11494 11"-=_="d"()"ndTgd6;_ST

```

Watch it in action!
> 1 votes

# Answer
# C, 138 bytes

```
f(i,j){puts("   .-@@-.\n  (======)\n (--------)\n(==========)\n(__________)");for(j=1;++j<7;i=puts(""))for(;i<7;)printf(i++<j?" ":"\\/");}

```

Try it online!
> 1 votes

# Answer
# C 165 bytes

```
y,x,z;f(){for(puts("   .-@@-.");y++<9;)for(;x=++x%14;)z=y+3-y/4,putchar(x<13?y<5?x-7^z-1?7-x^z?abs(x-7)<z?y<4?y&1?61:45:95:32:40:41:x+y>16|y-x>3?32:x+y&1?92:47:10);}

```
> 1 votes

# Answer
## VimL, 76 bytes

```
a   .-@@-.␤  ␤ ␛k6A=␛j8A-␛o␛10A=␛o␛10A_␛qaI(␛A)␛kq3@aGo ␛5A\/␛qayypxxI ␛q3@a

```

Animated with vimanim.py.
> 1 votes

# Answer
# C (gcc), ~~137~~ 136 bytes

-1 bytes thanks to ceilingcat

```
main(i){for(puts("   .-@@-.\n  (======)\n (--------)\n(==========)\n(__________)");8<printf("%*c%s\n",++i,92,"/\\/\\/\\/\\/\\/"+i*2););}

```

Try it online!
> 1 votes

# Answer
# Cubically, ~~345~~ 336 bytes

```
⇒@@@
RU+30f1+3-00@-2+3@+4@@-4@+2-3@-110@+31-4@@+2-4@+10f1f1-3+0@-400@+31-4@+2-4@+3-10f1f1@@-4+1@-400@+11@+10f1f1f1@-3+0@-400@+11@+4110@f1f1f1-22@-400@+31-4@+220@-43@+43@-43@+43@-43@+43@-43@+43@-43@-4000@+31-4@@+220@-43@+43@-43@+43@-43@+43@-43@-4000@+31-4f1+220@-43@+43@-43@+43@-43@-4000@+31-4f1@+220@-43@+43@-43@-4000@+31-4f1@@+220@-43@

```

Found via this tool and golfed via search-and-replace, with a couple custom optimizations.

Try it online!

---

Alternate method:

# 391 bytes (doesn't modify cube)

```
+5/1+3@@@:1/1+5@5.0+2@@5.0-2@-4@:5/1+3@@:4/1+4@:5+2/1+51@@@@@@:5/1+4@:1/1+1@:5/1+3@:4/1+4@5.05.05.05.05.05.05.05.0:5/1+4@:1/1+1@:4/1+4@:5+2/1+51@@@@@@@@@@:5/1+4@:1/1+1@:4/1+4@:5/1+55@@@@@@@@@@-51@:1/1+1@:5/1+3@:2/1+55@-5@+5@-5@+5@-5@+5@-5@+5@-5@:1/1+1@:5/1+3@@:2/1+55@-5@+5@-5@+5@-5@+5@-5@:1/1+1@:5/1+3@@@:2/1+55@-5@+5@-5@+5@-5@:1/1+1@:5/1+3@@@@:2/1+55@-5@+5@-5@:1/1+1@:5/1+3@@@@@:2/1+55@-5@

```
> 1 votes

---
Tags: code-golf, string, ascii-art, kolmogorov-complexity
---


title: When do I get my sandwich?

text:
# Question
Title: When do I get my sandwich?
Given one of the following inputs:

```
Sweet Onion Chicken Teriyaki
Oven Roasted Chicken
Turkey Breast
Italian BMT
Tuna
Black Forest Ham
Meatball Marinara
```
output a number from 1-7 (or 0-6) representing the day of the week that you get that deal, starting with Monday as the lowest number. Input can be all lowercase or uppercase if preferred (i.e "italian bmt"). No internet allowed.

# Answer
> 88 votes
# Python 2, ~~38~~ ~~30~~ 28 bytes

```
lambda S:`6793**164`[len(S)]

```

Try it online!

~~Unfortunately still **one** byte longer than the best Python 2 answer thus far; though not using the `enklact`-approach.~~

Now **one byte shorter** than i cri everytim's answer!

### How does it work?

After a lot of brute force, I found an expression that results in a number which has just the right digits.
I noticed that looking at only one specific digit of the given string's lengths required 3 bytes (`%10`). So I wrote another Python program (Pastebin link) to further search for numbers who directly map the input strings' lengths to the day of the week.

The magic number looks like this: `6793**164 = 28714733692312345620167113260575862840674216760386883406587492336415023761043044176257567032312859371641211117824224067391750766520256112063756278010050204239810862527958109285342869876264808102743173594017101607983288521836082497514383184553444755034407847810524083812459571382103831904835921560285915349760536969265992879312869538914200854305957428078269094250817029486005437991820466986793657301214564264748923199288698278615871481529585816783654841131577178922192383679718074693535597651237893794976519274268917335387876260270630339777501802739852278932279775510324916969726203688466311848240746465178859847331248655567344801` (a number with an impressive 629 decimal digits)

And as you can see, the number provides the necessary mapping from \[28, 20, 13, 11, 4, 16, 17\] to \[0, 1, 2, 3, 4, 5, 6\] (Python strings are 0-indexed):

`2871 **4** 733692 **3** 1 **2** 34 **5** **6** 20 **1** 6711326 **0** 5758628406742167603868834...
 [4]^ [11]^ [13]^ [16]^ ^[17] ^[20] ^[28]`

My program also found other expressions which yield numbers with the required property, though they take more bytes to represent (29 instead of 28): `19439**540`, `34052**726`, `39311**604`, `44873**182`, `67930**164` and `78579**469`. (Those are all the expressions found by the linked program; its execution took several hours.)

Alternative function that requires 28 bytes: `lambda S:`7954<<850`[len(S)]`
Alternative function that requires 29 bytes: `lambda S:`9699<<2291`[len(S)]`
Alternative function that requires 30 bytes: `lambda S:`853<<4390`[len(S)+9]`
Alternative function that requires 31 bytes: `lambda S:`1052<<3330`[len(S)+8]`

### How does it work? How did I generate that number? (30 byte answer)

The 30 byte answer was `lambda S:`3879**41`[len(S)%10]`.

Looking at the input string's lengths `[28, 20, 13, 11, 4, 16, 17]`, I noticed that all last digits in base ten differ, resulting in the list `[8, 0, 3, 1, 4, 6, 7]`. So I only needed a mapping from that list to the list of all seven days of the week, `[0, 1, 2, 3, 4, 5, 6]`.

My first approach simply used a string to perform the mapping: `lambda S:"13*24*560"[len(S)%10]`, though the string required eleven bytes (`"13*24*560"`).
So I wrote a Python program (Pastebin link) to test for arithmetic expressions which result in an integer with matching digits, hoping to further golf the program. What I came up with thus far is ``3879**41`` (only ten bytes, the only and thereby smallest expression my program finds).

Of course, there are many different possible expressions one could try; I just got lucky that there was one in the form `a**b` with a reasonably small result that fit my need.

Just for anyone curious, `3879**41 = 1372495608710279938309112732193682350992788476725725221643007306215781514348937145528919415861895033279220952836384201346579163035594383625990271079 = 1.372... * 10**147`.

Another valid function I found whilst searching for alternative expressions that unfortunately requires 32 bytes: `lambda S:`7**416`[len(S)%10+290]`

# Answer
> 58 votes
# Python 2, 29 bytes

```
lambda s:'enklact'.find(s[3])

```

Try it online!

## Explanation

The magic string, `enklact`, was found by looking for the first column with unique letters.

The first column goes `SOTITBM` which is not useful 'cause it contains duplicates. The second and third ones also don't work because they are `wvutule` and `eeranaa` respectively. The fourth column, however works as it has all unique letters.

```
lambda s:'enklact'.find(s[3])

lambda s:                      # declare a function that takes a single paramater s
                  .find(    )  # find the index of the first instance of...
                        s[3]   # the fourth (0-indexing) character of s...
         'enklact'             # in the magic string

```

# Answer
> 21 votes
# Python, 26 bytes

```
lambda S:1923136>>len(S)&7

```

Try it online!

With a debt of thanks (for my second straight code-golf try) to Jonathan Frech's answer -- I wouldn't have thought to use the string length instead of a distinguishing letter!

This code derives from my experience with De Bruijn Sequences and programming for chess.

In chess, you often work with several 64-bit integers, where each bit indicates something is true or false about the corresponding square on the chessboard, such as "there is a white piece here" or "this square contains a pawn".

It is therefore useful to be able to quickly convert `2**n` to `n` quickly and cheaply. In C and C++, the quickest way to do this is to multiply by a 64-bit De Bruijn sequence -- equivalent to shifting by `n` bits -- then right-shift 58 (to put the first six bits last -- make sure you're using an unsigned int or you'll get 1s half the time) and look up this 0..63 number in a table that gives you the corresponding `n` which is in the same range, but rarely the same number.

This is kind of related. Instead of changing from `2**n` to `n`, however, we want to change from `n` to some other 3-bit number. So, we hide our 3-bit numbers in a magic 31-bit number (a 28-bit shift requires bits 28-30, with numbering starting at 0.)

I generated the number needed by just seeing what values had to fall where (trying both 0..6 and 1..7 as the output sets). Fortunately, the overlapping values (14, 16, and 17) happen to work out! And since the first tri-bit is `000` and the next is `001`, we don't need the leftmost 7 bits, resulting in fewer digits -\> fewer bytes of source.

The required number is `000xxxx001110101011xxxx100xxxx`, where the x's can be 1 or 0 and it doesn't affect the result for these particular subs -- I set them to 0 just to minimize the number, but changing any of the last 8 xs shouldn't affect the source code's length. Setting all the xs to 0, and leaving off the start, gives 1923136 in decimal (or 1D5840 in hex, but then you need the 0x prefix -- shame!) The &7 at the end just masks the last 3 bits, you could also use %8, but then you'd need parentheses due to python's operator precedence rules.

tl;dr: 1923136 encodes each of the three-bit combinations from 0 to 6 in exactly the right spots that these sandwich names happen to fall in place, and then it's a matter of taking the last three bits after a right shift.

# Answer
> 12 votes
# Jelly, 10 bytes

<sup>**What's with all this "enklact" business?**</sup>

```
⁽ṃXị“Ð$¥»i

```

A monadic link taking a list of characters and returning the Monday=1 day of the week.

**Try it online!** or see the test-suite

### How?

```
⁽ṃXị“Ð$¥»i - Link: list of characters, sandwichName  e.g. "Tuna"
⁽ṃX        - base 250 literal                             -7761
   ị       - index into sandwichName (1-indexed & modular) 'n'
    “Ð$¥»  - dictionary word                               "retinal"
         i - index of                                           5

```

# Answer
> 9 votes
# C (gcc), ~~72~~ ~~71~~ ~~56~~ ~~46~~ ~~41~~ 39 bytes

```
f(char*s){s=index(s="enklact",s[3])-s;}

```

Try it online!

# Answer
> 7 votes
# MATL, ~~16~~ 15 bytes

```
O5OHlO7KI6vjYm)

```

Try it online! Or verify all test cases.

### Explanation

```
O5OHlO7KI6 % Push numbers 0, 5, 0, 2, 1, 0, 7, 4, 3, 6
v          % Concatenate all numbers into a column vector
j          % Push input as a string
Ym         % Mean (of ASCII codes)
)          % Index into the column vector (modular, 1-based, with implicit rounding)
           % Implicit display

```

# Answer
> 5 votes
# Jelly, 11 bytes

```
4ị“-ƭɼoṚ0»i

```

Try it online!

Explanation:

```
4ị“-ƭɼoṚ0»i
4ị          4th element of z
  “-ƭɼoṚ0»i First index in "enklactate"

```

# Answer
> 5 votes
## Perl 5, 24 bytes

**23 bytes code + 1 for `-p`.**

```
/[Svrl\s](?!a)/;$_="@+"

```

-4 bytes thanks to @nwellnhof!

Try it online!

# Answer
> 5 votes
I thought I would post a couple of other alternatives

# Javascript 38 bytes

```
a=s=>(271474896&7<<s.Length)>>s.Length

```

Explanation: Bit-mask rocks?

# Javascript 27 bytes

```
s=>"240350671"[s.length%10]

```

# Answer
> 3 votes
# Japt, 12 bytes

0-indexed, takes input in lowercase.

```
`kÇXsm`bUg#

```

Test it

---

## Explanation

Implicit input of lowercase string `U`

```
`kÇXsm`

```

The compressed string `kotinsm`.

```
bUg#

```

Get the first index (`b`) of the character at index (`g`) 26 (`#`) in `U`. (Yay, index wrapping!)

Implicit output of integer result.

---

## Alternative

Same as the above (and everyone else!), just using the characters at index 3 instead, allowing for title case input.

```
`klact`bUg3

```

Test it

# Answer
> 3 votes
# 05AB1E, 11 bytes

Saved 1 byte thanks to Erik the Outgolfer and 1 byte thanks to Magic Octopus Urn.

```
.•ΛΓ2º•I3èk

```

Try it online!

# Answer
> 3 votes
# JavaScript (ES6), 25 bytes

0-indexed.

```
s=>"enklact".search(s[3])

```

---

## Test it

```
o.innerText=(f=
s=>"enklact".search(s[3])
)(i.value);oninput=_=>o.innerText=f(i.value)
```

```
<select id=i><option selected value="Sweet Onion Chicken Teriyaki">Sweet Onion Chicken Teriyaki</option><option value="Oven Roasted Chicken">Oven Roasted Chicken</option><option value="Turkey Breast">Turkey Breast</option><option value="Italian BMT">Italian BMT</option><option value="Tuna">Tuna</option><option value="Black Forest Ham">Black Forest Ham</option><option value="Meatball Marinara">Meatball Marinara</option></select><pre id=o>
```

# Answer
> 3 votes
## GolfScript, 12 bytes

```
{+}*93&(5?7%

```

Try it online!

Maps the inputs (via the sum of their code points) to `0` to `6`.

### Explanation

Found with a GolfScript snippet brute force tool I wrote a while ago...

```
{+}*  # Sum all code points.
93&   # ... AND 93.
(     # Decrement.
5?    # ... raised to the fifth power.
7%    # ... modulo 7.

```

Here is how this transforms each of the inputs to the desired result:

```
                                 {+}*   93&     (            5?   7%
Sweet Onion Chicken Teriyaki     2658    64    63     992436543    0
Oven Roasted Chicken             1887    93    92    6590815232    1
Turkey Breast                    1285     5     4          1024    2
Italian BMT                       965    69    68    1453933568    3
Tuna                              408    24    23       6436343    4
Black Forest Ham                 1446     4     3           243    5
Meatball Marinara                1645    77    76    2535525376    6

```

# Answer
> 2 votes
# Perl 6, 22 bytes

```
tr/enklact/^6/.comb[3]

```

Try it online!

# Answer
> 2 votes
# Excel, 28 bytes

Using the `enklact` method:

```
=FIND(MID(A1,4,1),"enklact")

```

# Answer
> 2 votes
## CJam, 11 bytes

```
l1b93&(5#7%

```

Try it online!

A port of my GolfScript answer. It costs 1 byte to read the input explicitly, but we save two when summing the code points.

# Answer
> 2 votes
## Husk, 10 bytes

```
%7^5←n93ṁc

```

Try it online!

Another port of my GolfScript answer. I'm sure eventually I'll find a language that can sum the code points for a single byte...

## Husk (post-challenge update), 9 bytes

```
%7^5←n93Σ

```

Try it online!

Now, `Σ` *does* sum code points directly. Since this was added per a request after I answered this challenge, I'm not going to use it as my primary score though.

# Answer
> 1 votes
# Pyth, 13 bytes

```
x"enklact"@w3

```

**Verify all the test cases.**

Alternative:

```
x."atÖÅû"@w3

```

---

`3` can be substituted by any of the following values: `[3, 4, 11, 13, 21, 24, 25, 26]`

# Answer
> 1 votes
# Java 8, 26 bytes

***Credit to @icrieverytim***

Takes input as a char\[\]

```
s->"enklact".indexOf(s[3])

```

# Answer
> 1 votes
# Pyke, 12 bytes

```
3@"enklact"@

```

Try it here!

# Answer
> 1 votes
# Proton, 23 bytes

```
s=>'enklact'.find(s[3])

```

Try it online!

:P

# Answer
> 1 votes
# Perl 5, 43 + 1 (`-p`) = 44 bytes

```
for$i(S,O,TUR,I,TUN,B,M){$"++;$_=$"if/^$i/}

```

Try it online!

Requires the first three characters of input to be upper case.

# Answer
> 1 votes
## C++, ~~119~~ ~~118~~ ~~77~~ ~~76~~ 73 bytes

-41 bytes thanks to Peter Cordes
-1 byte thanks to Zacharý
-3 bytes thanks to Michael Boger

At the string index 3, character for every sandwich is different

```
#include<string>
int s(char*p){return std::string("enklact").find(p[3]);}

```

```
std::initializer_list<char*> t{
    "Sweet Onion Chicken Teriyaki",
    "Oven Roasted Chicken",
    "Turkey Breast",
    "Italian BMT",
    "Tuna",
    "Black Forest Ham",
    "Meatball Marinara"
};

for (auto& a : t) {
    std::cout << s(a);
}

```

Golfing with `std::string`, that was obvious ofc... what was i thinking...

# Answer
> 1 votes
# Haskell, 36 bytes

*-9 bytes thanks to H.PWiz.*

```
f s=length$fst$span(/=s!!3)"enklact"

```

Try it online!

## Alternate solution, 45 bytes

This uses the `indexOf` function in `Data.List` as `elemIndex`.

```
import Data.List
(`elemIndex`"enklact").(!!3)

```

Try it online!

# Answer
> 0 votes
# C# (.NET Core), 289 bytes

```
using System;class c{delegate int s(string r);static void Main(){s y=x=>{if(x[0]==83)return 1;if(x[0]==79)return 2;if (x[0]==84&x[2]=='r')return 3;if(x[0]==73)return 4;if(x[0]==84)return 5;if(x[0] ==66)return 6;if(x[0]==77)return 7;return 0;};Console.Write(y.Invoke(Console.ReadLine()));}}

```

Run online

# Answer
> 0 votes
# Golfscript, 13 bytes

Try it online!

```
'enklact'\3=?

```

Takes the 4th character (which, for each, will be unique) and looks it up in the string "`enklact`".

Alternatively:

```
'nklact'\3=?)

```

This takes advantage of the fact that Golfscript's `?` function returns -1 if the element searched for is not found (which, for Monday, it will not). If this were allowed, the solution could be reduced by 1 byte.

# Answer
> 0 votes
# Dyalog APL, 13 bytes

```
'enklact'⍳4⌷⍞

```

Try it online!

# Answer
> 0 votes
# K (oK), 13 bytes

**Solution:**

```
"enklact"?*3_

```

Try it online!

**Examples:**

```
> "enklact"?*3_"Black Forest Ham"
5
> "enklact"?*3_"Turkey Breast"
2

```

**Explanation:**

Interpretted right-to-left, pull out the 4th element from the input and return the zero-index location in the "enklact" list:

```
"enklact"?*3_  / the solution
           3_  / 3 drop, 3_"Turkey Breast" => "key Breast"
          *    / first, *"key Breast" => "k"
         ?     / lookup right in left
"enklact"      / list to lookup element in

```

---
Tags: code-golf, string, kolmogorov-complexity
---


# Question
Title: Advent Challenge 6: Transport Dock Relabeling!
\<\< Prev Next \>\>

Thanks to the PPCG community, Santa managed to sort his presents into the correct order for moving into the transportation dock. Unfortunately, the transportation dock signs are broken so he doesn't know where to put all the presents! The presents are all grouped together and not by their ranges, which Santa admits would have been a better idea.

Now, given the presents in the sorted order, determine all possible minimal range configurations that would result in the present being in the correct order. That is, find all minimal range configurations such that sorting the presents according to the algorithm in Challenge #5 would not change the order.

# Challenge

A minimal range configuration is a list of ranges such that the ranges are each as small as possible. That is, if a range is designated to cover a specific subset of presents, then the minimum and maximum of the range must be the same as that of the subset. In other words, shrinking any range in the cover would cause it to no longer be a cover.

The challenge is to find all possible minimal range configurations that would apply to the present sizes. Let's take an example: `[3, 1, 2, 5, 4, 7, 6]`

There is a trivial case, which is to take the range of the entire present configuration. In this case, `[[1, 7]]` would be a solution.

For examples with unique elements, another trivial case would be `[[3], [1], [2], [5], [4], [7], [6]]` (because the ranges don't need to be ordered).

For this example, we also see that `[[1, 3], [4, 7]]` and `[[1, 3], [4, 5], [6, 7]]` would work, as well as `[[1, 3], [5], [4], [6, 7]]` and `[[1, 3], [4, 5], [7], [6]]`.

The final answer for `[3, 1, 2, 5, 4, 7, 6]` would be `[[[3], [1], [2], [5], [4], [7], [6]], [[3], [1], [2], [5], [4], [6, 7]], [[3], [1], [2], [4, 5], [7], [6]], [[3], [1], [2], [4, 5], [6, 7]], [[3], [1], [2], [4, 7]], [[3], [1, 2], [5], [4], [7], [6]], [[3], [1, 2], [5], [4], [6, 7]], [[3], [1, 2], [4, 5], [7], [6]], [[3], [1, 2], [4, 5], [6, 7]], [[3], [1, 2], [4, 7]], [[1, 3], [5], [4], [7], [6]], [[1, 3], [5], [4], [6, 7]], [[1, 3], [4, 5], [7], [6]], [[1, 3], [4, 5], [6, 7]], [[1, 3], [4, 7]], [[1, 5], [7], [6]], [[1, 5], [6, 7]], [[1, 7]]]`.

# Formatting Specifications

The input will be given as a flat list of positive integers within your language's reasonable supported number range in any reasonable format. The input may contain duplicate elements. The output should be given as a 3D list of positive integers in any reasonable format.

Each range in your output (which is at the second layer) can be represented either as `[min, max]`, `[num]` if it's a single-value range, or as the entire range itself, but your output format must be consistent. Please specify if you wish to use a slightly different reasonable output format.

Duplicate values must be covered by a single range in the output; that is, no two ranges in the output may have any overlap.

Your solution may return the ranges in any order and this does not have to be deterministic.

# Rules

* Standard Loopholes Apply
* This is so the shortest answer in bytes wins
* No answer will be accepted

# Test Case for a list with duplicate elements:

```
2 3 2 4 -> [[[2, 3], [4]], [[2, 4]]]

```

# Reference Implementation

The header is the link.

Note: I drew inspiration for this challenge series from Advent Of Code. I have no affiliation with this site

You can see a list of all challenges in the series by looking at the 'Linked' section of the first challenge here.

Happy golfing!

# Answer
> 3 votes
# Mathematica, 106 bytes

```
sSelect[MinMax/@s~TakeList~#&/@Join@@Permutations/@IntegerPartitions@Tr[1^s],Unequal@@Join@@Range@@@#&]

```

Try it online!

Martin saved 16 bytes

# Answer
> 3 votes
# Brachylog, ~~17~~ 16 bytes

```
{~c⟨⌋⟦₂⌉⟩ᵐ.c≠∧}ᶠ

```

Works on lists with duplicates as well. Ranges are represented by the lists of elements they contain. Try it online!

## Explanation

The idea is to break the list into blocks and transform the blocks into ranges, then verify that they don't overlap.

```
{~c⟨⌋⟦₂⌉⟩ᵐ.c≠∧}ᶠ  Input is a list.
{             }ᶠ  Compute all possible outputs for this predicate:
 ~c                Break the list into contiguous blocks.
   ⟨    ⟩ᵐ         For each block,
    ⌋  ⌉           take its minimum and maximum,
     ⟦₂            and create the range between them.
          .        This is the output.
           c       Also, if you concatenate the output,
            ≠      its elements are distinct.
             ∧     Prevent the interpreter from thinking this is also the output.

```

# Answer
> 1 votes
# JavaScript (ES6), ~~166~~ 164 bytes

*Edit: updated version that now supports duplicates*

Prints the results directly to the console in **\[min, max\]** format.

```
f=(a,r=[],l=0)=>a[l++]?f([...a],r,l,f(a,[...r,[Math.min(...x=a.splice(0,l)),Math.max(...x)]])):a[0]|r.some(([x,y],i)=>r.some(([z])=>i--&&z>=x&z<=y))||console.log(r)

```

### Test cases

```
f=(a,r=[],l=0)=>a[l++]?f([...a],r,l,f(a,[...r,[Math.min(...x=a.splice(0,l)),Math.max(...x)]])):a[0]|r.some(([x,y],i)=>r.some(([z])=>i--&&z>=x&z<=y))||console.log(r)

consoleLog = console.log;
console.log = s => consoleLog(JSON.stringify(s))

consoleLog('Test case: [3, 1, 2, 5, 4, 7, 6]')
f([3, 1, 2, 5, 4, 7, 6])
consoleLog('Test case: [2, 3, 2, 4]')
f([2, 3, 2, 4])
```

# Answer
> 0 votes
# Pyth, 17 bytes

```
f{IsTmm}hSkeSkd./

```

**Try it here!**

Now that's *much* better. Outputs the whole ranges. See the revision history for the previous version (at a staggering 31 bytes).

### How it works

```
f{IsTmm}hSkeSkd./  ~> Full program.

               ./  ~> List partition.
     m             ~> Map using a variable d.
      m       d    ~> Map over d using a variable k.
        hSk        ~> The minimum of k.
           eSk     ~> The maximum of k.
       }           ~> Inclusive integer range.
f                  ~> Filter those...
   sT              ~> Which, when flattened,
 {I                ~> Are invariant over deduplication.

```

# Answer
> 0 votes
# Python 2, 179 bytes

```
lambda l:[l for l in[[range(min(x),max(x)+1)for x in P]for P in p(l)]if len(sum(l,[]))==len(set(sum(l,[])))]
p=lambda l:[[l[:i]]+a for i in range(1,len(l))for a in p(l[i:])]+[[l]]

```

Try it online!

Outputs a list of full ranges.

Heavily inspired by the reference implementation.

Builds all partitions, then ranges of min/max for each partition. A list of ranges is valid if no value appears more than once in the list.

---

`sum(l,[])` flattens a list of lists, and allows me to check for duplicates:

```
l=[[1, 2], [2, 3]]
sum(l,[]) = [1,2,2,3]
len([1,2,2,3] == len(set([1,2,2,3]))  -> False (duplicates)

```

---
Tags: code-golf, array, set-partitions
---


title: Pour me a drink, will you?

text:
# Question
Title: Pour me a drink, will you?
### The Challenge

I am thirsty and need a drink, but I don't know what to order. Your task is to provide me with either a drink or options for one.

### I/O

Input will be either a *base* or a *drink name*.

If given a *base*, your program should output *one random* drink from a list of drinks with that base. If given a *drink name*, your program should output the *base* that drink is made from.

Below is a list of drink names, ordered by their bases:

```
Absinthe:
    Death in the Afternoon
    Earthquake
    Green Russians
    Green Vesper
    Moloko Plus

Beer:
    Black and Tan
    Black Velvet
    Boilermaker
    Michelada
    Irish Car Bomb

Brandy:
    B&B
    Brandy Alexander
    French Connection
    Horse's Neck
    Sidecar

Cachaça:
    Caipirinha
    Leite de Onça
    Quentão
    Rabo-de-Galo
    Royce

Gin:
    Bramble
    Casino
    Clover Club Cocktail
    Gin Fizz
    Martini

Rum:
    Bacardi
    Cuba Libre
    Daiquiri
    El Presidente
    Piña Colada

Tequila:
    El Toro Loco
    Margarita
    Matador
    Paloma
    Tequila Sunrise

Vodka:
    Black Russian
    Bloody Mary
    Cosmopolitan
    Kamikaze
    Screwdriver

Whiskey:
    Bourbon Lancer
    Irish Coffee
    Manhattan
    Rusty Nail
    Whiskey Sour

```

### Rules:

* Standard Loopholes are forbidden.
* If given a *base*, the program's output should be *non-deterministic*, meaning that multiple runs should result in different outputs.
* Accordingly, when given a *drink name*, the program's output should be *deterministic*, yielding the same result for drinks with the same base.
* You may assume the input will always be one of the bases or drink names in the list compiled above.
* You may choose to print characters such as `ç`, `ñ` and `ã` as `c`, `n` and `a`, respectively.
* You may accept I/O in any reasonable format.
* This is a challenge, so the shortest answer (in bytes) wins.

### Test Cases:

```
Input:                    Output (Any one of the following):
Absinthe                  Death in the Afternoon
                          Earthquake
                          Green Russians
                          Green Vesper
                          Moloko Plus

Beer                      Black and Tan
                          Black Velvet
                          Boilermaker
                          Michelada
                          Irish Car Bomb

Brandy                    B&B
                          Brandy Alexander
                          French Connection
                          Horse's Neck
                          Sidecar

Cachaça                   Caipirinha
                          Leite de Onça
                          Quentão
                          Rabo-de-Galo
                          Royce

Gin                       Bramble
                          Casino
                          Clover Club Cocktail
                          Gin Fizz
                          Martini

Rum                       Bacardi
                          Cuba Libre
                          Daiquiri
                          El Presidente
                          Piña Colada

Tequila                   El Toro Loco
                          Margarita
                          Matador
                          Paloma
                          Tequila Sunrise

Vodka                     Black Russian
                          Bloody Mary
                          Cosmopolitan
                          Kamikaze
                          Screwdriver

Whiskey                   Bourbon Lancer
                          Irish Coffee
                          Manhattan
                          Rusty Nail
                          Whiskey Sour

```

Likewise, the input can be any of the drink names in the output column. If so, the output should be the corresponding base.

# Answer
> 6 votes
# Python 3, ~~693~~ ~~690~~ ~~686~~ 687 bytes

Yeah, naive approach. I tried some compression methods, and this one seems to be the shortest.

*-2 bytes thanks to HyperNeutrino.*

EDIT: Bug fixed.

```
import random
v="Absinthe$Death in the Afternoon$Earthquake$Green Russians$Green Vesper$Moloko Plus$Beer$Black and Tan$Black Velvet$Boilermaker$Michelada$Irish Car Bomb$Brandy$B&B$Brandy Alexander$French Connection$Horse's Neck$Sidecar$Cachaca$Caipirinha$Leite de Onca$Quentao$Rabo-de-Galo$Royce$Gin$Bramble$Casino$Clover Club Cocktail$Gin Fizz$Martini$Rum$Bacardi$Cuba Libre$Daiquiri$El Presidente$Pina Colada$Tequila$El Toro Loco$Margarita$Matador$Paloma$Tequila Sunrise$Vodka$Black Russian$Bloody Mary$Cosmopolitan$Kamikaze$Screwdriver$Whiskey$Bourbon Lancer$Irish Coffee$Manhattan$Rusty Nail$Whiskey Sour".split('$');a=v.index(input());print(v[a-a%6if a%6else random.randint(1,5)+a])

```

Try it online!

# Answer
> 6 votes
# Jelly, 356 bytes

```
“%³“¥;ġŀṭṢDṡỌµ“Ñçḥ“)ụ_ƥÐ¬“(OE⁼Ọ“"³Ḟ'×ɱA8“tẊ“ßDæj|t³G“z⁸ƈƲe“¦¿¶“ßṆÑẆṇ8“©ŒẓġṾɠ×“¢(°“⁶oI“¬ĿḤẈX“ṫ°^iɱ“ıịṣXṆẠL“3!ṁ“©VṢ“¦ƈœƘNd]¶mḄœ“Ðv4WṁḌạYÐġȯḣɼ“¢ḅuɼḶŒß“AṠḍ*ɦ)!Ḷ¿µʋ“¡pK“¡ȯL“¦uż“¬5;“¥I¢q9ḅḋĖ“µ>Ƥøŀ“ ØÐ“¤^(“¡Il“£Ḅ#ṫ$⁽ø“€Uy“"ƭ/4¢ṫ“ƬƒN⁼A6+EẈṆ“8ɠ¹“½oŒLụ}ɗ“µṡ⁴“½Çj“€g©“ÆḄ²zị'“¥¹j“þk¥ÆṢ“C⁼ṭ¬'“¿®ı“÷Ụ;“1ṂY“?]ʂ“¢ȥ4Ɗh⁺“Œ\ẒƘḳ“µċ$“¦ʋȷ[Ɱ“¡?ƓṚĠk»
¢i³
¢_¢’¤%6¤¤¢+5X¤¤¢%6¤’¤?ị1£

```

Try it online!

Formula stolen from Colera Su but I think I can get it shorter in Jelly using a Jelly-mindset approach.

**¢\_¢**

# Answer
> 3 votes
# PHP, ~~681 680 676 661~~ 646+1 bytes

**gz version:**

```
<?=($x=explode)(_,$x(X,strstr($d=gzinflate(base64_decode("RZHBbtswDIZfhaft1IeI3TYblnRZEmS6CbTM1IRlMqXkbs7Tj9lS7CCQBH6Sn36uusJSBwqPhHUAFvACVudKJqoSn9Dq8DbjSHFtRAL7uRRGKffyROVCFreadVTY5bmEhsjCltNAGXuMTcY0AkoPR5R7daL8TjU2ypls8uEWvxqXAVo0aHTqQmPesYTmUxP/pbDK9NsTlz4bSXKtilCq7JRf1Ap9LvBCaYwH7imhhRbTgAk98oWNZcC4Ia4EPcF3SRh/zCQVNe6x04eeHtaYvdAlUViz3B488/Uat+4BC99Api5TbNE909hmfSeDNs+ds6SxIuewn6fQ+FbrObZzh7Dhzig+Ir/NDhF3LOjqv848ZdgZFceVSuFIrsj4EeEwi1tCN9VRTWGjSW8or2hc0bOKvVrcOfSE4aT9iKHJqm6Vq5a70/dzxVbLpBfN3irxkIx+9caOH7/hxCNeKfwcuIy0fEQ46Gx+odk6FdigpP9H0vOZyAnc0nqb50vqAi/+/z8")),$argn.X))[1])[rand()%5]?:array_slice($x(X,strstr($d,$argn,1)),-2)[0];

```

**strtr version, ~~676~~ 661+1 bytes**

```
<?=($x=explode)(_,$x(X,strstr($d=strtr("Abs4theXDeath 4 the Aft2noon_E5thquake_Green Russi0s_Green Vesp2_Moloko PlusXBe2XMiche7da1 0d T01 Velvet_Boil2mak2_I8sh C5 BombXBr0dyXB&B_Br0dy Alex0d2_French Connection_Horse's Neck_Sidec5XCachacaXCaipi8nha_Leite de Onca_Quentao_Rabo-de-Galo_RoyceXG4XG4 Fizz9rt4i_Bramble_Cas4o_Clov2 Club CocktailXRumXBac5di_Cuba Libre_Daiqui8_P4a Co7da_El Presidente66 Sun8se_El Toro Loco9rg5ita9tador_PalomaXVodkaXBloody M5y1 Russi0_Cosmopolit0_Screwd8v2_Kamikaze33 Sour_Bourbon L0c2_I8sh Coffee9nhatt0_Rusty Nail",[an,_Black,er,XWhiskey,in,ar,XTequila,la,ri,_Ma]),$argn.X))[1])[rand()%5]?:array_slice($x(X,strstr($d,$argn,1)),-2)[0];

```

Run as pipe with `-nF` or try it online. Requires PHP 7.

# Answer
> 2 votes
# Python 2, 640 bytes

```
import random as r
def f(s):d="eJw9Ucty2zAM/BWc2lPwD5by6tRJXNvjniEKjjCiAAek0tpfXyij6UlYanexXG66IloHxnumOoAoBIDNubKrmeIDeR0+ZhoZn5xZYT+XIqRlhScuF3Z8sWyjwS7PBRuOgyZTGoG0hyPpik6cP7liY5LZp7AMnaSBM/WEP1zKAC05NDZ12Hhor9h8a9YRNpn/xhCiR2dNwTVVTlUi5bN54e8FXjmNeJCeEzm2lAZKFF+5iIsOhFuWytAzvGn8+DWzVjLcU2d3Pd89UQ5g1xR3FV32Tl3m0EdFhm22T3Zo89zF6jRWkrzw4FFuN3yJnkQF9/OETWz1XrCdO4KtdB7tknzMEQIfMuycS0TUyrgTpTD7KuDIwci0MI7mBltLtti+k0ulmCr15riLkNN/NhxmjeIYT9aPtPa8PlEgsyguPK7YWpnsYjmsFH/SJCPdGA/J+U/vEhfD34OUkaNym70zhS1piuP1Xex8Zo4Q0WJdLGJHvcLr0sEqhEMI/wHq6dVM".decode('base64').decode('zip').split('.');i=d.index(s);print d[[i+r.randint(1,5),i/6*6][i%6>0]]

```

Try it online!

# Answer
> 2 votes
## PHP, 628 bytes

Stealing the best ideas from others... thanks for the inflate trick

```
<?$d=explode("|",gzinflate(base64_decode("PVHLctswDPwVnHrLR1hqHp06iWt73DNEwRVGFOCAVBp78Lc99Nw/KNTR9CQstbtYLjddYakD+WfCOgALBIDNuZKJqvg9Wh3eZhzJH41IYD+XwihlhScqFzJ/1qyjwi7PxRuKgyZjGgGlhyPKik6U36l6o5zJprAMHaeBMvboX4zLAC0aNDp13lhor958atYRNpk+YgjRg5Gk4KoIpcqR8kmtEBR4oTT6gXtKaN5iGvA3xpcvbCwD+pa4EvQErxI/vs0k9Zf6Hju96+nuEXMAvaa4K8uyd+oyhT4qUm+zvpNBm+cuVqexIueFBw98u/lz9MTCvp8nbzDW9+zt3CFsubNoF/ltjhB+n2FnVCKiVPId/8Ew+1fAkYKRcWEc1RS2mnSx/YHGFWOq2Kv5LkJO/9lwmCWKIz9pP+La8/pEgVSjuPC4eqtl0ovmsBL/ihOPeCM/JKOfvXFczL8PXEaKynW2TgW2KCmO13fR85koQkSLdbGIHfUKL0sHqxAOIfwL")));$i=array_search($argv[1],$d);echo($i%6)?$d[$i-$i%6]:$d[$i+rand(1,5)];

```

# Answer
> 1 votes
# Charcoal, 381 375 bytes

```
≔⪪”}⊞J'%↓B+K…↙ZＱαyε↘¶⎚\`⟲≧↑lⅉ＆⬤↖ΦüY⁹←‖⧴p×OＣ∧⊗F]±⊗✳Ｎ″ⅈ✳c∕lü,Π438↖⍘✳⍘⁷N⪪ςz↨Ｄ″≦«p¶↧⟦¬²◨▶↗⪫/_"b8n↨À⊙ρ≡1#▶UD⸿no,7φ²↘↑r‴m⪪pＷ⭆mC↥#pP″νr↧″h[κznβd6qυ:*…KC⪫⌈⸿＆DΣεＸMω⊙⟧↔Ｌ↓;?ü↶σ⁵%Ｆ⊙⪫:ＱD*)⊞↥$Ｘ4.⎆V\`″Ｎb5βς｜…5¤⁴↘⊗｜%À⭆)⬤,⁻f»Ｄh…{“ [ＷＦ⸿⊗$ς«8RbγＺ5gv⮌⟲Π\`XcρO≦3；2{§³Ｑψt‹ＳY⪫ς⦃Ｄ⪫⎚TO⁼Ｎ⊗Ｅ⁺ζt≕·´H|›gＰＯＷkＫ⁶³⧴\`⁶Ａ⊟ⅈ✂&)ξ↧εβ%ιSΦＹ\`»ＸＷV⁸｜∧Ａ▷RE⍘Zα#÷Þ~↙{﹪ÞqＳＫ[μO\`It›▷≕ρ≔⊘Jc◨;Ｚm�～8″⟲Ｐ↶S⎆2×”#δ≔⌕δθπ§δ⁻π∨﹪π⁶±⊕‽⁵

```

Try it online!

A port to Charcoal of Colera Su's answer. Link is to the verbose version of the code. I could not test some of the cases because Charcoal considers `French Connection` as two different inputs...

* 6 bytes saved thanks to Neil!

---
Tags: code-golf, string
---


title: Half-Exponential Function

text:
# Question
Title: Half-Exponential Function
A half-exponential function is one which when composed with itself gives an exponential function. For instance, if `f(f(x)) = 2^x`, then `f` would be a half-exponential function. In this challenge, you will compute a specific half-exponential function.

Specifically, you will compute the function from the non-negative integers to the non-negative integers with the following properties:

* Monotonically increasing: if `x < y`, then `f(x) < f(y)`
* At least half-exponential: For all `x`, `f(f(x)) >= 2^x`
* Lexicographically smallest: Among all functions with the above properties, output the one which minimizes `f(0)`, which given that choice minimizes `f(1)`, then `f(2)`, and so on.

The initial values of this function, for inputs `0, 1, 2, ...` are:

`[1, 2, 3, 4, 8, 9, 10, 11, 16, 32, 64, 128, 129, 130, 131, 132, 256, 257, ...]`

You may output this function via any of the following methods, either as a function or as a full program:

* Take `x` as input, output `f(x)`.
* Take `x` as input, output the first `x` values of `f`.
* Infinitely output all of `f`.

If you want to take `x` and output `f(x)`, `x` must be zero indexed.

Reference implementation

This is code golf - shortest code in bytes wins. Standard loopholes are banned, as always.

# Answer
## JavaScript (ES7), ~~51~~ 48 bytes

*Saved 3 bytes thanks to @Arnauld*

```
f=i=>i?f[f[q=f(i-1),r=f[i]||q+1]=(i>1)<<i,i]=r:1

```

Takes in **n** and outputs the **n**'th item in the sequence.

---

## JavaScript (ES7), ~~70~~ ~~68~~ 64 bytes

```
f=(n,a=[],q=1)=>n?f(n-1,a,(n=2**a.indexOf(a.push(q)))<++q?q:n):a

```

A recursive function that takes in `x` and returns the first `x` items of the sequence as an array.

### How it works

The array **a** is procedurally generated, one item at a time, until it reaches the desired length. (A port of the infinite technique used in xnor's excellent Python answer would likely be shorter.)

We can make the following observation for each index **i** (0-indexed):

* If **i** exists as an item in **a** at index **j** (**a\[j\] = i**), then **a\[i\]** needs to be at least **2j**.

This is true because **f(f(j))** needs to be at least **2j**, and **f(f(j))** is equivalent to **a\[a\[j\]\]**, which is in turn equivalent to **a\[i\]**.

Normally the correct option is exactly **2j**. However, for the singular case **i = 2**, **2** exists in the array at index **j = 1**, which means that **2j** would be **2**—but this means that we would have **2** at both **a\[1\]** and **a\[2\]**. To get around this, we take the maximum of **2j** and **a\[i-1\] + 1** (one more than the previous item), which gives **3** for **i = 2**.

This technique also happens to take care of deciding whether or not **j** exists—if it doesn't, JS's `.indexOf()` method returns **-1**, which leads to taking the max of **a\[i-1\] + 1** and **2-1 = 0.5**. Since all items in the sequence are at least **1**, this will always return the previous item plus one.

(I'm writing this explanation late at night, so please let me know if something is confusing or I missed anything)
> 8 votes

# Answer
# Python 2, 60 bytes

```
d={};a=n=1
while 1:print a;a=d.get(n,a+1);d[1%n*a]=2**n;n+=1

```

Try it online!

Prints forever.

---

# Python, 61 bytes

```
f=lambda n,i=2:n<1or(i>=n)*-~f(n-1)or(f(i)==n)<<i or f(n,i+1)

```

Try it online!

A function. Outputs `True` in place of `1`.
> 7 votes

# Answer
# Perl 5, 53 + 1 (`-p`) = 54 bytes

```
$\=$_>0;map$a[$\=$a[$_]?2**$a[$_]:$\+1]=$_,++$\..$_}{

```

Try it online
> 2 votes

# Answer
# Bash, 66 bytes

```
for((r=$1?2:1,i=2;i<=$1;i++));{ a[r=a[i]?2**a[i]:r+1]=$i;};echo $r

```

Try it online
> 1 votes

# Answer
# Jelly, 14 bytes

```
iL’2*»Ṁ‘$ṭ
⁸Ç¡

```

Try it online!

### How it works

```
⁸Ç¡         Main link. No arguments.

⁸           Set the left argument and the return value to [].
 Ç¡         Read an integer n from STDIN and call the helper link n times, first on
            [], then on the previous result. Return the last result.

iL’2*»Ṁ‘$ṭ  Helper link. Argument: A (array)

 L          Take the length of A. This is the 0-based index of the next element.
i           Find its 1-based index in A (0 if not present).
  ’         Decrement to a 0-based index (-1 if not present).
   2*       Elevate 2 to the 0-based index.
      Ṁ‘$   Take the maximum of A and increment it by 1.
            Note that Ṁ returns 0 for an empty list.
     »      Take the maximum of the results to both sides.
         ṭ  Tack (append) the result to A.

```
> 1 votes

# Answer
# Python 2, 111 bytes

```
def f(x):
 a=range(1,2**x)
 for i in range(1,x):a[i]=max(a[i],a[i-1]+1);a[a[i]]=max(a[a[i]],2**i)
 return a[:x]

```

Try it online!

This is a significant modification of user202729's answer. I would have posted this improvement as a comment, but the answer is deleted and so comments are disabled.
> 0 votes

# Answer
# Swift, 137 bytes

```
func f(n:Int){var l=Array(1...n).map{$0>3 ?0:$0},p=8;if n>3{for i in 3..<n{if l[i]<1{l[i]=l[i-1]+1};if l[i]<n{l[l[i]]=p};p*=2}};print(l)}

```

Takes input as `Int` (integer) and prints as `[Int]` (integer array).

## Ungolfed version

```
func f(n:Int){
    var l = Array(1...n).map{$0 > 3 ? 0 : $0} // Create the range from 1 to n and set all
    var p = 8                                 // values greater than 3 to 0
    if n > 3 {
        for i in 3 ..< n {
            if l[i] < 1 {
                l[i] = l[i - 1] + 1
            }
            if l[i] < n {
                l[l[i]] = p
            }
            p *= 2
        }
    }
    print(l)
}

```
> 0 votes

---
Tags: code-golf, math, sequence, function
---


title: Encode Factor Trees

text:
# Question
Title: Encode Factor Trees
I once saw on the xkcd fora a format for expressing numbers in an odd way. In this "factor tree" format:

* The empty string is 1.
* Concatenation represents multiplication.
* A number *n* enclosed in parentheses (or any paired characters) represents the *n*th prime number, with 2 being the first prime number.
    + Note that this is done recursively: the *n*th prime is the factor tree for *n* in parentheses.
* The factors of a number should be ordered from smallest to largest.

For example, here are the factor trees for 2 through 10:

```
()
(())
()()
((()))
()(())
(()())
()()()
(())(())
()((()))

```

Your task is to take in a positive integer, and output the factor tree for it.

# Test Cases

In addition to the 9 above…

```
100 => ()()((()))((()))
101 => (()(()(())))
1001 => (()())(((())))(()(()))
5381 => (((((((())))))))
32767 => (()())((((()))))(()()(())(()))
32768 => ()()()()()()()()()()()()()()()

```

# Rules

* Characters other than `()[]{}<>` are allowed in the output, but ignored.
* You should be able to handle any input from 2 to 215 inclusive.
* The winner is the shortest answer in bytes.

# Answer
> 3 votes
# Husk, ~~15~~ 7 bytes

```
ṁös;₁ṗp

```

Try it online!

-8 bytes thanks to @Zgarb!

### Explanation

Note that the header `f€"[]"₁` just filters out all `[` & `]` characters, it's just so that the output is more readable, if you want to see the original output, here you go.

```
ṁ(s;₁ṗ)p  -- define function ₁; example input: 6
       p  -- prime factorization: [2,3]
ṁ(    )   -- map and flatten the following (example with 3): "[""]["[\"\"]"]"
     ṗ    --   get prime index: 2
    ₁     --   recurse: "[\"\"]"
   ;      --   create singleton: ["[\"\"]"]
  s       --   show: "[\"[\\\"\\\"]\"]"

```

# Answer
> 5 votes
## Wolfram Language (Mathematica), ~~84~~ ~~81~~ ~~80~~ 64 bytes

*Byte count assumes Windows ANSI encoding.*

*Thanks to Misha Lavrov for saving 16 bytes.*

```
±1=""
±x_:=Table[{"(",±PrimePi@#,")"},#2]&@@@FactorInteger@x<>""

```

Try it online!

### Explanation

Quite a literal implementation of the spec. We're defining a unary operator `±` via two separate definitions.

```
±1=""

```

This is just the base case, the empty string for `1`.

```
±x_:=Table[±#,#2]&@@@FactorInteger@x<>""

```

For all other `x`, we factor the integer (this gives a list of prime-exponent pairs, `{p, k}`), generate a table of `k` copies of the representation of `p`. For each `p`, we figure out the prime's index via `PrimePi` (i.e. the number of primes less than or equal to it), recursively pass it to `±` and wrap the result in parentheses. Then flatten and join the result into a single string.

# Answer
> 4 votes
# Jelly, 10 bytes

```
ÆfÆC$ÐLŒṘ€

```

Try it online!

-7 bytes thanks to user202729

# Explanation

```
ÆfÆC$ÐLŒṘ€  Main Link
     ÐL     While the results have not yet repeated
ÆfÆC$       Prime factorize the number (vectorizes) and turn each prime to its prime index
       ŒṘ€  Since none of the lists actually contain anything, turn it to a Python string or else it won't print. Call on each because otherwise there will be an extra set of brackets around the output.

```

# Answer
> 1 votes
# Python 2, ~~113~~ 110 bytes

```
f=lambda n,d=2,p=1:n>2and(n%d and f(n,d+1,p+all(-~d%i for i in range(2,d)))or'(%s)'%f(p)+f(n/d,d,p))or'()'*~-n

```

Try it online!

---

**ungolfed**

```
def f(num, div=2, prime=1):
    if num > 2:
        if num % div:
            # if div does not divide num
            # try next divisor, add 1 to prime if the next divisor is prime
            return f(num, div + 1, prime + all((div + 1) % i for i in range(2, div)))
        else:
            # if div divides num add div as a factor, continue with num / div
            return '(%s)' % f(prime) + f(num / div, div, prime)
    else:
        # if num <= 1: return ''
        # if num == 2: return '()'
        return '()' * (num - 1)

```

Try it online!

# Answer
> 0 votes
# JavaScript (ES6), 93 bytes

Uses the same approach as ovs' Python answer.

```
f=(n,d=2,k=1)=>n>2?n%d?f(n,++d,k+(P=n=>n%--d?P(n):d<2)(d)):`(${f(k)})`+f(n/d,d,k):n-2?'':'()'

```

### Test cases

```
f=(n,d=2,k=1)=>n>2?n%d?f(n,++d,k+(P=n=>n%--d?P(n):d<2)(d)):`(${f(k)})`+f(n/d,d,k):n-2?'':'()'

;[2,3,4,5,6,7,8,9,10,100,101,1001,5381,32767,32768].forEach(
  n => console.log(n, '->', f(n))
)
```

# Answer
> 0 votes
# \+ numbers, 113 bytes

```
f=function(n)"if"(n<2,"",paste0("(",sapply(match(primeFactors(n),Primes(n)),f),")",collapse=""))
library(numbers)

```

Try it online!

Recursive function. Returns a string.

```
function(n)
if(n < 2)                                                # 1 is empty string
 ""                                                      #
else                                                     #
 paste0("(",                                             # wrap in parens
            sapply(                                      # for each
                   match(primeFactors(n),Primes(n))),    # prime index of factors of n
                                                     f), # apply f
           ")",                                          #
               collapse="")                              # collapse into a single string
```

# Answer
> 0 votes
# Swift, 155 bytes

```
func f(_ n:Int)->String{var d=0;return n<2 ?"":(d=(2...n).first{n%$0<1}!,n==d).1 ?"(\(f((2...n).filter{m in(2...m).first{m%$0<1}==m}.count)))":f(d)+f(n/d)}

```

## Explanation (Ungolfed)

```
func f(_ n:Int) -> String {                        // Declare recursive function f(n)
    var d = 0;                                     // Temporary variable d
    return n < 2 ?                                 // If n < 2:
        ""                                         //    Return empty string
    : (d = (2...n).first{n % $0 < 1}!, n == d).1 ? // If the lowest number divisible by n
                                                   // is equal to n (n is prime):
        "(\(f((2...n).filter{m in (2...m).first{   //    Return prime index of n (length of
        m % $0 < 1} == m}.count)))"                //    list of all primes ≤ n)
    :                                              // Else:
        f(d) + f(n / d)                            //    Return f(d) + f(n / d) where d is
}                                                  //    the smallest number divisible by n

```

---
Tags: code-golf, primes, balanced-string, factoring
---


title: Golf an Advent Calendar

text:
# Question
Title: Golf an Advent Calendar
It's that time of year when many of us get our advent calendars! If you are unfamiliar with an advent calendar, these are special calendars used to count down advent in anticipation of Christmas. In my experience the doors are placed randomly, and part of the fun as a child was working out where tomorrow's door was! Often these days, calendars have chocolates behind each door, but instead of buying an advent calendar this year, you should build an ASCII one!

## Task

Given input of an integer (`n`) in the range `0`-`24`, produce an ASCII advent calendar with the numbered doors up-to `n`, opened. You must use the same order as in the below example: `2`, `17`, `8`, `12`, `1`, `6`, `11`, `20`, `5`, `22`, `3`, `10`, `15`, `23`, `7`, `16`, `9`, `24`, `18`, `4`, `13`, `19`, `21`, `14`.

## Doors

The closed door must be:

```
.-----------.
|           |
|           |
|           |
|       nn  |
|___________|

```

where `n` represents the number of the door (leading zeros are optional) and the opened door is:

```
.-----------.
|\          |
| |         |
| |         |
| |         |
| |_________|
 \|

```

except for door 24, which is instead:

```
.--------------------------.
|                          |
|                          |
|                          |
|                      24  |
|__________________________|
.--------------------------.
|\                         |
| |                        |
| |                        |
| |                        |
| |________________________|
 \|

```

These doors are arranged within a frame of 37 lines of 79 characters, with two spaces between each column, and an empty line between each row.

## Opened Doors

When the doors are opened you must display one of the (tenuously Christmas related - apologies for my terrible art skills!) pictures below within the door:

```
 . _ .    _'_        +       .^o     _(")_     _n_       $        .
 }\O/{    ) (^.^_   /~\     (';')   (_ . _)    (")      |,|    __/ \__
 }/*\{    \./v`v'  /~*~\   {\|+|/}   / : \   >( o )<    | |    `.   .'
 /***\     oO8    /~*~~*\    d-b    (_/ \_)  (  o  )  ._|_|_.   /.^.\

 .\^/.     ____   __.==,_    .*.     _   _    . . .   _______   _   _
<->o<->   /_%_/|  --|XX|-    /.\    (O X O)  .i_i_i.  _j_j_j_  ( `v' )
 '/v\`   |_|_| |   _|  |    |_-_|    / ^ \   |-~~-~|   ||__|    \   /
         |_|_|/   (____'   (.-o-.)   \/ \/   |_____|  _|/$$|_     V

   i       |~|     //'`\     |=|    _{/ _{/   ,   *   \  ====     b
 .'%'.     | |    //....\    / \      \_/    +  . +   \\\|+-|   .'''.
|^~~.~|     Y     ||()()|   |(%)|     /O \     . ' .  \\\\\+|  {*=*=*}
_'._.'_    _|_    ||_[]_|   |___|   @__,/\\  ~~~~~~~  \\\\\\\   '._.'

    _    |  _  |  .W. .W.  .&%$+*.    \O/       .;'   ..,.;..   ('v')
  .'.'O  | ($) |  |*| |*|  */'"'\&  [ ]|_.     .m_.   |\\|//|  //   \\
 /___\   |  " o|  |*| |*|  $\._./%  |_____)   C|  |    \\|//   |\   /|
(_____)  | === |  'M' 'M'  '%&*+$'  ------'    |__|    _=|=_     Y Y

 \   /      .==.    .-.     -._.-   __/\__     ...       .-.
._o_O_.  .--'  |  \|   |/    .+.    \_\/_/    '*  `     //`);
|/\/\/|  \_____/  /|   |\   ( W )   /_/\_\   |_/\*_|   %%
"""""""  `====='    '-'      `"`      \/     [_____]  //

```

Each image is 7 characters long and covers 4 lines so they will fit within the windows. You are free to choose any of the above images and use them in any order, but you may not repeat an image. For the 24th, you must also add a message:

```
       ~
   ~ MERRY ~
 ~ CHRISTMAS! ~
     ~~~~~

```

which fits alongside one of the above pictures, you can choose whether the text is to the right or the left of the image.

## Examples

Given input `0`, output the calendar with no doors opened:

```
.-----------------------------------------------------------------------------.
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |        2  |  |       17  |  |        8  |  |       12  |  |        1  |  |
|  |___________|  |___________|  |___________|  |___________|  |___________|  |
|                                                                             |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |        6  |  |       11  |  |       20  |  |        5  |  |       22  |  |
|  |___________|  |___________|  |___________|  |___________|  |___________|  |
|                                                                             |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |        3  |  |       10  |  |       15  |  |       23  |  |        7  |  |
|  |___________|  |___________|  |___________|  |___________|  |___________|  |
|                                                                             |
|  .-----------.  .-----------.  .--------------------------.  .-----------.  |
|  |           |  |           |  |                          |  |           |  |
|  |           |  |           |  |                          |  |           |  |
|  |           |  |           |  |                          |  |           |  |
|  |       16  |  |        9  |  |                      24  |  |       18  |  |
|  |___________|  |___________|  |__________________________|  |___________|  |
|                                                                             |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |           |  |           |  |           |  |           |  |           |  |
|  |        4  |  |       13  |  |       19  |  |       21  |  |       14  |  |
|  |___________|  |___________|  |___________|  |___________|  |___________|  |
|                                                                             |
|_____________________________________________________________________________|

```

For input `5`, output something similar to:

```
.-----------------------------------------------------------------------------.
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\   . _ .  |  |           |  |           |  |           |  |\  __.==,_ |  |
|  | |  }\O/{  |  |           |  |           |  |           |  | | --|XX|- |  |
|  | |  }/*\{  |  |           |  |           |  |           |  | |  _|  |  |  |
|  | |  /***\  |  |       17  |  |        8  |  |       12  |  | | (____'  |  |
|  | |_________|  |___________|  |___________|  |___________|  | |_________|  |
|   \|                                                          \|            |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |           |  |           |  |           |  |\  _{/ _{/ |  |           |  |
|  |           |  |           |  |           |  | |   \_/   |  |           |  |
|  |           |  |           |  |           |  | |   /O \  |  |           |  |
|  |        6  |  |       11  |  |       20  |  | | @__,/\\ |  |       22  |  |
|  |___________|  |___________|  |___________|  | |_________|  |___________|  |
|                                                \|                           |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\    _n_   |  |           |  |           |  |           |  |           |  |
|  | |   (")   |  |           |  |           |  |           |  |           |  |
|  | | >( o )< |  |           |  |           |  |           |  |           |  |
|  | | (  o  ) |  |       10  |  |       15  |  |       23  |  |        7  |  |
|  | |_________|  |___________|  |___________|  |___________|  |___________|  |
|   \|                                                                        |
|  .-----------.  .-----------.  .--------------------------.  .-----------.  |
|  |           |  |           |  |                          |  |           |  |
|  |           |  |           |  |                          |  |           |  |
|  |           |  |           |  |                          |  |           |  |
|  |       16  |  |        9  |  |                      24  |  |       18  |  |
|  |___________|  |___________|  |__________________________|  |___________|  |
|                                                                             |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\     +    |  |           |  |           |  |           |  |           |  |
|  | |   /~\   |  |           |  |           |  |           |  |           |  |
|  | |  /~*~\  |  |           |  |           |  |           |  |           |  |
|  | | /~*~~*\ |  |       13  |  |       19  |  |       21  |  |       14  |  |
|  | |_________|  |___________|  |___________|  |___________|  |___________|  |
|   \|                                                                        |
|_____________________________________________________________________________|

```

For input `14`:

```
.-----------------------------------------------------------------------------.
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\   . _ .  |  |           |  |\     .    |  |\    ____  |  |\  __.==,_ |  |
|  | |  }\O/{  |  |           |  | | __/ \__ |  | |  /_%_/| |  | | --|XX|- |  |
|  | |  }/*\{  |  |           |  | | `.   .' |  | | |_|_| | |  | |  _|  |  |  |
|  | |  /***\  |  |       17  |  | |  /.^.\  |  | | |_|_|/  |  | | (____'  |  |
|  | |_________|  |___________|  | |_________|  | |_________|  | |_________|  |
|   \|                            \|             \|             \|            |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\      _   |  |\     $    |  |           |  |\  _{/ _{/ |  |           |  |
|  | |   .'.'O |  | |   |,|   |  |           |  | |   \_/   |  |           |  |
|  | |  /___\  |  | |   | |   |  |           |  | |   /O \  |  |           |  |
|  | | (_____) |  | | ._|_|_. |  |       20  |  | | @__,/\\ |  |       22  |  |
|  | |_________|  | |_________|  |___________|  | |_________|  |___________|  |
|   \|             \|                            \|                           |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\    _n_   |  |\   _(")_  |  |           |  |           |  |\    |=|   |  |
|  | |   (")   |  | | (_ . _) |  |           |  |           |  | |   / \   |  |
|  | | >( o )< |  | |  / : \  |  |           |  |           |  | |  |(%)|  |  |
|  | | (  o  ) |  | | (_/ \_) |  |       15  |  |       23  |  | |  |___|  |  |
|  | |_________|  | |_________|  |___________|  |___________|  | |_________|  |
|   \|             \|                                           \|            |
|  .-----------.  .-----------.  .--------------------------.  .-----------.  |
|  |           |  |\  \  ==== |  |                          |  |           |  |
|  |           |  | | \\\|--| |  |                          |  |           |  |
|  |           |  | | \\\\\-| |  |                          |  |           |  |
|  |       16  |  | | \\\\\\\ |  |                      24  |  |       18  |  |
|  |___________|  | |_________|  |__________________________|  |___________|  |
|                  \|                                                         |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\     +    |  |\    ,  *  |  |           |  |           |  |\     i    |  |
|  | |   /~\   |  | | +  .  + |  |           |  |           |  | |  .'%'.  |  |
|  | |  /~*~\  |  | |  .  ' . |  |           |  |           |  | | |^~~.~| |  |
|  | | /~*~~*\ |  | | ~~~~~~~ |  |       19  |  |       21  |  | | _'._.'_ |  |
|  | |_________|  | |_________|  |___________|  |___________|  | |_________|  |
|   \|             \|                                           \|            |
|_____________________________________________________________________________|

```

For input `24`:

```
.-----------------------------------------------------------------------------.
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\   . _ .  |  |\   //''\  |  |\     .    |  |\    ____  |  |\  __.==,_ |  |
|  | |  }\O/{  |  | | //....\ |  | | __/ \__ |  | |  /_%_/| |  | | --|XX|- |  |
|  | |  }/*\{  |  | | ||()()| |  | | `.   .' |  | | |_|_| | |  | |  _|  |  |  |
|  | |  /***\  |  | | ||_[]_| |  | |  /.^.\  |  | | |_|_|/  |  | | (____'  |  |
|  | |_________|  | |_________|  | |_________|  | |_________|  | |_________|  |
|   \|             \|             \|             \|             \|            |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\      _   |  |\     $    |  |\    |~|   |  |\  _{/ _{/ |  |\   . . .  |  |
|  | |   .'.'O |  | |   |,|   |  | |   | |   |  | |   \_/   |  | | .i_i_i. |  |
|  | |  /___\  |  | |   | |   |  | |    Y    |  | |   /O \  |  | | |-~~-~| |  |
|  | | (_____) |  | | ._|_|_. |  | |   _|_   |  | | @__,/\\ |  | | |_____| |  |
|  | |_________|  | |_________|  | |_________|  | |_________|  | |_________|  |
|   \|             \|             \|             \|             \|            |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\    _n_   |  |\   _(")_  |  |\  |  _  | |  |\  .W. .W. |  |\    |=|   |  |
|  | |   (")   |  | | (_ . _) |  | | | ($) | |  | | |*| |*| |  | |   / \   |  |
|  | | >( o )< |  | |  / : \  |  | | |  " o| |  | | |*| |*| |  | |  |(%)|  |  |
|  | | (  o  ) |  | | (_/ \_) |  | | | === | |  | | 'M' 'M' |  | |  |___|  |  |
|  | |_________|  | |_________|  | |_________|  | |_________|  | |_________|  |
|   \|             \|             \|             \|             \|            |
|  .-----------.  .-----------.  .--------------------------   .-----------.  |
|  |\   _   _  |  |\  \  ==== |  |\  .&%$+*.       ~        |  |\    \O/   |  |
|  | | (O X O) |  | | \\\|--| |  | | */'"'\&   ~ MERRY ~    |  | | [ ]|_.  |  |
|  | |  / ^ \  |  | | \\\\\-| |  | | $\._./% ~ CHRISTMAS! ~ |  | | |_____) |  |
|  | |  \/ \/  |  | | \\\\\\\ |  | | '%&*+$'     ~~~~~      |  | | ------' |  |
|  | |_________|  | |_________|  | |________________________|  | |_________|  |
|   \|             \|             \|                            \|            |
|  .-----------.  .-----------.  .-----------.  .-----------.  .-----------.  |
|  |\     +    |  |\   ,   *  |  |\     |    |  |\    .*.   |  |\     i    |  |
|  | |   /~\   |  | | +  . +  |  | |  .'''.  |  | |   /.\   |  | |  .'%'.  |  |
|  | |  /~*~\  |  | |   . ' . |  | | {*=*=*} |  | |  |_-_|  |  | | |^~~.~| |  |
|  | | /~*~~*\ |  | | ~~~~~~~ |  | |  '._.'  |  | | (.-o-.) |  | | _'._.'_ |  |
|  | |_________|  | |_________|  | |_________|  | |_________|  | |_________|  |
|   \|             \|             \|             \|             \|            |
|_____________________________________________________________________________|

```

## Rules

This is so the shortest code in bytes, in each language, wins.

* Any reasonable format can be used for I/O assuming it is consistent.
* Any amount of whitespace before and after the calendar is fine, as well as additional spaces/unprintables at the end of each line, but nothing before each line as this must fit into 80 characters.
* All standard loopholes are forbidden.

## Thanks

James Holderness for contributing ASCII images!

# Answer
> 25 votes
# Charcoal, 676 639 614 607 598 590 564 561 bytes

```
Ｐ⁴⁰↓.↓³⁷Ｍ↗×³⁹_‖ＯＦ²⁴«≔⌕”%↖∧F◨℅V⊖⎚λJ↷;φε⊟ ↧”§βιε≔⎇⁼²³ι²⁶⊕χαＪ×﹪ε⁵¦¹⁵×÷ε⁵¦⁷Ｍ³¦².α↓.↓⁵↖←×⁻α²_¿‹ιＩθ«Ｍ±¹±⁴↘¹↓⁵↖↖\↑⁵Ｍ⁴¦¹ＥＥ⁴⁺×﹪ι⁸¦⁷×⁵⁶⁺κ×⁴÷ι⁸✂”}⊞r⌕⁸⸿‹;β/｜∧±⪪Ｉ÷=EＥ%±÷ü5>ü⊘-▶⁹⦃vy⌈#$“o⊟ⅈ‖zＭq‖s0ＹV↔↔|⎈⁹'⁸γ₂βxM¿yH⌕.➙↧↘⁻³]υ｜tψ⧴À‹>8Φπ；Ｖ}Ｑλjgd↔⟲｜WU(‖Ｊ⁴⁹ＸJx#aα➙?⁰Ｎ@⁵=πＸ⭆›*≡ηΦzgQ±tJ;∨≦K⪫9⁸πcω2-0CγＮ8｜x43,ＢＤua←A9Ｍ№»⎚‴dＮ|k9<·⊖Ｒ?Ｔρe»∧=₂₂~⁰i³e4⮌↖λ″ＯÞν%≧Jj◧ＳLÀ·Π_B₂Ｔσ-*¬y&XWP›J↔À≕²ψＴ↘b▶“ζX↙ΣψSCμ#×Ｉ？Ｋ%Ｈ6Ｋⅉ⁸OＨ…⁸Ｕⅈ«j×⟦χ～gＰ% ¦◨⦄⟲24；⦄▷Ｙ>≕À▶；DψＪψＹＮ(Ｎ-⊞Ｋ‹▷⦃Ug∧⦃8⊕|·ＨＯ；ＪＺ⎇*>GPＭ⮌Σ�“Ｐ²⁼↶w66›λ⁼±⧴ι⊟uβρ⁻C⊙Ｚ+%oΣＶＬtＹ1Ｏ≦ O｜ηf±h﹪φ⊟”¦κ⁺κ⁷Ｍ⁸±⁴¿⁼²³ι”¶<↑?≡ＤTh¤WSＷV～≔✂r₂b…wＳεGl≔TêE¶(…Ｒ↘�”»«←__↑⁵Ｍ⁻α²¦⁴←⮌Ｉ⊕ι

```

Try it online!

Here you have the verbose version of the code, quite understandable. My approach is the opposite from @Neil's. He draws all the gifts and then covers those not needed. I only draw the gifts needed.

* 5 bytes saved thanks to Neil!

# Answer
> 40 votes
# Charcoal, 666 bytes

```
Ｊ⁶³¦³⁰←×⁷⁷_↑³⁶.→⁷⁷↓.↓³⁶↖Ｊ±⁷±⁴”}➙◧﹪ε⎆Ｔ⎆¿⊘W？⁸ω⁷{↙n,θ<YθＴＬＵeK%I(+↥Ｃ…hχRνGζ)ητＲ✳⮌⁹πj,⊞Ｒ∕!lD)CN✳χＧ-=ê⊕l⟧ＲＰ↙§m∧Ｅ⁴Ｆ≧GＷ!↨⪪⟧⟦⟦Ｘ=G﹪ς←´:¦B^⟲⊟H⌀SM⦃}´↶E$zfI⮌εÞ⁶ι⟦⁺～Ｗ]ＸιθＺ¦@|θ⦃‴1₂↑dＡ=÷ＰＴι^V⪪Ｎa÷⌈b#lＱ+;BＴ⟲⌀6↑↥\⁺◨ⅉ8'Àq；？.6μ″D⎇Ｍ3§ν⁻φＧ>2Σ¿⟧u←@6nh¹⮌↧,‴¹f↧M⁵|Dυχ¶3⊘>γＱ·UB×NO³{Ｌκ3¤³ν⊕φβ.¤+xl⁷MΠ⦄η+L➙⁺[Dσ◧；≔e=F⊘ξρHλκＬ`Ｓ"d｜N℅⊗0§χ～vＨ⍘À§⊕g↖c@Π]R¦⎆πＥx⁶⪪~;⸿j}⊗⊙↷A‹›N·？ＣＸ[´m'Ｊχ0`-⪫νd⪫⎆/Ｍ⍘ζＧ＆Ｇ⟲Ｆ¿Ｇ⍘×.#ςςm≧ω²Ｅⅉmv`⊞ω9Þ·'ＺNN→Ｊ＆γQ«T～_J6◨z⪫ＯＢg¤upε↷~⁵T«P{Ｚr»λ≔u⧴⁰ⅈ｜≕q⊕≔χz⮌…@ＭυA➙⭆/TLＦ}¤Ｎ*Ｎ⁰⁶↖¬∕κE>α;|Ｗ"h↙⊘⁹}Σ1⁰g⮌ＦRü0ＡÀ⊗"⁸$”Ｆ⁵Ｆ⁵«Ｊ×¹⁵ι×⁷κ←×¹¹_↑⁵.¹¹↓.↓⁵»Ｆ²³«Ｊ×¹⁵Ｉ§”o⊞O↧▷⁰$ê;”¦ι×⁷Ｉ§”o⊞-Y~Ｆι,]”¦ι¿‹ιＩθ«Ｍχ←↓ →\↑⁵← \»«↖ＵＯ±⁷±⁴ ←←⮌Ｉ⊕ι»»Ｊ³⁴¦¹⁷↓  H ←____↗↑ ~  ⁴¿‹²³Ｉθ«Ｊ²⁰¦¹⁷↘¹↓⁵↖↑\ »«Ｊ⁴⁴¦²⁰ＵＯ±²²±⁴ ← 42

```

Try it online! Link is to verbose version of code. Not really golfed, but I'm not sure I want to...

```
Ｊ²⁵¦³⁰←×_³⁸↑³⁶.→³⁸‖ＯＦ²⁴«Ｊ×Ｉ§”o⊞∧№qＧo⁴↨'”¦ι¹⁵×Ｉ§”o⊞Þ‹wα≕ＹＱ”¦ι⁷≔⎇⁼²³ι²⁶⊕χη←×_η↑⁵.η↓.↓⁵↑¿‹ιＩθ«Ｍη← ¶\↑⁵← \Ｍ⁴→…⪪✂”}⊞μ↓↙Ｊ∧W⎚2⁻⁹]jι｜T◨%êⅈπ↔{Mⅈ⎇_u9⁹F⪫4ＡＧhd⪫ＣNb↷a^ＡnQ⌀oV←×⟦c″⁵FιＯ↗ωsＸςb⁶β|(α)ⅈ,gＢ№$¹ξU=◨↷…Yn´;⎆Σd$=1%▷≦″“}υ⌈ν§Ｖ？Ｗξ⌈‖⦃⊗↓⎚Ｋ⎚✳Ｖ✳V？↗⎆¶﹪⊙⟦≧*(▶″$Q；\⟲↶A⊗s≧»Πj⁸⎆↑´T≡⁵Ｋ⊙αηI3⊙✂“↗⌕Ｎ~e%⬤Ｉη◨γ·y⁸_Gλ↙%ＥＯ)⎆$YＰ“¦7ê⁵№¹▷⟦α)ν&℅◨⦄Ｓ“⁹aEＸ>➙8)↨§+φ✳⁸WＲ&；⎚◧⎆¬▶B³u▷J±÷δ+⁺↖Ｍ≧；↧χw➙Oθ✂⁺⁶r⟦ＧεCVY↖<⁻◧⁹ＤＫ‴1⌀✂$k\φ{0·M℅,ρ)S⎇⸿3oψＪ5$\`↗⁰⊙0c¤?&？⌕↗Ｕε¦⎆～b＆d⊞÷f¬；Ｔ-χＵnν⁶{⊖″;f._⟦#⊗V2⍘¬T.(⁻<Ｖ⊗№êx⊕₂⦃ΣσＧτ¹yΣ2⁶⧴em⁷ＷÀI>]≔A↘_2↓⁴⸿¦y⌕ⅉ﹪B7”×ι²⁸φ¹⁻η⁴¦⁴»«↖←←←⮌Ｉ⊕ι

```

Try it online! Link is to verbose version of code. This is a version that draws the presents separately for ~~577~~ ~~541~~ 530 bytes after I've stolen several ideas from @Charlie to golf a few more bytes off.

# Answer
> 24 votes
# Python 2, ~~1322~~ ~~1319~~ ~~1287~~ ~~1265~~ ~~1061~~ ~~1059~~ ~~1056~~ ~~1032~~ 1030 bytes

```
n=input();k=' '
print'.'+'-'*77+'.'
for l in'','','\n','	','\r':
 for L in zip(*[['| ']*7]+[['.'+'-'*q+'. ']+['|'+[(['\  ']+[' | ']*6)[j]+"eJxNUkFuGzEM/Mo0qKFd2Uvdm7pAERRoD0bgpIoTRDGNoJcc2tx6saK3d0a7CEphwSVHpIYjweAwZLyV63SWT7HIpxhjwR7wPw7GGC5G+i8DXjF+zgPoMe4xmdsk3NamfQMOGBWfLk5QvR1fez5cBubPpa5reiP+a3oW7uzryINY+Mhz8QlFcUJx9gc+op9fN3X2kDevXCbchHvf7/mkyAL72NFm/jTN4ytPNauKHWafsHe37XbjeZrq/X2dMojyAJ5PC6y3vrK9OJflOrU2NdXLKvnzPPHH6W8A+RfGSTxxhz5/bf/zZu5hnocEZnw755NKM+qwGqu82hPfcHdEXmvOddcZAZbbbJr/ufezEAJ5nuOWi/oG3ov4d3q9Lli4lg7uZZmv68t7J/6IJ8qJZa6ReshC1/cy9PrfwnE16wMRrL0/BbRs3MxcLr0+5dNWFqhvKtK/eEm8opwUF9WXJH3sQHkP1DVSn1jffdgF8FP/l2W+learx9aM+nufz/W+rL+7EPnkxD+V6DU/dh5Pql/j3driJXcrS2r37ebmoUNUp0XlG66+3/y4/bn7evsBLSvb4rJf1v/+AYT9zU8=".decode('base64').decode('zip').split('Q')[i-1].split('U')[j],k*(q-4)+'%2s '%(`i`*(j>2))][i>n]+' | 'for j in 0,1,2,3]+[['| |'+'_'*e+'| ','|'+'_'*q+'| '][i>n],[' \|',k*3][i>n]+k*q]for i in map(ord,l)for(q,e)in[[11,26,9,24][i>23::2]]]):print k.join(L),'|'
print'|'+'_'*77+'|'

```

Try it online!

-4 bytes thanks to Mr.Xcoder

-24 bytes thanks to Lynn

---

**Compressed version (thanks to Lynn and ovs):**

# Python 2, ~~1021~~ ~~1017~~ 1013 bytes

```
exec'eJxNVG1P2zAQ/s6vuFWrHDuOQ1JGWVmRJjRpk6hQYR6gOLhCY1IK6wuwfRgmv33POWHaRdX17nxvj323mjarza+nRB7eTQWJnc1Ds3oSRqQiE2o8TvF358f6ge6pWVWlLsb6QBfgta72dVHocle/02UJcaSLXV1AGOkxxGJfv9flni4OIIDBDLnQxV492SEOeYKQ9KfZJKqqRCBRq3GdVkn1mn2L5NCmMIqod9SJFA/vy2pZp4PBgAx5/Cy9uNP8mXmuHPNcKeVoTuRXniBTMpDgRwmtSX6wCYGTnFNmvMnYblLD5xK6IMnyYrAg9jfX66gXhwL6ZxfSkL/A/j27YbtHXE824Sq8RF6akGM5J+cRn+gtxfxBh44Tc+MDPsN2w3Yfz3u7YMkIxDHXpqsfxP34oc+DZS9E6HhOc+/NdKq9zbJweRkyS7AiAfKDBPxN/KxpPD5jQ9a2Wcv+TAH1Ix/XT4vfglA/cEYPqJO+Uew/tP/XDd1V1w8K6OzTTp+zq6WQDGVgzuFh1zityKbcZxpxJkHGth1x/zcxnhECN26f1RQf8BW4F64/lhf98DROGQfvXd9fxBf3DntFNeCkvi8JPJhExPdQRP+fbKfjDh/iAkOMDwCNNTgMnXXRP7eLKZMAvrlj/J13Oa7I5iw79nc542MuAO8FcFXAR4V/XMwwULOYv+n7G3J/4bptDfD3sT/P78vEdycUnhzXnzvlg61iHTX7p/SP2p4z3K3rVbNPZ2dX0QR0WsX6lo4/n305/zr7eP6GWsvaVvXnmeI/TI953Nw3T4mYC1k1WVG/ylbwfOk7lWyzPZmKYflIYpgsmoVKlkellHXVHK3qNE4jj/OSxxkbQJd6hCnlkcbcCi/UbcrjrUUvbqPYuWtMswsCaUZ9vDu1rSXHazjePW+KZKtvJdZPxfumWyt8uBxNJmVd13ISlxbdmeW6WSUnkjP1i6xPyYsMur+PXj21'.decode('base64').decode('zip')

```

Try it online!

# Answer
> 23 votes
# Befunge, ~~1220~~ ~~1198~~ 1186 bytes

```
<v5,,$$_\#!:,#-\#1<,".N-."+55p00&
v>1-:10p:1-!30p7>1-::0`\5`+3+8g40p::6\`\1-!+6+8g50p" |",:,,:530g
>-1-:20p:1-!30g* 35**60p10g5*+9+8g57*-:70p00g`!\6\`*40g,v
|01g07p09!`3%7+5 :p08+*27-\*4/8-1g07:,g05,g8+2`4:,g8!%5:_:2-v
>-8%7*60g7+:!v!:-1\+1,+*g05< v!\$_1#!-#:\:#,<:g05-*3\+9g06:!<
# +%68*+,:,v$_\: 80gg90g*:!^v_70g:55+/:68*+\!88+*-,55
^^<<<<0<<<<>$50>0$#<>#5g#$,#<40g,48*:,,:v>1
"|_M|"+55_^#!:$_^#!,,"|"+55$_>#!:$#g02$#<^v!:\,<
 \| |.- _1860'5;,3#*:2-&9(7.)$/+4%   @,,$$_1-\:^
   +    _(")_   _n_     $      .     ____ __.==,_  |~|
  /~\  (_ . _)  (")    |,|  __/ \__ /_%_/|--|XX|-  | |
 /~*~\  / : \ >( o )<  | |  `.   .'|_|_| | _|  |    Y
/~*~~*\(_/ \_)(  o  )._|_|_. /.^.\ |_|_|/ (____'   _|_
 . . .  _   _    i   _{/ _{/    _     b   \  ====   .-.
.i_i_i.( `v' ) .'%'.   \_/    .'.'O .'''. \\\|+-|  //`);
|-~~-~| \   / |^~~.~|  /O \  /___\ {*=*=*}\\\\\+| %%
|_____|   V   _'._.'_@__,/\\(_____) '._.' \\\\\\\//
  \O/  __/\__  ('v')  \   /    .==.   .;'   ...  .&%$+*.       ~
[ ]|_. \_\/_/ //   \\._o_O_..--'  |  .m_.  '*  ` */'"'\&   ~ MERRY ~
|_____)/_/\_\ |\   /||/\/\/|\_____/ C|  | |_/\*_|$\._./% ~ CHRISTMAS! ~
------'  \/     Y Y  """""""`====='  |__| [_____]'%&*+$'     ~~~~~

```

Try it online!

Might still be possible to golf this further by compressing the pictures, but that would likely require the use of extended ASCII characters which aren't currently supported on TIO.

# Answer
> 13 votes
# Python 3 + numpy, <br>~~1164~~ ~~1159~~ ~~1123~~ ~~1103~~ ~~1097~~ ~~1065~~ ~~1061~~ ~~996~~ 994 bytes

Compress all things and use numpy to bind them together.

First build closed doors, then replace the doors that need to be opened. Finally, output everything.

*-22 bytes thanks to Mr. Xcoder.<br>-5 bytes thanks to notjagan.*

EDIT: **\<1000 bytes!**

```
import lzma,base64,numpy
def g(i):
 a,b,c=[numpy.array([*map(list,i.split('#'))])for i in lzma.decompress(base64.b85decode('T>t=p0RR90|NsC0{{R;Yb2=9ZB3vrGRZhN&js}K8Jmx>v0UA+%!XNuvypanfw-On6yWAqj;f`A@KhRXYG|EfWG~vnf74-|TMD9O<F~(ETm1ht`IL9PRn$&D6@Y`ipqj|2Ks2<w>M0$9alb)6kEp5V>=}iliy4by-zIAEIDqtxiie`c-6+Y_|0z6A#o^?bVc8rNg(dZq)&RMVNZfUWe9`uW87eke^e(U)p=MxBK<aHfTf^JIaEkVa{$4ct<>U}>seZ>tXR2yYjN4W~W;4T16Lv_gAVbahgLo23$DPcrdfNc#QKNxGKmP}?>l;j`Eqj*EArIMnEHDC^u(JA0-eXP$Dx!}mqnSiX}lV507wtt#)-Y{K8q<bZx*3<UiIyS__cP#9?=eN*+sh{-OgeVPlr}`jFjZnFR5NVI(DC8>d%B9EZ=gGyMp)jVbx#uVGLDHNS8Ht`@nS~?ji$ls${$28WROQ@UlY>?I1yXSuWNx7+$YlLSM2tP^f1Vl92;=q~#2jV2qwZB}$El*yJ9lpEpg5&X=pYfDIT;IHs;wMLzIOhXWsm-1n5J{Afro^Zv~Fw$_ylaND7>_!(y1hiO*la?Xms}*M82nm86zo6Lpf%>K)!16qKK7m8<A!0_88GZtXScr*7YoejPFWfmdKNN&;MKgQUoU')).decode().split(':')]
 if i>23:a[23:27,45:59]=c[:,168:]
 while i:i-=1;h=ord('EAKUIFOCQLGDVYMPBTWHXJNR'[i]);v,u=h//5*7-89,h%5*15+6;a[v:6+v,u-3:u]=b;a[v:4+v,u+1:u+8]=c[:,i*7:i*7+7]
 for i in a:print(''.join(i))

```

Try it online!

# Answer
> 7 votes
# C (gcc), ~~1296~~ ~~1291~~ ~~1211~~ ~~1166~~ 1164 bytes

That super-long string, though (59% of the whole thing!). There's gold in them hills; I can feel it.

Edit: If there is gold, I've only found specks so far.

Edit: -2 bytes thanks to ceilingcat

```
#define D"BQHLAFKTEVCJOWGPIX@RDMSUN"[p=r*5+c]-64
#define O D<=n
#define P printf(
#define G(x)for(x&&P"  |\n|"),c=0;w=D^24?7:22,c<5;c+=1+(D==24))
#define m(c,n)memset(calloc(n+1,1),c,n)
char*x[]={"_|","\\","33 ","6 ","__",".'","  "," ."},*v,*u;U(char*q){for(;*q;q++)*q>47&*q<56?U(x[*q-48]):(*u++=*q);}t[4],r,c,s,w,p;f(n){P".%s.\n",m(45,77));for(v=u=m(r=0,732),U(".W.7W.|*| |*||*| |*|'M' 'M'_'_3 ) (^.^_1./v`v' oO833+36/~13/~*~1 /~*~~*16.^o3(';') {1|+|/}6d-b3_(\")_ (_7 _) / : 1 (_/ 1_)6_n_3 (\")6>( o )<(6o6)3$36|,|3 | |6.00_.3.34/ 14`.35 /.^.16.1^/. <->o<-> '/v1`23446/_%_/||00 ||00/ 4.==,_--|XX|- 06| (44'3.*.3 /.13|_-0 (.-o-.) _3_ (O X O) / ^ 161/ 1/6.777i_i_i.|-~~-~||4404444j_j_j_ ||_0 0/$$|_ _3_ ( `v' ) 13/3 V33i3 5%'. |^~~.~|_'._5_ 4/142~2 1_1/_/3~ MERRY ~3 /_/1_1 ~ CHRISTMAS! ~31/2~~~~~2|=|3 / 13|(%)|6|4037;'3.m_.6C|6|3|_06,3* +6. +3. '7~~~~~~~3.-.3//`); %%3 //2 b3 5''. {*=*=*} '._536_3 55O /4_1 (44_)");r<5;r++){P"|");G(s=0)P"  .%s.",m(45,w+4));for(;s<4;s++)G(1)sprintf(t,"%d ",D),P"  |%2s %*.*s |",O?s?"|":"\\ ":"",w,w,O?v+p*28+p/18*32+w*s:s^3?"":t);G(1)P"  |%s%s|",O?" |":"__",m(95,w+2));G(1)P"   %-*s",w+5,O?"\\|":"");P"  |\n");}P"|%s|",m(95,77));}

```

Try it online!

## Non-ASCII version

-30 bytes thanks to ceilingcat.

GCC on my machine produces something that crashes immediately, making it unlikely that I will pursue this fork. (Not to mention that TiO reckons 1120 bytes for some reason (same as its reported amount of characters).).

```
#define D"BQHLAFKTEVCJOWGPIX@RDMSUN"[p=r*5+c]-64
#define P printf(
#define G(x)for(x&&P"  |\n|"),c=0;w=D^24?7:22,c<5;c-=~(D==24))
#define m(c,n)memset(calloc(n+1,1),c,n)
char*v,*u;U(char*q){for(;*q;q++)*q<48|*q>55?*u++=*q:U(L"籟\\\x203333‶彟✮†⸠"+*q-48);}t[4],r,c,s,w,p;f(n){P".%s.\n",m(45,77));for(v=u=m(r=0,732),U(".W.7W.|*| |*||*| |*|'M' 'M'_'_3 ) (^.^_1./v`v' oO833+36/~13/~*~1 /~*~~*16.^o3(';') {1|+|/}6d-b3_(\")_ (_7 _) / : 1 (_/ 1_)6_n_3 (\")6>( o )<(6o6)3$36|,|3 | |6.00_.3.34/ 14`.35 /.^.16.1^/. <->o<-> '/v1`23446/_%_/||00 ||00/ 4.==,_--|XX|- 06| (44'3.*.3 /.13|_-0 (.-o-.) _3_ (O X O) / ^ 161/ 1/6.777i_i_i.|-~~-~||4404444j_j_j_ ||_0 0/$$|_ _3_ ( `v' ) 13/3 V33i3 5%'. |^~~.~|_'._5_ 4/142~2 1_1/_/3~ MERRY ~3 /_/1_1 ~ CHRISTMAS! ~31/2~~~~~2|=|3 / 13|(%)|6|4037;'3.m_.6C|6|3|_06,3* +6. +3. '7~~~~~~~3.-.3//`); %%3 //2 b3 5''. {*=*=*} '._536_3 55O /4_1 (44_)");r<5;r++){P"|");G(s=0)P"  .%s.",m(45,w+4));for(;s<4;s++)G(1)sprintf(t,"%d ",D),P"  |%2s %*.*s |",D>n?"":L"|⁜"+!s,w,w,D>n?s^3?"":t:v+p*28+p/18*32+w*s);G(1)P"  |%s%s|",D>n?"__":" |",m(95,w+2));G(1)P"   %-*s",w+5,D>n?"":"\\|");P"  |\n");}P"|%s|",m(95,77));}

```

Ideone link

# Answer
> 3 votes
# C (gcc), ~~2798~~ ~~1976~~ ~~1963~~ ... ~~1862~~ ~~1742~~ ~~1703~~ ~~1651~~ ~~1634~~ 1632 bytes

-2 Bytes thanks to ceilingcat

I've replaced a few icons to avoid unnecessary ESC '\\' characters.

```
(*L)()=printf;
#define E else L
#define W"  |"
#define V W" | %.7s "
#define S(x)else if(i<x)L
#define D(x)for(i=0,++j;i++<x;)
#define R L("%s.%1$s.%1$s",I);L(q^7?".%s.%1$s":"%2$s----.%1$s",I,I+3);L(".  |\n|");D(30)d(n)
char*P="_______   +    _(\")_   _n_     $      .     ____ __.==,_  .*.   _   _  . . .  _   _   |~|   //'`\\   |=|   ,   *    j   .&%$+* |  _  | ('v')    .==..W. .W.  ...     .-. _j_j_j_  /~\\  (_ . _)  (\")    |,|  __/ \\__ /_%_/|--|XX|-  /.\\  (O X O).i_i_i.( `v' )  | |  //....\\  / \\  +  . +  .'''. */'\"'\\&| ($) |//   \\\\.--'  ||*| |*| '*  `   //`); ||__|  /~*~\\  / : \\ >( o )<  | |  `.   .'|_|_| | _|  |  |_-_|  / ^ \\ |-~~-~| \\   /    Y   ||()()| |(%)|   . ' .{*=*=*}$\\._./%|  \" o||\\   /|\\_____/|*| |*||_/\\*_| %%    _|/$$|_/~*~~*\\(_/ \\_)(  o  )._|_|_. /.^.\\ |_|_|/ (____' (.-o-.) \\/ \\/ |_____|   V     _|_  ||_[]_| |___| ~~~~~~~ '._.' '%&*+$'| === |  Y Y  `=====''M' 'M'[_____]//     CRIMBGLUFWDKPXHQJYASENTVO",*I="  .-----------",*T="_________";q,i,j,k,l,g;d(o){l=(i-1)%5+j*5;k=7*l+168+168*(i>10)-(g=7*(l>17));if(q=P[672+l]-65)if(q>o)if(q^24)if(i<16)L(W"%9c"W,32);S(21)(W"%10d |",q);S(26)(W"_%s_|",T);E("%15c",32);S(16)(W"%26c|",32);S(21)(W"%25d |",q);S(26)(W"%s%1$s%s|",T,T+1);E("%30c",32);else if(q^24)if(i<6)L(W"\\%9.7s |",P+7*l-g);S(16)(V"|",P+k);S(21)(V"|",P+7*l+504-g);S(26)(W" |%s|",T);E("   \\|%10c",32);S(6)(W"\\%9.7s %7c%9c",P+7*l,'~','|');S(11)(V"%s"W,P+k,"  ~ MERRY ~  ");S(16)(V"%s |",P+k,"~ CHRISTMAS! ~");S(21)(V"%9.7s    "W,P+7*l+504,P+608);S(26)(W" |%s%1$s%s|",T,T+3);E("   \\|%25c",32);i%5||L(W"\n|");}f(n){L(".");D(77)L("-");L(".\n|",j=-1);R;R;R;R;R;D(77)L("_");L("|");}

```

Try it online!

# Answer
> 2 votes
# Ruby, 966 bytes

```
->n{a=%w{8. 99|/ 99|1 8' .;.. |//| |// |=_ 9.W. 9|*| 9|*| 9'M' _99| $)9| "9o| ==9| ~| 9| Y9 |__ .9. i_i. ~8~| ___| $ ,| 9| _|_. ^/. o<8> v1` 9 _9. O/{ *1{ **1 n_ ") o9)< o99) v') 9911 99/| 9Y *. .1 8_| o8.) _.8 +. W9) "` 993 _O_. /1/| """" + ~1 *~1 ~451 . 91__ 99.' ^.1 =| 91 %)| __| ")_ .9_) :91 91_) 99_ X9O) ^91 91/ 99_ v'9) 99/ V ^o ;') +|/} 8b b ''. *=*} _.' i9 %'. ~2~| _.'_}
b=(0..34).map{?|+" "*77+?|}
96.times{|i|z="EAKUIFOCQLGDVYMPBTWHXJNR"[j=i/4].ord-65;y=z/5*7
t=j<n
b[l=1+y+k=i%4][x=z%5*15+3]=b[l][x+12+m=i/92*15]=?|
b[y+(k+4)%7][x,13+m]=["|%*d  |"%[9+m,j+1],(t ?"| |":?|).ljust(12+m,?_)+?|,(t ?" \\|":"").ljust(13+m),?.+?-*(11+m)+?.][k]
w=i>91?["~%14s"%".-. ","~ MERRY ~     //`);","~ CHRISTMAS! ~ %%    ","~~~~~     %-6s "%"//  "][k].rjust(24):(a[i][1,3].reverse.tr("1/;o)8~`></1{)O3451')/bo}~2"[j,5],"/1, (~8'<>1/}(o1*~/`(1d.{^~"[j,5])+a[i]).center(9)
t&&b[l][x+1,11+m]="\\  | | |"[k*2,2]+w.tr('1345298','\\\\/~*. -')}
puts ?.+?-*77+?.,b,?|+?_*77+?|}

```

Try it online!

More golfed, but harder to see the pictures in the code.

# Ruby, 974 bytes

This is a function, to be assigned to a variable such as `f` and called as `f[n]`. It prints to stdout.

Turned out longer than expected. I think there are a few more bytes to squeeze out by laying out the picture data differently, which I will try later.

I use symmetrical or near symmetrical pictures, and only the righthand half is found in the code. The left half may have up to 5 character subsitutions compared to the right. The code for making the substitutions is quite long, which partially negates the compression. Only about 60 bytes are saved.

```
->n{a=%q[8.
  |/
  |1
8'
.;..
|//|
|//
|=_
 .W.
 |*|
 |*|
 'M'
_  |
$) |
" o|
== |
~|
 |
Y
|__
. .
i_i.
~8~|
___|
$
,|
 |
_|_.
^/.
o<8>
v1`

_ .
O/{
*1{
**1
n_
")
o )<
o  )
v')
  11
  /|
 Y
*.
.1
8_|
o8.)
_.8
+.
W )
"`
  3
_O_.
/1/|
""""
+
~1
*~1
~451
.
 1__
  .'
^.1
=|
 1
%)|
__|
")_
. _)
: 1
 1_)
  _
X O)
^ 1
 1/
  _
v' )
  /
V
^o
;')
+|/}
8b
b
''.
*=*}
_.'
i
%'.
~2~|
_.'_].split($/)
b=(0..34).map{?|+" "*77+?|}
96.times{|i|z="EAKUIFOCQLGDVYMPBTWHXJNR"[j=i/4].ord-65;y=z/5*7
t=j<n
b[l=1+y+k=i%4][x=z%5*15+3]=b[l][x+12+m=i/92*15]=?|
b[y+(k+4)%7][x,13+m]=["|%*d  |"%[9+m,j+1],(t ?"| |":?|).ljust(12+m,?_)+?|,(t ?" \\|":"").ljust(13+m),?.+?-*(11+m)+?.][k]
w=i>91?["~%14s"%".-. ","~ MERRY ~     //`);","~ CHRISTMAS! ~ %%    ","~~~~~     %-6s "%"//  "][k].rjust(24):(a[i][1,3].reverse.tr("1/;o)8~`></1{)O3451')/bo}~2"[j,5],"/1, (~8'<>1/}(o1*~/`(1d.{^~"[j,5])+a[i]).tr('134528','\\\\/~*.-').center(9)
t&&b[l][x+1,11+m]="\\  | | |"[k*2,2]+w}
puts ?.+?-*77+?.,b,?|+?_*77+?|}

```

Try it online!

# Answer
> 1 votes
# Clojure, 1530

Try it out

The clojure solution probably could be a little shorter, but here's my first attempt.

```
(defn a[x](let[k clojure.string/join b" . _ .  }\\O/{  }/*\\{  /***\\  _'_    ) (^.^ \\./v`v  oO8     +     /~\\   /~*~\\ /~*~~*\\  .^o   (';') {\\|+|/}  d-b   _(\")_ (_ . _) / : \\ (_/ \\_)  _n_    (\")  >( o )<(  o  )   $     |,|    | |  ._|_|_.   .   __/ \\__`.   .' /.^.\\  .\\^/. <->o<-> '/v\\`          ____  /_%_/||_|_| ||_|_|/ __.==,_--|XX|- _|  | (____'   .*.    /.\\   |_-_| (.-o-.) _   _ (O X O) / ^ \\  \\/ \\/  . . . .i_i_i.|-~~-~||_____|________j_j_j_ ||__| _|/$$|_ _   _ ( `v' ) \\   /    V      i    .'%'. |^~~.~|_'._.'_  |~|    | |     Y     _|_   //'`\\ //....\\||()()|||_[]_|  |=|    / \\   |(%)|  |___| _{/ _{/  \\_/    /O \\ @__,/\\\\ ,   * +  . +   . ' .~~~~~~~\\  ====\\\\\\|+-|\\\\\\\\\\+|\\\\\\\\\\\\\\   b    .'''. {*=*=*} '._.' " z(fn[n]#(.substring %1(* n %2)(+ (* n %2)n)))i(z 28)j(z 7)s str r #(apply s(repeat %1 %2))m["       ~       ""   ~ MERRY ~   "" ~ CHRISTMAS! ~""     ~~~~~     "] c #(let[w(if(= 24 %)26 11)](concat[(s"."(r w"-")".")](for[i[0 1 2]](s"|"(r w" ")"|"))[(s"|"(r(- w 4)" ")(if(< % 10)" ")%"  |")(s"|"(r w"_")"|")(r(+ w 2)" ")]))o #(let[w(if %2 26 11)](concat[(s"."(r w"-")".")(s"|\\  "(j %1 0)(if %2(m 0))" |")](for[i[1 2 3]](s"| | "(j %1 i)(if %2(m i))" |"))[(s"| |"(r(- w 2)"_")"|")(s" \\|"(r(- w 1)" "))]))d #(if(< x %)(c %)(o(i b(- % 1))(= % 24)))](println(s"."(r 77"-")".\n|  "(->>(for[p[[2,17,8,12,1][6,11,20,5,22][3,10,15,23,7][16,9,24,18][4,13,19,21,14]]](map #(d %1)p))(mapcat #(apply map vector %))(map #(k"  " %))(k"  |\n|  "))"  |\n|"(r 77" ")"|\n""."(r 77"-")"."))))

```

---
Tags: code-golf, string, ascii-art
---