13
\$\begingroup\$

The Halloween is upon us, and I haven't decorated my house yet, so I gonna need your help to do this task

Input
The input will be a list of 4 digits numbers, where each digit represent a portion of decoration:

EMBU
||||
|||+-upper decoration
||+-bottom decoration
|+-mouth/nose
+-eyes

Eyes:
0 - °
1 - ¯
2 - -
3 - ^
4 - '

Mouth/Nose
0 - v
1 - w
2 - o
3 - _
4 - -

Bottom decoration
0 - nothing
1 - skeleton
2 - pumpkin

Upper decoration
0 - nothing
1 - flying bat
2 - resting bat
3 - spider

Output

Skeleton:
(EME)
​ _|_ ​
/[|]\
​ | ​ ​
​ / \ ​

Pumpkin
​ , ​
(EME)

Flying bat
​ ​
​ ^"^ ​

Resting bat
​ ​ () ​
​ ​ ´` ​

Spider
​ | ​
​ .|. ​
​ :": ​

  • Each decoration has a 5 character width
  • Upper decorations start from the top
  • Lower decorations start from the bottom
  • If the spider is over the pumpkin or there is no bottom decoration the web length will be 3, if it's over the skeleton, the web length will be 1
  • When the bottom decoration is 0 the first 2 digits are irrelevant
  • Between each decoration there will be an empty column

Example
Input
3123 ??02 1021 0310
Output

   |     ()             ​
​   |     ´`   ^"^       ​
​  .|.              (°_°)
​  :":               _|_ ​
​                   /[|]\
​   ,           ,     |  ​
​ (^w^)       (¯v¯)  / \ ​

Trailing spaces at the end of each line are optional
Trailing newline at the end of the entire output is allowed

Winning criteria
This is so the shortest answer wins

\$\endgroup\$
  • \$\begingroup\$ Is input always valid, so no 9999? \$\endgroup\$ – Karl Napf Oct 14 '16 at 1:52
  • \$\begingroup\$ @KarlNapf yes, the input will always be valid \$\endgroup\$ – Rod Oct 14 '16 at 11:52
4
\$\begingroup\$

JavaScript (ES6), 319 315 bytes

let f =

s=>[0,1].map(i=>s.map(([A,B,C,D],x)=>+(z=i?D:C)&&[...'01/21/5015/41211/91/65'.split`/`[z-(i?C+D-13?1:-2:-2)]].map((n,y)=>a[(i?y:6-y)*4+x]=' '+('      ^"^   ()   ´`  / \\   |   .|. /[|]\\ _|_ ('+(e='°¯-^'[A])+'vwo_-'[B]+e+')  ,   :": ').substr(p+=n*5,5),p=0)),a=Array(28).fill`      `)&&a.join``.match(/.{24}/g).join`
`

console.log(f(["3123","0002","1021","0310"]));

\$\endgroup\$
5
\$\begingroup\$

Java, 829, 798

Yeah. Substantially improved thanks to Kevin Cruijssen and corvus_192.

s->{String[]e=s.split(" ");char c[][]=new char[8][e.length*6],t,u,h='|';int y,x=2,i=0,j;for(String l:e){y=0;char[]p=l.toCharArray(),z=c[y];int a=p[0],b=p[1],f=p[2],d=p[3],k=x-1,m=x+1;t=a<49?'°':a<50?'¯':a<51?45:a<52?'^':39;u=(char)(b<50?b+70:b<51?111:b<52?95:39);if(d>50){z[x]=h;if(f!=49){y=2;c[1][x]=h;c[2][x]=h;}z=c[y];z[k]=46;z[m]=46;z=c[++y];z[k]=58;z[m]=58;z[x]=34;}if(d==50){z[x]=40;z[m]=41;c[++y][x]='´';c[y][m]=96;}if(d==49){z=c[++y];z[k]=94;z[x]=34;z[m]=94;}if(f>49){y=6;c[y][x]=44;}if(f>48){y=f>49?7:3;z=c[y++];z[x]=u;z[k]=t;z[m]=t;z[x-2]=40;z[x+2]=41;}if(f==49){z=c[y++];z[x]=h;z[k]=95;z[m]=95;z=c[y];z[x]=h;z[k]=91;z[m]=93;z[x-2]=47;c[y++][x+2]=92;c[y++][x]=h;c[y][k]=47;c[y][m]=92;}x+=6;}for(;i<8;i++){s="";for(j=0;j<c[0].length;){t=c[i][j++];s+=t<1?' ':t;}System.out.println(s);}};

the ungolfed version

static void makeDecorations(String s){
    String[]e=s.split(" ");
    char c[][]=new char[8][e.length*6],t,u,h='|';
    int x=2,i=0,j,y;
    for(String l:e){
        y=0;
        char[]p=l.toCharArray(), z=c[y];
        int a=p[0],b=p[1],f=p[2],d=p[3],k=x-1,m=x+1;
        t=a<49?'°':a<50?'¯':a<51?45:a<52?'^':39;
        u=(char)(b<50?b+70:b<51?111:b<52?95:39);
        if(d>50){z[x]=h;
            if(f!=49){y=2;
                c[1][x]=h;
                c[2][x]=h;
            }
            z=c[y];
            z[k]=46;
            z[m]=46;
            z=c[++y];
            z[k]=58;
            z[m]=58;
            z[x]=34;
        }
        if(d==50){
            z[x]=40;
            z[m]=41;
            c[++y][x]='´';
            c[y][m]=96;
        }

        if(d==49){
            z=c[++y];
            z[k]=94;
            z[x]=34;
            z[m]=94;}
        if(f>49){
            y=6;
            c[y][x]=44;
        }
        if(f>48){
            y=f>49?7:3;
            z=c[y++];
            z[x]=u;
            z[k]=t;
            z[m]=t;
            z[x-2]=40;
            z[x+2]=41;
        }
        if(f==49){
            z=c[y++];
            z[x]=h;
            z[k]=95;
            z[m]=95;
            z=c[y];
            z[x]=h;
            z[k]=91;
            z[m]=93;
            z[x-2]=47;
            c[y++][x+2]=92;
            c[y++][x]=h;
            c[y][k]=47;
            c[y][m]=92;
        }
        x+=6;
    }
    for(;i<8;i++){
        s="";
        for(j=0;j<c[0].length;){
            t=c[i][j++];s+=t<1?32:t;
        }
        System.out.println(s);
    }
}

Favorite decoration (which apparently looks more evil in my console): terminator skeleton

(-w-) 
 _|_  
/[|]\ 
  |   
 / \
\$\endgroup\$
  • \$\begingroup\$ You can save some bytes by defining a lambda instead of a full method \$\endgroup\$ – corvus_192 Oct 13 '16 at 18:38
  • 1
    \$\begingroup\$ That initial "Yeah" made me laugh hard, I don't know why. \$\endgroup\$ – Magic Octopus Urn Oct 13 '16 at 19:12
  • \$\begingroup\$ +1! Some things you can golf: char[][]c=new char[8][e.length*6];char t,u,h='|'; -> char c[][]=new char[8][e.length*6],t,u,h='|';; '-' can be 45; '^' can be 94; The space can be removed here: if(f>48) {; And I'm sure a lot more can be golfed, but it's a bit too much to go into more complex golfing. :) \$\endgroup\$ – Kevin Cruijssen Oct 14 '16 at 9:34
  • \$\begingroup\$ Kevin and corvus: thanks, I'll take another go at it later when I have the time. I'm sure this can be dropped under 800, especially with a lambda. \$\endgroup\$ – dpa97 Oct 14 '16 at 13:55
2
\$\begingroup\$

Ruby 2.3.1, 777 752 bytes

Edit_0: I totally missed out on some golfable variable usage and some other stuff.

@o=Array.new;$*.each_with_index do|j,i|a,e,n,b,u,q,r,z,y=0,j[0].to_i,j[1].to_i,j[2].to_i,j[3].to_i,['°','¯','-','^',"'"],['v','w','o','_',"-"],Array.new(7," "),"     ";g,h=[z,["(#{q[e]}#{r[n]}#{q[e]})","​ _|_ ​","/[|]\\","​  | ​ ​","​ / \\ ​"],["     ","​  ,  ","(#{q[e]}#{r[n]}#{q[e]})"]],[z,["​     ​","​ ^\"^ ​"],["​ ​ () ", "​ ​ ´` "],["​ .|. ​","​ :\": ​"]];2.times{h[3].unshift("  |  ​")}unless b==1;if b<1 && u<1;@o.push(z);elsif b<1;u<3 ? (a=5):(a=3);a.times{h[u].push(y)};@o.push(h[u]);elsif u<1;b==1 ? (a=2):(a=4);a.times{g[b].unshift(y)};@o.push(g[b]);elsif u>0;2.times{h[u].push(y)}if u<3&&b>1;@o.push(h[u]+g[b]);end;@o.push(z);end;@o.transpose.each do|v|;v.each do |w|;print w;end;print"\n";end

Takes in N number of variables of decorations. There's certainly some more golfing that can be done with this. I'm not that familiar with a lot of Ruby's tricks, but here's a shot at it! I'm also happy at being able to solve it.

Un-golfed

@output = Array.new
$*.each_with_index do |j, i|
  # output decoration combo
  s = 0

  # set up vars for decoration input
  e = j[0].to_i
  n = j[1].to_i
  b = j[2].to_i
  u = j[3].to_i

  # Setup decorations/misc
  eyes = ['°','¯','-','^',"'"]
  nose = ['v','w','o','_',"-"]
  nothing = Array.new(7, " ")
  skeleton = ["(#{eyes[e]}#{nose[n]}#{eyes[e]})", "​ _|_ ​", "/[|]\\", "​  | ​ ​", "​ / \\ ​"]
  pumpkin = ["     ", "​  ,  ", "(#{eyes[e]}#{nose[n]}#{eyes[e]})"]
  fbat = ["​     ​", "​ ^\"^ ​"]
  rbat = ["​ ​ () ", "​ ​ ´` "]
  spider = ["​  |  ​", "​ .|. ​", "​ :\": ​"]
  spider.unshift("  |  ​") unless b == 1
  a = "     "
  bot = [nothing, skeleton, pumpkin]
  top = [nothing, fbat, rbat, spider]

  # if bottom and upper are empty
  if b < 1 && u < 1
    @output.push(nothing)
  # if bottom is empty
  elsif b < 1
    u < 2 ? (s = 3) : (s = 5)
    s.times {top[u].push(a)}
    @output.push(top[u])
  # if upper is empty
  elsif u < 1
    # put in white space before the decorations
    b == 1 ? (s = 2) : (s = 5)
    s.times {bot[b].unshift(a)}
    @output.push(bot[b])
  # if there's an upper decoration
  elsif u > 0
    # put in the top deco
    2.times {top[u].push(a)} if u < 3 && b > 1
    @output.push(top[u] + bot[b])
  end
  # Input the empty column
  @output.push(nothing)
end

# Transpose the array of arrays so that
# instead of outputting each line of a single each decoration
# what's output is each line of each decoration.
# Example:
# [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]
# [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4], [5, 5, 5, 5, 5]]
@output.transpose.each do |data|
   data.each do |data1|
     print data1
   end
   print "\n"
end

The following:

ruby deco_g.rb 0000 0001 0002 0003 1110 1111 1112 1113 2220 2221 2222 2223 3310 3312 3321 3323

Outputs this:

          ()    |                 ()   .|.                ()    |           ()          |
   ^"^    ´`    |          ^"^    ´`   :":         ^"^    ´`    |           ´`   ^"^    |
               .|.  (¯w¯) (¯w¯) (¯w¯) (¯w¯)                    .|.  (^_^) (^_^)        .|.
               :":   _|_   _|_   _|_   _|_                     :":   _|_   _|_         :":
                    /[|]\ /[|]\ /[|]\ /[|]\                         /[|]\ /[|]\
                      |     |     |     |     ,     ,     ,     ,     |     |     ,     ,
                     / \   / \   / \   / \  (-o-) (-o-) (-o-) (-o-)  / \   / \  (^_^) (^_^)
\$\endgroup\$
1
\$\begingroup\$

Python 2, 331 bytes""

B,I,l,s=' '*5,'  |  ',' .|. ',' :": '
r=[]
for x in inputtt:m,n,b,u=(int(y)for y in x);e="°¯-^'"[m];H='('+e+"vwo_-"[n]+e+')';r+=[[[B,B,'  () ',[I,l,I][b]][u],[B,' ^"^ ','  ´` ',[I,s,I][b]][u],[[B,l][u==3],H][b==1],[[B,s][u==3],' _|_ '][b==1]]+[[B]*3,['/[|]\\',I,' / \ ',],[B,'  ,  ',H]][b]]
print'\n'.join(map(' '.join,zip(*r)))

Takes input as list of strings

-

Example

Input: ["1212","4321","0123","1102","0020","1010","0101","2113"]

Output:

  ()          |     ()                     .|. 
  ´`   ^"^    |     ´`               ^"^   :": 
(¯o¯)        .|.              (¯v¯)       (-w-)
 _|_         :":               _|_         _|_ 
/[|]\                         /[|]\       /[|]\
  |     ,     ,           ,     |           |  
 / \  ('_') (°w°)       (°v°)  / \         / \ 
\$\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.