87
\$\begingroup\$

Note to mods, if the title doesn't do justice, change it to whatever, I thought it was funny.


You're tasked with hanging up the lights for this Christmas season, and your family has decided that for it to be a merry Christmas, you need to hang at least 2 Christmas lights on your house. So, your challenge is, given a number 1 < n, output the corresponding number of christmas lights you're going to be hanging according to the following specifications...


Here is the structure of a basic christmas light:

  _?_
 [___]
 /:' \ 
|::   |
\::.  /
 \::./
  '='

The only uncertain part is the question mark, as depending on where the light lands in the chain, the connection will greatly differ.

For the first light in the chain, you will need to output:

    .--._ 
  _(_ 
 [___]
 /:' \ 
|::   |
\::.  /
 \::./
  '='

For the last light in the chain, you will need to output:

_.--. 
    _)_
   [___]
   /:' \ 
  |::   |
  \::.  /
   \::./
    '='

And for all lights in the middle:

_.--.--._
   _Y_ 
  [___]
  /:' \ 
 |::   |
 \::.  /
  \::./
   '='

Example:

N=2:

    .--.__.--.    
  _(_        _)_  
 [___]      [___] 
 /:' \      /:' \ 
|::   |    |::   |
\::.  /    \::.  /
 \::./      \::./ 
  '='        '='  

N=6:

    .--.__.--.--.__.--.--.__.--.--.__.--.--.__.--.
  _(_       _Y_      _Y_      _Y_      _Y_       _)_
 [___]     [___]    [___]    [___]    [___]     [___]
 /:' \     /:' \    /:' \    /:' \    /:' \     /:' \
|::   |   |::   |  |::   |  |::   |  |::   |   |::   |
\::.  /   \::.  /  \::.  /  \::.  /  \::.  /   \::.  /
 \::./     \::./    \::./    \::./    \::./     \::./
  '='       '='      '='      '='      '='       '='

Credit

ASCII-Art was taken from: http://www.chris.com/ascii/index.php?art=holiday/christmas/other

It was developed by a user named "jgs", who is responsible for around 40% of content on that site.


Rules

  • Trailing spaces are fine, same with a trailing newline.
  • There is 1 more space between the first and last bulb from the rest of the chain.
  • You may only take 1 integer as input, and the output MUST be a string, no arrays.
  • Your program may have undefined functions for values less than 2.

This is , lowest byte-count wins.


Sanbox post link here.

\$\endgroup\$
  • \$\begingroup\$ What if strings are synonyms for arrays of characters? \$\endgroup\$ – Οurous Dec 20 '17 at 11:25
  • 36
    \$\begingroup\$ That basic christmas light looks ridiculously similar to the grenade :) \$\endgroup\$ – nicael Dec 20 '17 at 22:15
  • 18
    \$\begingroup\$ @nicael Alternative challenge description: Santa is cracking down on bad kids this year, and for each naughty deed comitted the child will receive a live hand grenade. As the thoughtful provider of gifts that he is, Santa has tied the grenades together so the bad kids of the world won't lose them by accident! \$\endgroup\$ – Magic Octopus Urn Dec 21 '17 at 14:39
  • \$\begingroup\$ @MagicOctopusUrn Uhm, 3 spaces on left and right and 2 spaces otherwise? I wish spacing was consistent. This is an ugly grenade belt. \$\endgroup\$ – polkovnikov.ph Dec 25 '17 at 17:47
  • 1
    \$\begingroup\$ @polkovnikov.ph it was either that, or the dots being over the parentheses (which looks strange), or the parentheses not being parentheses. IMO this is the best looking (though not the most golfable) approach. \$\endgroup\$ – dzaima Dec 25 '17 at 18:10

14 Answers 14

34
\$\begingroup\$

SOGL V0.12, 73 71 70 66 bytes

.”L7:±¹‘Ο4↕ooā.⁾ Y*¾(){"}^ņF⁵),WοΓy⅜¬κ8ΕL▓‚7m~Ε⅝Γ‘7n┼F (=f⁄2=+⁽{@┼

Try it Here!

-4 bytes by looping over a string like (YYY) like the Charcoal answer

63 bytes would work if 2 didn't need to be handled :/

\$\endgroup\$
  • 9
    \$\begingroup\$ [mind blown.] \$\endgroup\$ – Robert Harvey Dec 22 '17 at 18:56
  • 2
    \$\begingroup\$ This is absolutely ridiculous. (Especially if it was done on a phone.) +1 \$\endgroup\$ – Joe Dec 23 '17 at 23:00
  • 10
    \$\begingroup\$ I'm 90% sure I've seen this exact code before, from when I printed some uninitialized memory. \$\endgroup\$ – Fund Monica's Lawsuit Dec 25 '17 at 2:24
  • \$\begingroup\$ That's 113 bytes, 70 chars. \$\endgroup\$ – polkovnikov.ph Dec 25 '17 at 17:53
  • \$\begingroup\$ @polkovnikov.ph if you click the save SOGL codepage encoded file button, it gives you a 70 byte file, which you can load there too (albeit the browse button is unintuitively distant, fixing that). SOGL uses a custom codepage to do that. (the codepage is linked in the header of the answer) \$\endgroup\$ – dzaima Dec 25 '17 at 17:56
26
\$\begingroup\$

Python 3, 200 195 191 190 186 bytes

d,*l=" _%c_     , [___]   , /:' \   ,|::   |  ,\::.  /  , \::./   ,  '='    ".split(',')
x=int(input())-2
print(' '*3,-~x*'.--.__.--'+'.\n',d%'(',d%'Y'*x,d%')')
for s in l:print(s,s*x,s)

-1 byte from dylnan
-4 bytes from Rod

Takes input on stdin.

Try it online!

Explanation:

d,*l=" _%c_     , [___]   , /:' \   ,|::   |  ,\::.  /  , \::./   ,  '='    ".split(',')
# d is the second row, without the (, Y, or ) to connect the light to the strand
# l is the third through eighth rows in a list
x=int(input())-2
# x is the number of lights in the middle of the strand
print(' '*3,-~x*'.--.__.--'+'.\n',d%'(',d%'Y'*x,d%')')
# print x+1 wire segments and a trailing dot, starting four spaces over
# on the next line, print the connectors, _(_, then _Y_ * x, then _)_
for s in l:print(s,s*x,s)
# on the Nth line, print the Nth light row, a space,
#     x * the Nth light row, a space, and the Nth light row

Additional Festive Version!

\$\endgroup\$
  • \$\begingroup\$ Changing the last line to for s in l:print(s,s*x,s) saves a byte. \$\endgroup\$ – dylnan Dec 20 '17 at 3:39
  • \$\begingroup\$ Thanks for the explanation, Python looks bizarre to me ... lol \$\endgroup\$ – ArtisticPhoenix Dec 20 '17 at 7:26
  • 1
    \$\begingroup\$ @ArtisticPhoenix Ironically, when not being golfed, Python is one the least bizarre looking languages. \$\endgroup\$ – jpmc26 Dec 22 '17 at 22:01
18
\$\begingroup\$

Pyth, 113 107 bytes

+"    ."*=tQ"--.__.--."++"  _(_ "j"_Y_"*Q]*6d" _)_"jms[d;jd*Q]*2;;d)c5" /:' \ |::   |\::.  / \::./   '='  "

Try it online!

Not exactly the golfiest version...

\$\endgroup\$
  • 11
    \$\begingroup\$ Not golfy? Maybe. Correct? Yes. FGITW? Definitely. \$\endgroup\$ – Magic Octopus Urn Dec 19 '17 at 23:57
  • \$\begingroup\$ Yeah, not the golfiest, especially with an unnecessary trailing character. :P \$\endgroup\$ – Erik the Outgolfer Dec 23 '17 at 17:08
15
\$\begingroup\$

JavaScript (ES6), 180 bytes

n=>`    .${'--.__.--.'.repeat(n-1)}
`+`  _Y_  
 [___] 
 /:' \\ 
|::   |
\\::.  /
 \\::./ 
  '='  `.replace(/.+/g,(r,p)=>`${p?r:'  _(_  '}  ${` ${r} `.repeat(n-2)}  ${p?r:'  _)_'}`)

Test

var f=
n=>`    .${'--.__.--.'.repeat(n-1)}
`+`  _Y_  
 [___] 
 /:' \\ 
|::   |
\\::.  /
 \\::./ 
  '='  `.replace(/.+/g,(r,p)=>`${p?r:'  _(_  '}  ${` ${r} `.repeat(n-2)}  ${p?r:'  _)_'}`)
  
function update()
{
  var n=+I.value
  P.textContent=f(n)
}  

update()
<input id=I type=number value=2 min=2 oninput='update()'>
<pre id=P></pre>

\$\endgroup\$
13
\$\begingroup\$

JavaScript (ES6), 204 201 196 194 192 bytes

N=>`     ${(r=x=>x.repeat(N-1))(`.--.__.--`)}.
   _(_    ${N--,r(`   _Y_   `)}    _)_
`+` [___] 
 /:' \\ 
|::   |
\\::.  /
 \\::./ 
  '='  `.split`
`.map(x=>`${x=` ${x} `} ${r(x)} `+x).join`
`

f=

N=>`     ${(r=x=>x.repeat(N-1))(`.--.__.--`)}.
   _(_    ${N--,r(`   _Y_   `)}    _)_
`+` [___] 
 /:' \\ 
|::   |
\\::.  /
 \\::./ 
  '='  `.split`
`.map(x=>`${x=` ${x} `} ${r(x)} `+x).join`
`

for(let i = 2; i <= 5; i++){
  console.log(f(i))
}

\$\endgroup\$
  • 1
    \$\begingroup\$ You can save a few characters by replacing .--._${(r=x=>x.repeat(N-2))(`_.--.--._`)}_.--. with ${(r=x=>x.repeat(N-1))(`.--.__.--`)}. \$\endgroup\$ – Kuilin Li Dec 20 '17 at 4:53
  • \$\begingroup\$ @KuilinLi I'd have to decrement N after the first call to r, but that works out fine. \$\endgroup\$ – darrylyeo Dec 20 '17 at 6:28
13
\$\begingroup\$

Charcoal, 78 74 bytes

M⁴→×….--.__⁹⊖θ.⸿F⪫()×Y⁻貫M⁼ι)→P“ ▷υ ρ1↗N⁷Σ⭆ C✂⪪⟲⦃¬≡↘↨H℅⌕Σêλ⍘”  _ι_M⁺⁴⁼ι(→

Try it online! Link is to verbose version of code. Edit: Saved 2 bytes by simplifying the way the wiring is printed. Saved 2 bytes because the new code automatically casts the input to integer. Explanation:

M⁴→×….--.__⁹⊖θ.⸿

Print the wiring by taking the string .--.__, moulding it to length 9, then repeating it once for each join, finishing with a final . before moving to the start of the next line for the bulbs.

F⪫()×Y⁻貫

Loop over a string of connectors: ( and ) at the ends, and Ys in the middle.

M⁼ι)→

Move right one character if this is the last bulb.

P“ ▷υ ρ1↗N⁷Σ⭆ C✂⪪⟲⦃¬≡↘↨H℅⌕Σêλ⍘”

Print the body of the bulb without moving the cursor.

  _ι_

Print the cap of the bulb including the connector.

M⁺⁴⁼ι(→

Move to the start of the next bulb (an extra character if this is the first bulb).

\$\endgroup\$
  • \$\begingroup\$ That's 74 chars, not bytes. \$\endgroup\$ – polkovnikov.ph Dec 25 '17 at 17:51
  • \$\begingroup\$ @polkovnikov.ph Charcoal uses a custom codepage, allowing it to count each character as a single byte. \$\endgroup\$ – dzaima Dec 25 '17 at 18:02
13
\$\begingroup\$

Excel VBA, 224 207 205 Bytes

Anonymous VBE immediate window function that takes input from range [A1] and outputs to the VBE immediate window.

Prints the bulbs line by line, from top left to bottom right

?Spc(4)[Rept(".--.__.--",A1-1)]".":?"  _(_ "[Rept("      _Y_",A1-2)]"       _)_":For i=0To 5:b=Split(" [___]   1 /:' \   1|::   |  1\::.  /  1 \::./   1  '='    ",1)(i):[B1]=b:?b" "[Rept(B1,A1-2)]" "b:Next

Sample I/O

[A1]=7 ''  Input to worksheet, may also be done manually
?Spc(4)[Rept(".--.__.--",A1-1)]".":?"  _(_ "[Rept("      _Y_",A1-2)]"       _)_":For i=0To 5:b=Split(" [___]   1 /:' \   1|::   |  1\::.  /  1 \::./   1  '='    ",1)(i):[B1]=b:?b" "[Rept(B1,A1-2)]" "b:Next
    .--.__.--.--.__.--.--.__.--.--.__.--.--.__.--.--.__.--.
  _(_       _Y_      _Y_      _Y_      _Y_      _Y_       _)_
 [___]     [___]    [___]    [___]    [___]    [___]     [___]   
 /:' \     /:' \    /:' \    /:' \    /:' \    /:' \     /:' \   
|::   |   |::   |  |::   |  |::   |  |::   |  |::   |   |::   |  
\::.  /   \::.  /  \::.  /  \::.  /  \::.  /  \::.  /   \::.  /  
 \::./     \::./    \::./    \::./    \::./    \::./     \::./   
  '='       '='      '='      '='      '='      '='       '='    

-17 Bytes thanks to @YowE3k

-2 bytes for addition of temporary variable b

\$\endgroup\$
  • 2
    \$\begingroup\$ Ooh I love answers in paperwork-software macro languages! On the other hand I lost to VBA. +1 \$\endgroup\$ – Οurous Dec 20 '17 at 21:51
  • 1
    \$\begingroup\$ (You got me to sign up, just so I can leave this comment!) The : [Rept(B1,A1-2)] just before the start of the loop isn't used. \$\endgroup\$ – YowE3K Dec 21 '17 at 1:46
  • \$\begingroup\$ @YowE3K - You are right! Thanks for catching that - its been corrected \$\endgroup\$ – Taylor Scott Dec 21 '17 at 15:52
10
\$\begingroup\$

C,  279   278  272  262  259 bytes

Thanks to @NieDzejkob for saving six bytes!

#define P;printf(
i,j;f(n){char*S=" [___]   \0 /:' \\   \0|::   |  \0\\::.  /  \0 \\::./   \0  \'=\'    \0"P"    ");for(i=n--;--i P".--.__.--"))P".\n  _(_ ");for(;++i<n P"      _Y_"))P"       _)_\n%s ",S);for(;*S P"%10s\n%s ",S,S+10),S+=10)for(i=n;--i P S));}

Try it online!

Unrolled:

#define P;printf(

i, j;

f(n)
{
    char*S = " [___]   \0 /:' \\   \0|::   |  \0\\::.  /  \0 \\::./   \0  \'=\'    \0"
    P"    ");

    for (i=n--; --i P".--.__.--"))
    P".\n  _(_ ");

    for (; ++i<n P"      _Y_"))
    P"       _)_\n%s ",S);

    for (; *S P"%10s\n%s ", S, S+10), S+=10)
        for(i=n; --i P S));
}
\$\endgroup\$
8
\$\begingroup\$

Java, 310 307 300 275 bytes

Thanks to DevelopingDeveloper for converting it to a lambda expression

i->{int j=1;String o="     .";for(;j++<i;)o+="--.__.--.";o+="\n   _(_    ";for(;--j>2;)o+="   _Y_   ";o+="    _)_";String[]a={"  [___]  ","  /:' \\  "," |::   | "," \\::.  / ","  \\::./  ","   '='   "};for(String b:a)for(j=0;j++<i;)o+=j==1?"\n"+b+" ":j==i?" "+b:b;return o;};

Expanded:

i->
{
    int j=1;
    String o="     .";
    for(;j++<i;)
        o+="--.__.--.";
    o+="\n   _(_    ";
    for(;--j>2;)
        o+="   _Y_   ";
    o+="    _)_";
    String[]a={"  [___]  ","  /:' \\  "," |::   | "," \\::.  / ","  \\::./  ","   '='   "};
    for(String b:a)
        for(j=0;j++<i;)
            o+=j==1?"\n"+b+" ":j==i?" "+b:b;
    return o;
};

Looking into shorter ways to multiply strings, and found that streams are surprisingly more verbose

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ String o=""; + o+=" ."; = String o=" ."; \$\endgroup\$ – manatwork Dec 20 '17 at 18:27
  • \$\begingroup\$ @manatwork Thanks, missed that \$\endgroup\$ – phflack Dec 20 '17 at 18:27
  • 2
    \$\begingroup\$ @phflack I got it down to 290 if you use a lamda expression \$\endgroup\$ – DevelopingDeveloper Dec 20 '17 at 18:43
  • 1
    \$\begingroup\$ @phflack Also, the OP said it just needs to return the String, not print it to the console, so you can drop it down to 279 doing this \$\endgroup\$ – DevelopingDeveloper Dec 20 '17 at 19:13
  • 1
    \$\begingroup\$ @DevelopingDeveloper Cool, I also found a way to golf j=# out of the for loops \$\endgroup\$ – phflack Dec 20 '17 at 19:15
8
\$\begingroup\$

PHP, 276, 307, 303, 301, 293, 283, 280, 278 Bytes

function g($n){$a=["     .--._".r("_.--.--._",$n)."_.--.",r("_(_")." ".r(_Y_,$n)." ".r("_)_")];foreach(explode(9,"[___]9/:' \9|::   |9\::.  /9\::./9'='")as$b)$a[]=r($b)." ".r($b,$n)." ".r($b);return join("\n",$a);}function r($s,$n=3){return str_repeat(str_pad($s,9," ",2),$n-2);}

Readable version for testing:

function g($n){
    $a=[
         "     .--._".r("_.--.--._",$n)."_.--.",
         r("_(_")." ".r(_Y_,$n)." ".r("_)_")
    ];

    foreach(explode(9, "[___]9/:' \9|::   |9\::.  /9\::./9'='") as$b)
         $a[]=r($b)." ".r($b,$n)." ".r($b);

    return join("\n",$a);
}
function r($s,$n=3){
    return str_repeat(str_pad($s,9," ",2),$n-2);
}

Check minified version out here

Check readable version out here

UPDATE

Wrapped it in a function,

\$\endgroup\$
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – Christoph Dec 21 '17 at 7:05
  • 2
    \$\begingroup\$ The old JavaScript tip of using digit as delimiter works fine in PHP too, just that you will have to escape the \ before the separator digit, so will save only 1 char. You can save another 2 chars by making the space characters part of the same bigger string, containing the expression in the middle as expansion: $a[]=$r($b)." {$r($b,$n)} ".$r($b);. \$\endgroup\$ – manatwork Dec 21 '17 at 9:42
  • \$\begingroup\$ @manatwork - thanks for the tip Updated \$\endgroup\$ – ArtisticPhoenix Dec 21 '17 at 18:22
  • 1
    \$\begingroup\$ @manatwork - also if I use a 9 as the delimiter no escaping is needed, probably this works with other numbers just not 0 \$\endgroup\$ – ArtisticPhoenix Dec 21 '17 at 18:29
  • 1
    \$\begingroup\$ And another one is that you could define the $r() lambda function as a regular function r() (could be in the same place, function in function is possible). You do need to fix the string parsing: " {r("")} " won't work. Another -7 bytes ;) \$\endgroup\$ – 7ochem Dec 22 '17 at 13:40
5
\$\begingroup\$

Clean, 305 292 288 275 bytes

import StdEnv
f c=mklines['  _',c,'_  \n [___] \n /:\' \\ \n|::   |\n\\::.  /\n \\::./ \n  \'=\'  ']
@n=flatlines[a++b++c\\a<-[['    .--._']:[e++['  ']\\e<-f'(']]&b<-map(flatten o(repeatn(n-2)))[['_.--.--._']:[[' ':e]++[' ']\\e<-f'Y']]&c<-[['_.--.    ']:[['  ':e]\\e<-f')']]]

Try it online!

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

Python 2 (PyPy), 365 316 315 251 245 bytes

-21 thanks to FlipTack

-43 thanks to ovs

-6 thanks to Mr. Xcoder

v,p=' \n'
a,l,n=".--._",["[___]"," /:' \ ","|::   |","\::.  /"," \::./ ","  '='  "],input()-2
e,b=v*5+"_)_",a[::-1]
r=v*4,a,(b[:4]+a)*n,b,p+"  _(_   ",(v*4+"_Y_  ")*n,e+p+v
for i in l:b=4-2*(i in l[1:]);r+=i+v*-~b,(i+v*b)*n,v+i+p
print''.join(r)

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ -21 bytes \$\endgroup\$ – FlipTack Dec 22 '17 at 23:06
  • 1
    \$\begingroup\$ 245 bytes. \$\endgroup\$ – Mr. Xcoder Dec 29 '17 at 22:22
  • \$\begingroup\$ I think you forgot to update the bytecount after editing in the last suggestion. \$\endgroup\$ – NieDzejkob Jan 22 '18 at 17:19
1
\$\begingroup\$

Kotlin, 261 bytes

{val c="  [___]\n/:' \\\n |::|\n \\::./\n  \\::./\n   '='"
(0..7).map{i->print("     .--._\n   _(_\n$c".lines()[i].padEnd(10))
(0..L-3).map{print("_.--.--._\n   _Y_\n$c".lines()[i].padEnd(9))}
if(i>1)print(' ')
print("_.--.\n    _)_\n$c".lines()[i])
println()}}

Beautified

{
    val c = "  [___]\n  /:' \\\n |::   |\n \\::.  /\n  \\::./\n   '='"

    (0..7).map {i->
        print("     .--._\n   _(_\n$c".lines()[i].padEnd(10))
        (0..L - 3).map {
            print("_.--.--._\n   _Y_\n$c".lines()[i].padEnd(9))
        }
        if (i > 1) print(' ')
        print("_.--.\n    _)_\n$c".lines()[i])
        println()
    }
}

Test

fun f(L: Int)
{val c="  [___]\n/:' \\\n |::|\n \\::./\n  \\::./\n   '='"
(0..7).map{i->print("     .--._\n   _(_\n$c".lines()[i].padEnd(10))
(0..L-3).map{print("_.--.--._\n   _Y_\n$c".lines()[i].padEnd(9))}
if(i>1)print(' ')
print("_.--.\n    _)_\n$c".lines()[i])
println()}}

fun main(args: Array<String>) {
    f(6)
}

TIO

TryItOnline

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

Google Sheets, 190 Bytes

Anonymous worksheet function that take input from range A1 and outputs to the calling cell

="    "&Rept(".--.__.--",A1-1)&".
  _(_    "&Rept("   _Y_   ",A1-2)&"    _)_"&RegexReplace("
 [___]   
 /:' \   
|::   |  
\::.  /  
 \::./   
  '='    
","
(.*)","
$1 "&Rept("$1",A1-2)&" $1
\$\endgroup\$

Your Answer

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

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