Cuentas ASCII básicas


36

Título alternativo: Cuenta tu sentencia de prisión en el muro

Dado un número n, los resultados obtenidos se agrupan en el tradicional 5 por grupo y 50 por fila.


Ejemplos

1

|
|
|
|

4 4

||||
||||
||||
||||

5 5

|||/
||/|
|/||
/|||

6 6

|||/ |
||/| |
|/|| |
/||| |

50

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

51

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|
|
|
|

256

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |
||/| |
|/|| |
/||| |

Reglas

  • 5 tantos por grupo, 50 totales por fila.
  • Los primeros 4 recuentos son verticales, el quinto recuento cruza todos los otros recuentos.
    • Cada uno de los primeros cuatro consta de 4 |caracteres verticales .
    • La quinta cuenta final abarca los 4 primeros, con un /personaje, en diagonal.
  • Cada grupo debe estar separado por un espacio, cada fila una nueva línea en blanco.
  • Las restricciones nson: 0 <= n <= 1000(por simplicidad).
  • Los espacios finales y las nuevas líneas están bien, los anteriores no.
  • Este es el , el menor recuento de bytes gana.

Revisado por ~ 4 personas en el sandbox .


PS divertido poco tid-bit, el número promedio de recuentos por fila en prisión fue de 50, de ahí la alt. título.



Gran desafío, complejo pero simple.
ATaco

@ATaco Realmente quiero encontrar la solución que agregue las barras en el "panorama general", y tenga en cuenta que el patrón de barra se puede inferir por fila (esa es la victoria fácil).
Urna de pulpo mágico

2
Gracias tanto por hacerlos barras inclinadas en lugar de barras invertidas.
Totalmente humano el

1
@totallyhuman Oh, Dios, el tipo de la imagen que publiqué lo hace ... ¿QUÉ UNIVERSO ES ESTO? Son los osos Bernstein de nuevo ... ¿La moneda cayó en cara o cruz para decidir las elecciones más recientes de los Estados Unidos?
Urna mágica del pulpo

Respuestas:


11

Carbón , 30 25 bytes

FN«J﹪ι⁵⁰×⁵÷ι⁵⁰¿﹪⊕ι⁵↓⁴«←↙⁴

Pruébalo en línea! El enlace es a la versión detallada del código. Explicación:

 N                          Input number
F «                         Loop over implicit range
     ι     ι                Loop index
      ⁵⁰    ⁵⁰              Literal 50
    ﹪                       Modulo
          ÷                 Integer divide
         ⁵                  Literal 5
        ×                   Multiply
   J                        Jump to column, row
                 ι          Loop index
                ⊕           Incremented
                  ⁵         Literal 5
               ﹪            Modulo
              ¿             If
                   ↓⁴       Print 4 `|`s downwards
                     «      Implicit else
                      ←     Move left
                       ↙⁴   Print 4 `/`s down and left

6

Funky , 156 132 133 bytes

n=>{k=n=>((l="|"::rep)(3-i)+"/"+l(i)+" ")::rep(n)p=print L=f=>fori=0i<4i++p(f())forc=0c<n//50c++{L@k(10);p()}L@k((m=n%50)//5)+l(m%5)}

Pruébalo en línea!


1
Funky es un ... ¿Y ahora qué? Interesante. Nunca he visto este lenguaje en ninguno de mis desafíos antes.
Urna de pulpo mágico

1
@MagicOctopusUrn Probablemente porque lo escribí: P
ATaco

1
¿Un lenguaje basado en JavaScript? Peligroso. Pero está bien, me encanta el peligro.
Urna mágica de pulpo

1
fori=0i<4i++p(f())forc=0c<n//50c++¿Qué es esta bestia impía que toma el nombre de sintaxis
Totalmente humano

1
@totallyhuman "Es como si
ATaco


5

Jalea , 37 bytes

:5[“|||/”]ẋ;”|ẋ⁸%5¤¤W¤ṙ€4Ḷ¤s⁵Z€G€j⁾¶¶

Pruébalo en línea!

Explicación

:5[“|||/”]ẋ;”|ẋ⁸%5¤¤W¤ṙ€4Ḷ¤s⁵Z€G€j⁾¶¶  Main Link
:5                                     Floordiv by 5
  [“|||/”]ẋ                            Repeat ["|||/"] by this number
           ;                           Append
            ”|ẋ    ¤                   "|" repeated by
               ⁸%5¤                    The argument modulo 5
                    W¤                 Then wrapped to prevent weirdness
                      ṙ€               Rotate each tally segment by
                        4Ḷ¤            (each) [0, 1, 2, 3]
                           s⁵          Slice into pieces of length 10 (to get 50 per row)
                             Z€        Transpose each
                               G€      Convert each into a grid
                                 j⁾¶¶  Join these grids by a double newline

si esto es demasiado largo


@FrownyFrog arreglado, gracias!
HyperNeutrino

4

Casco , 29 bytes

J;øṀṪṙŀ4C10§:oR"|||/"÷5oR'|%5

Pruébalo en línea!

Siento que el primero 5es redundante, pero eliminarlo da un error de tipo ...

Explicación

J;øṀṪṙŀ4C10§:oR"|||/"÷5oR'|%5  Implicit input, an integer n.
                       oR'|    Repeat the character '|'
                           %5  n mod 5 times.
             oR"|||/"          Repeat the string "|||/"
                     ÷5        n/5 times.
           §:                  Tack the '|'-string to the end of that list.
        C10                    Cut the list of strings into pieces of length 10.
   Ṁ                           For each piece,
    Ṫ ŀ4                       for each k in [0,1,2,3],
     ṙ                         rotate each string k steps to the left
                               and collect the results into a list.
                               Now we have a list of lists of lists of strings.
J;ø                            Join them with the list [[]].
                               Implicitly join each list of strings by spaces,
                               then join the resulting list of strings by newlines,
                               and print the result.

4

SOGL V0.12 , 33 bytes

ā.{┐4∙F5\?X1w⁄3-14╚╬5@}┼FM»\?O¶oā

Pruébalo aquí!

Jugar al golf en un teléfono es difícil ...

Explicación:

ā                                  push an empty array
 .{                                repeat input times
   ┐4∙                               push a 4 tall line
      F5\?            }              if the counter (1-indexed) divides by 5
          X                            pop that vertical line
           1w⁄                         get the width of the main array
              3-                       subtract 3 from that width - X position
                1                      push 1 - Y position
                 4╚                    push a 4 long diagonal
                   ╬5                  place that in the main array at [width-3; 1]
                     @                 push a space - for the below to add spacing
                       ┼             append horizontally
                        FM»\?        if the counter divides by 50
                             O         output the main array
                              ¶o       output a newline
                                ā      push a new array
                                       (note that the outputting here doesn't disable
                                       implicit outputting)

4

JavaScript (ES6), 139 137 bytes

n=>eval('s="";for(i=0;i++<=n/50;s+=N)for(j=5;--j;s+=N=`\n`)for(k=0;k<(x=(y=n-i*50)<0?50+y:50);)s+=++k%5?k%5-j|k>5*(x/5|0)?"|":"/":" ";s')

Devuelve una cadena con una nueva línea final cuando nno es un múltiplo de 50 y una con varias líneas nuevas cuando n es un múltiplo de 50.

Sin golf

n=>{
    s=""
    for(i=0; i++ <= n/50; s+=N)
        for(j=5; --j; s+=N=`\n`)
            for(k=0; k < (x = (y = n-i*50) < 0 ? 50+y : 50);)
                s += ++k%5 ?
                    k%5-j|k>5*(x/5|0) ?
                        "|"
                    : "/"
                : " "
    return s
}

Fragmento de prueba

Sin evalsolución, 150 bytes

n=>(A=(v,m)=>j=>[...Array(v).keys()].map(m).join(j))(n/50+1|0,i=>A(4,j=>A(x=(y=n+~i*50)<0?50+y:50,k=>++k%5?k%5-4+j|k>5*(x/5|0)?"|":"/":" ")``)`
`)`

`

Posiblemente capaz de jugar más golf, pero el evalmétodo ha sido más corto hasta ahora.


Me tomó unos 10 minutos sólidos para trabajar en la versión sin golf y entenderla. = ^ P Tienes algunos buenos trucos allí.
DLosc

bastante seguro de que puede hacer para (i = 0; ++ i <n / 50; s + = N) que ahorra un personaje
DanielIndie

@DanielIndie Eso falla porque el bucle externo se ejecuta muy pocas veces: ¡ Pruébelo en línea!
Justin Mariner el

4

J , 50 48 45 35 33 bytes

_50|:\'|/ '{~[{.(|.2,=i.4)$~]-5|]

Pruébalo en línea!

                (    =i.4)          Identity matrix of size 4.
                (  2,    )          Prepend a row of 2s.
                (|.      )          Upside down.
                          $~        Take __ rows.
                            ]-5|]   Input rounded down to a multiple of 5.
             [{.                    Pad with rows of zeroes to [input] rows.
      '|/ '{~                       Get the characters.
_50|:\                              Transpose and fit to width.

Me encanta la idea de usar infijos para esta parte4,&' '\7$'|||/'
Jonás

@Jonah tenía que irse :(
FrownyFrog

3

C (gcc), 170 bytes

char*s="|||/ \0||/| \0|/|| \0/||| \0";h;k;g(x){for(h=0;h<5;h++){for(k=x;k>4;k-=5)printf(s+6*h);for(;k&&h-4;k--)printf("|");putchar(10);}}f(x){for(;x>49;x-=50)g(50);g(x);}

Pruébalo en línea!

f es una función que toma un número entero no negativo (x ) e imprime tantos recuentos, agrupados como se especifica, para stdout

ges una función auxiliar que imprime los xrecuentos, agrupados por 5, sin dividir líneas.

fllamadas g(50)y decrementos xpor 50 hasta que sea inferior a 50, luego llama g(x)para imprimir los recuentos restantes en una línea.

ses char*tal que, como cadenas, ses la primera fila de un paquete, s+6es la segunda, s+12es la tercera y s+18es la cuarta, y s+24es una cadena vacía.

g(x)imprime paquetes y disminuye x por 5 hasta que x sea menor que 5, luego imprime xrecuentos individuales.



2

Python 2 , 142 bytes

n=input()
while n>0:print"\n".join("".join("|/ "[2*(j%5>3)+(n/(5*(j/5+1))and 3-i==j%5)]for j in range(min(50,n)))for i in range(4)),"\n";n-=50

Pruébalo en línea!


1
142 bytes en 18 minutos? No está mal :).
Urna mágica de pulpo

3
Me puse a trabajar rápido cuando realmente deberías haberte acostado hace una hora
Halvard Hummel

Quick ~= Quality;). Buen trabajo.
Urna mágica del pulpo

3
Errr ... eso puede ser mal interpretado. Decir que hizo un trabajo de calidad rápido ... No es lo contrario.
Urna mágica de pulpo




2

PHP, 138 141 + 1 bytes

probablemente no sea la solución más corta posible

for(;0<$z=50+min($n=$x=$y=0,$argn-=50);print"
")while($n++<$z||!$x=+(3<$y+=$n=print"
"))echo"/| "[$n%5?($y+$x++)%4<3|$n%5+$y<4|$z-$z%5<$n:2];

Ejecutar como tubería -nRo probarlo en línea .


¡Ordenado! Pero desde la segunda línea de conteo en el conteo no se cruzan por completo.
SpazzMarticus

Cuando ejecute su ejemplo "pruébelo en línea" desde 5.5 en adelante, localmente 5.6.31 y 7.1.9.
SpazzMarticus

1
$xsolo está indefinido en el primer bucle, esto desordena la salida para un conteo mayor a 54. Corregido, pero no golfizado: sandbox.onlinephpfunctions.com/code/…
SpazzMarticus

@SpazzMarticus solucionado
Titus

¡Guay! Era la primera vez que depuraba el código de golf, ¡me lo pasaste mal! :) Creo que estoy enganchado!
SpazzMarticus

2

Pitón, 129 129 113 112 bytes

f=lambda n:n>50and f(50)+"\n\n"+f(n-50)or"\n".join(("|||/|||"[k:k+4]+" ")*(n//5)+" "+"|"*(n%5)for k in range(4))

Explicación

def p(n):
  if n > 50:
    return p(50) + "\n\n" + p(n-50) # Handle 50-groups recursively
  else:
    # For each of the 4 lines:
    rows = []
    for row in range(4):
      #  - Build the "|||/"-blocks by slicing the correct part of "|||/|||".
      #  - Do that n/5 times
      #  - Then add "|" n%5 times
      rows += [("|||/|||"[row:row+4]+" ")*(n//5) + " " + "|"*(n%5)]

    # Join the four rows together
    return "\n".join(rows)

Funciona en Python 2 y 3.

Pruébalo en línea



1

Ruby , 100 bytes

->n{(n/-50*-4).times{|i|j=[n-i/4*50,50].min
$><<("|||/|||"[i%4,4]+" ")*(j/5)+?|*(j%5)+$/*(1+i%4/3)}}

Comentado

->n{(n/-50*-4).times{|i|              #Calculate rows of tallies (Ruby rounds division towards negative infinity. Multiply by 4 lines per tally and iterate through them.)
  j=[n-i/4*50,50].min                 #Number of strokes printed in current row is either the number remaining, or 50, whichever is less
    $><<("|||/|||"[i%4,4]+" ")*(j/5)+ #Send to stdout the correct 4 chars selected from "|||/|||" plus a space, j/5 times (rounded down, which eliminates odd strokes.) 
    ?|*(j%5)+                         #If there are any odd strokes, add them to the output
    $/*(1+i%4/3)                      #followed by a newline (2 for the final line of each row of tallies.)
  }
}

Pruébalo en línea!


1

Pip , 47 46 bytes

Wa-:yP('|X4.sRA3-_'/M,4)X(YMN[a50])/5.'|Xy%5.n

Pruébalo en línea!

Explicación

        Implicit: a is 1st cmdline arg, y is "", s is space, n is newline
W       While loop:
 a-:y   Each iteration, subtract y from a and check if a is still nonzero
        (Since "" is 0 in numeric contexts, this does nothing the first time through)
     P  Print the following:

('|X4.sRA3-_'/M,4)X(YMN[a50])/5.'|Xy%5.n
              M                           Map this function to each number in
               ,4                         range(4):
 '|X4                                      String of four pipe characters
     .s                                    Concatenate a space
       RA                                  Replace the character at index
         3-_                                (3 minus function argument)
            '/                              with forward slash

                                          We now have a list of four strings representing
                                           the rows of a group of 5 tally marks; the
                                           following operations apply to the list
                                           element-wise:

                       [a50]              List of a (number of remaining tallies) and 50
                     MN                   Get the min (number of tallies on this row)
                    Y                     Yank it into y
                   (        )/5           Divide by 5 (number of groups on this row)
(                )X                       String-multiply by that amount
                                   y%5    Number of leftover tallies on this row
                                '|X       String-multiply that many pipes
                               .          Concatenate
                                      .n  Concatenate a newline

La lista resultante será algo como esto:

["|||/ ||\n" "||/| ||\n" "|/|| ||\n" "/||| ||\n"]

Por defecto, Pconcatena los contenidos de la lista y los genera con una nueva línea final. Por lo tanto, obtenemos

|||/ ||
||/| ||
|/|| ||
/||| ||

con dos nuevas líneas finales (una del contenido de la lista y otra agregada por P). Si hay otra fila para imprimir, esto proporciona la línea en blanco necesaria en el medio.




0

05AB1E , 28 bytes

5‰"|||/"¬‚×J4ôTôεε3Ý._}ø»¶«,

Pruébalo en línea.

Explicación:

5              # Divmod the (implicit) input-integer by 5
                #  i.e. 111 → [22,1]
  "|||/"        # Push string "|||/"
        ¬       # Push its first character (without popping the string itself): "|"
               # Pair them together: ["|||/","|"]
          ×     # Repeat it based on the divmod
                #  i.e. [22,1] → ["|||/|||/|||/...|||/|||/|||/","|"]
           J    # Join everything together to a single string
                #  → "|||/|||/|||/...|||/|||/|||/|"
            4ô  # Which is then split into block of size 4
                #  → ["|||/","|||/","|||/",...,"|||/","|||/","|||/","|"]
Tô              # Then split this list into sublists of size 10
                #  → ["|||/","|||/","|||/",...],[...,"|||/"],["|||/","|||/","|"]]
  ε             # For-each over the sublists:
   ε            #  Map over the strings in the sublist:
    3Ý          #   Push list [0,1,2,3]
      ._        #   For each: rotate the string that many times
                #    ("|||/" → ["|||/","||/|","|/||","/|||"])
              #  After the map: zip/transpose; swapping rows/columns
     »          #  Join each inner list by spaces, and then the strings by newlines
      ¶«        #  Append a newline to each string
        ,       #  And print with trailing newline

¶«,Por supuesto, tiene algunas alternativas posibles de bytes iguales, como ,¶?o ,õ,.



Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.