Excavación de cantera timelapse

11

¿Te encanta ver increíbles timelapses de construcciones u otro trabajo masivo realizado en minutos? Hagamos uno aquí.
Observaremos una cantera excavadora, haciendo fotos todos los días para ver el progreso completo. ¡Y su tarea es mostrarnos este proceso!

Cantera se define por el ancho de su primera capa.
La excavadora se define por su capacidad para excavar en un día.

Entrada

Ancho de cantera. Número entero, siempre> = 1.
Velocidad de excavación del excavador. Número entero, siempre> = 1.

Salida

Progreso de la excavación de cantera en cada día. Comenzó con terreno plano sin tocar y terminó con cantera completa.

Reglas

  • El último día puede haber menos unidades para excavar de las que es capaz la excavadora. El trabajo excesivo no se utilizará en ninguna parte, por lo que solo debe generar una cantera totalmente excavada.

  • Todos los días el progreso debe estar presente en la salida a la vez. No puede borrar ni sobrescribir el progreso del día anterior en la salida.

  • Las nuevas líneas finales y principales para cada salida diaria son aceptables en cualquier número razonable.

  • Este es el , así que haga su código lo más compacto posible.

Aclaraciones

El trabajo comienza con un terreno plano. La longitud del terreno visualizado es el ancho de la cantera + 2. Por lo tanto, siempre habrá un carácter de subrayado en ambos lados de la cantera.

__________

La cantera excavada se ve así para un ancho uniforme:

_        _      
 \      /
  \    /
   \  /
    \/

Y así para ancho extraño

_       _      
 \     /
  \   /
   \ /
    V

Aquí hay ejemplos de progreso en canteras:

_ _______
 V          dug 1 unit

_  ______
 \/         dug 2 units

_     ___
 \___/      dug 5 units


_       _
 \   __/    dug 10 units
  \_/

Ejemplo de progreso completo. Ancho de cantera: 8. Velocidad de excavadora: 4 unidades por día.

__________

_    _____
 \__/

_        _
 \______/

_        _
 \    __/
  \__/

_        _
 \      /
  \  __/
   \/

_        _
 \      /
  \    /
   \  /
    \/

Cajas de esquina

El excavador necesitará excavar el último día exactamente su capacidad (velocidad)

Width: 7, Speed: 3
Width: 10, Speed: 4 
Zarigüeya muerta
fuente

Respuestas:

1

Stax , 65 bytes

Θ└R4∞√4Fµ■zJ┐╚▌▼ZJ╧fφ½à╘▲☼å♥s≥┤ÖòOúU╬ΩmPê|ë↕ƒ].Y┴↓á÷>}St☺┐B╒╞O☼╧O

Ejecutar y depurarlo

Si primero calcula los caracteres de excavación, en una cadena plana. Luego agrega profundidad. Por ejemplo, "_V___"es un día de excavación, y "_\V/_"es la cadena plana completa.

Utiliza este método para hacer una unidad de excavación.

  1. Comience con un solo "\", más el número apropiado de caracteres "_".
  2. Si "V_" está en la cadena, reemplácelo con "/".
  3. De lo contrario, si "/ _" está en la cadena, reemplácelo con "_ /".
  4. De lo contrario, si "\ _" está en la cadena, reemplácelo con "\ V".
  5. La nueva cadena es el resultado de una unidad de excavación. Repita desde el paso 2.

Aquí está todo el programa desempaquetado, sin golf y comentado.

'_*'\s+                 initial string e.g. "\_______"
{                       generator block to get each day's flat digging results
  {                     block to repeat digging within each day
    "V_\//__/\_\V"4/    replacement strings
    {[2:/|em|!H         find the first substring that exists and do replacement
  };*                   repeat digging within day specified number of times
gu                      get all unique results
                            when digging is complete, the result duplicates
{Dm                     drop the leading "\" characters from each result
F                       for each day's flat result, execute the rest of the program
  '_|S                  surround with "_"
  M                     split into chars; e.g. ["_", "\", "/", "_"]
  c|[                   copy and get all prefixes
  {                     mapping block to get "depth" of each character
    '\#                 get number of backslashes in this prefix (A)
    _1T'/#-             get number of forward slashes prior to last character of prefix (B)
    'V_H=+^             is the current character "V"? 1 for yes. (C)
  m                     map prefixes to A - B + C + 1
  \                     zip depths with original characters
  {E)m                  prefix each character with spaces; e.g. ["_", " \", " /", "_"]
  M                     transpose grid; e.g. ["_  _", " \/ "]
  m                     print each row

Ejecutar y depurarlo

recursivo
fuente
¡Buen trabajo! Esperando explicación: D
Dead Possum
@DeadPossum: ¡Solo tenías que esperar una semana!
recursivo el
3

Retina 0.8.2 , 163 156 bytes

.+
$*_
(_+)¶(_+)
$2¶$1¶$1
r`__\G
$%`$&
¶
;
(?<=(_+);.*)(?<=;_+;\1*)_
¶$`_
m`^_+;
__
+`(>*)_(_+)(_+<?;)\2
$1_$.2$* $3¶$1>$2<;
T`>\_` \\`>+_
T`\\\_;<`V/_`.<|;

Pruébalo en línea! Explicación:

.+
$*_

Convierta las entradas a unario. Esto nos da W¶S.

(_+)¶(_+)
$2¶$1¶$1

Intercambie las entradas y duplique el ancho. Esto nos da S¶W¶W.

r`__\G
$%`$&

Calcule el volumen de la cantera. Esto nos da S¶W¶V.

¶
;

Une las entradas en una línea. Esto nos da S;W;V.

(?<=(_+);.*)(?<=;_+;\1*)_
¶$`_

Calcule la cantidad de progreso para cada día en su propia línea. Cada día tiene el formato S;W;D, donde Destá 0en la primera línea y se incrementa Scada día hasta que llega V.

m`^_+;
__

Eliminar Sy aumentar Wen 2 en cada línea. Esto nos da G;Dpara cada día.

+`(>*)_(_+)(_+<?;)\2
$1_$.2$* $3¶$1>$2<;

Mientras Dno sea cero, excave una línea Do G-2la siguiente (de modo que el primer y el último carácter siempre queden), moviendo la profundidad a la siguiente línea. Cada línea está sangrada con una más >que la anterior. Las líneas recién excavadas también incluyen a <.

T`>\_` \\`>+_

Convierta la sangría en espacios y lo siguiente _en a \.

T`\\\_;<`V/_`.<|;

Si a <está siguiendo a \, conviértalo en a V, si está siguiendo a _, conviértalo en a /. Eliminar todos los <sy ;s.

Neil
fuente
La retina me sorprende por alguna razón ._. ¡Buen trabajo!
Dead Possum
1

Python 2 , 265 bytes

w,s=input();R=range((3+w)/2)
d=0
while d-s<sum(range(w%2,w+1,2)):
 q=[[' _'[i<1]]*(w+2)for i in R];D=d
 for i in R[:-1]:
  a=min(D,w-i*2);D-=a
  if a:q[i][1+i:1+i+a]=[' ']*a;q[i+1][1+i:1+i+a]=(['\\']+['_']*(a-2)+['/'])*(a>1)or['v']
 for l in q:print''.join(l)
 d+=s

Pruébalo en línea!

TFeld
fuente
2x 1+i+aa i-~a.
Kevin Cruijssen
sum(range(0,w+1,2))puede serw/2*(w/2+1)
ovs
Los @ovs tposiblemente también pueden estar en línea, lo que resulta en 257 bytes .
Jonathan Frech
@DeadPossum Corregido
TFeld
@TFeld ¡Buen trabajo!
Dead Possum
1
  • golf en progreso

JavaScript (Node.js) , 329 315 307 300 301 298 285 275 260 254 bytes

  • solución fija dúo de error en w impar (gracias a @Shaggy) + reducir en 2 bytes
  • gracias a @Herman Lauenstein por reducir en 1 byte
(w,s)=>{h=[...Array(-~w/2+1|0)].map((x,i)=>[...(i?" ":"_").repeat(w)])
for(t=S="";t<s&&h.map((x,i)=>S+=(p=i?" ":"_")+x.join``+p+`
`);)for(y in t=s,h)for(x in D=h[y])if(D[x]=="_"&&t){(d=h[-~y])[x]=x^y?(d[x-1]=x^-~y?"_":"\\","/"):"v"
D[x]=" "
t--}return S}

Pruébalo en línea!

Explicación

(w,s)=>{
h=[...Array(-~w/2+1|0)]                       //the height of the quarry when finished is w/2+1 if even or (w+1)/2+1 if odd
.map((x,i)=>                                  
    [...(i?" ":"_").repeat(w)]                //the first row is the _ w times (i will explain why w and not w+2 in the following lines) afterwards lets just fill with spaces so the output would be clear(when convertion to string)
    )                                         
for(t=S="";                                   //t="" is like t=0(we actually need t to be different from s in the start and s>=1), S will hold the final output
t^s&&                                         //if t not equals s -> it means that now changes were made to the quarry->it means we finished digging
h.map((x,i)=>                                 
S+=(p=i?" ":"_")+x.join``+p+`                 //here comes the reason for w and not w+2. because the border _XXXX_ are not to be touched i only add them to the output and not woking with them in the solution
                                              //that ways its much easier to replace the correct chars. so here i just add _ to either sides if its the first row otherwise space(to pad correctly).
                                              //in the end i add a new line to differ from the previous day
`);)
    for(y in t=s,h)                           //always update t back to s so we know weve passed a day
        for(x in D=h[y])
            if(D[x]=="_"&&t)                  //if the current cell is _ we need to work, but only if the day have yet to pass(t)
            {
                (d=h[-~y])[x]=                //updating the row below us because we just dug a hole
                x^y?                          //if x == y that means we are digging the first hole in the row below
                (d[x-1]=x^-~y?"_":"\\", //we want to update the row below and cell before([y+1][x-1]) only if its not the first cell(AKA not space). if v we need \ other wise _
                    "/")                          //other wise (x!=y) we put "/"
                :"v"                          //so we should put v (if they are equal)
                D[x]=" "                      //always remove the _ from the current one because we dug it
                t--}                          //decrement the counter for the day by one digging
return S}
DanielIndie
fuente
No funciona si wes extraño.
Shaggy
@Shaggy corregido :)
DanielIndie
@HermanLauenstein, ¿podrías ser más específico?
DanielIndie
No necesita contar la asignación de variable ( f=) y puede guardar otro byte al cursar los parámetros ( w=>s=>).
Shaggy
@DeadPossum parece funcionar para 7,3 ¿estás seguro? ¿podría poner la salida esperada?
DanielIndie