Ayúdame con mi decoración de Halloween

13

El Halloween está sobre nosotros, y todavía no he decorado mi casa, así que necesitaré tu ayuda para hacer esta tarea.

Entrada
La entrada será una lista de números de 4 dígitos, donde cada dígito representa una parte de la decoración:

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

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

Boca / Nariz
0 - v
1 - w
2 - o
3 - _
4 --

Decoración inferior
0 - nada
1 - esqueleto
2 - calabaza

Decoración superior
0 - nada
1 - murciélago volador
2 - murciélago en reposo
3 - araña

Salida

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

Calabaza
​ , ​
(EME)

Murciélago volador
​ ​
​ ^"^ ​

Murciélago descansando
​ ​ () ​
​ ​ ´` ​

Araña
​ | ​
​ .|. ​
​ :": ​

  • Cada decoración tiene un ancho de 5 caracteres.
  • Las decoraciones superiores comienzan desde arriba
  • Las decoraciones inferiores comienzan desde abajo
  • Si la araña está sobre la calabaza o no hay decoración de fondo, la longitud de la banda será 3, si está sobre el esqueleto, la longitud de la banda será 1
  • Cuando la decoración del fondo es 0 los primeros 2 dígitos son irrelevantes
  • Entre cada decoración habrá una columna vacía.

Ejemplo de
entrada y
3123 ??02 1021 0310
salida

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

Los espacios finales al final de cada línea son opcionales.
Se permite una nueva línea final al final de toda la salida

Criterio ganador
Este es el por lo que gana la respuesta más corta

varilla
fuente
¿La entrada es siempre válida, entonces no 9999?
Karl Napf
@KarlNapf sí, la entrada siempre será válida
Rod

Respuestas:

4

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"]));

Arnauld
fuente
5

Java, 829 , 798

Si. Mejorado sustancialmente gracias a Kevin Cruijssen y 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);}};

la versión sin golf

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);
    }
}

Decoración favorita (que aparentemente se ve más malvada en mi consola): esqueleto terminador

(-w-) 
 _|_  
/[|]\ 
  |   
 / \
dpa97
fuente
Puede guardar algunos bytes definiendo una lambda en lugar de un método completo
corvus_192
1
Ese "Sí" inicial me hizo reír mucho, no sé por qué.
Urna mágica de pulpo
+1! Algunas cosas que puedes jugar al golf: char[][]c=new char[8][e.length*6];char t,u,h='|';-> char c[][]=new char[8][e.length*6],t,u,h='|';; '-'puede ser45 ; '^'puede ser 94; El espacio se puede eliminar aquí if(f>48) {:; Y estoy seguro de que se puede jugar mucho más al golf, pero es demasiado para ir al golf más complejo. :)
Kevin Cruijssen
Kevin y corvus: gracias, lo intentaré más tarde cuando tenga tiempo. Estoy seguro de que esto se puede caer por debajo de 800, especialmente con una lambda.
dpa97
2

Ruby 2.3.1, 777 752 bytes

Edit_0: me perdí totalmente el uso de variables de golf y otras cosas.

@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

Toma en N número de variables de decoraciones. Ciertamente, se puede hacer más golf con esto. No estoy tan familiarizado con muchos trucos de Ruby, ¡pero aquí hay una oportunidad! También estoy feliz de poder resolverlo.

Sin golf

@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

El seguimiento:

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

Salidas esto:

          ()    |                 ()   .|.                ()    |           ()          |
   ^"^    ´`    |          ^"^    ´`   :":         ^"^    ´`    |           ´`   ^"^    |
               .|.  (¯w¯) (¯w¯) (¯w¯) (¯w¯)                    .|.  (^_^) (^_^)        .|.
               :":   _|_   _|_   _|_   _|_                     :":   _|_   _|_         :":
                    /[|]\ /[|]\ /[|]\ /[|]\                         /[|]\ /[|]\
                      |     |     |     |     ,     ,     ,     ,     |     |     ,     ,
                     / \   / \   / \   / \  (-o-) (-o-) (-o-) (-o-)  / \   / \  (^_^) (^_^)
metrópoli
fuente
1

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)))

Toma entrada como lista de cadenas

-

Ejemplo

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

Salida:

  ()          |     ()                     .|. 
  ´`   ^"^    |     ´`               ^"^   :": 
(¯o¯)        .|.              (¯v¯)       (-w-)
 _|_         :":               _|_         _|_ 
/[|]\                         /[|]\       /[|]\
  |     ,     ,           ,     |           |  
 / \  ('_') (°w°)       (°v°)  / \         / \ 
TFeld
fuente