Timelapse di scavo di cava


11

Ti piace guardare fantastici timelapse di costruzioni o altri lavori di massa eseguiti in pochi minuti? Facciamo uno qui.
Guarderemo un escavatore scavare cava, fare foto ogni giorno per vedere tutti i progressi. E il tuo compito è mostrarci questo processo!

La cava è definita dalla larghezza del suo primo strato.
L'escavatore è definito dalla sua capacità di scavare in un giorno.

Ingresso

Larghezza della cava. Numero intero, sempre> = 1.
Velocità di scavo dell'escavatore. Numero intero, sempre> = 1.

Produzione

Progressi di scavare cava ogni giorno. Iniziato con un terreno piatto incontaminato e terminato con cava completata.

Regole

  • L'ultimo giorno potrebbero esserci meno unità da scavare, di quelle che l'escavatore è in grado di fare. Il lavoro eccessivo non verrà utilizzato da nessuna parte, quindi dovresti solo produrre cava completamente scavata.

  • Tutti i giorni di avanzamento devono essere presenti nell'output contemporaneamente. Non è possibile cancellare o sovrascrivere i progressi del giorno precedente nell'output.

  • Le righe finali e iniziali nuove per ogni giorno sono accettabili in qualsiasi numero ragionevole.

  • Questo è , quindi rendi il tuo codice il più compatto possibile.

chiarimenti

Il lavoro inizia con un terreno pianeggiante. La lunghezza del terreno visualizzato è la larghezza della cava + 2. Quindi ci sarà sempre un carattere di sottolineatura su entrambi i lati della cava.

__________

La cava scavata si presenta così per una larghezza uniforme:

_        _      
 \      /
  \    /
   \  /
    \/

E così per larghezza dispari

_       _      
 \     /
  \   /
   \ /
    V

Ecco alcuni esempi di avanzamento della cava:

_ _______
 V          dug 1 unit

_  ______
 \/         dug 2 units

_     ___
 \___/      dug 5 units


_       _
 \   __/    dug 10 units
  \_/

Esempio di avanzamento completo. Larghezza della cava: 8. Velocità dell'escavatore: 4 unità al giorno.

__________

_    _____
 \__/

_        _
 \______/

_        _
 \    __/
  \__/

_        _
 \      /
  \  __/
   \/

_        _
 \      /
  \    /
   \  /
    \/

Cornercases

L'escavatore dovrà scavare l'ultimo giorno esattamente la sua capacità (velocità)

Width: 7, Speed: 3
Width: 10, Speed: 4 

Risposte:


1

Stax , 65 byte

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

Esegui ed esegui il debug

Se prima calcola i caratteri di scavo, in una stringa piatta. Quindi aggiunge profondità. Ad esempio "_V___"è un giorno di scavo ed "_\V/_"è la stringa piatta completata.

Utilizza questo metodo per eseguire un'unità di scavo.

  1. Inizia con un singolo "\", più il numero appropriato di "_" caratteri.
  2. Se "V_" è nella stringa, sostituirlo con "/".
  3. Altrimenti, se "/ _" è nella stringa, sostituirlo con "_ /".
  4. Altrimenti, se "\ _" è nella stringa, sostituirlo con "\ V".
  5. La nuova stringa è il risultato di un'unità di scavo. Ripetere dal passaggio 2.

Ecco l'intero programma decompresso, ungolf e commentato.

'_*'\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

Esegui ed esegui il debug


Buon lavoro! In attesa di spiegazione: D
Dead Possum

@DeadPossum: hai dovuto aspettare solo una settimana!
ricorsivo il

3

Retina 0.8.2 , 163 156 byte

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

Provalo online! Spiegazione:

.+
$*_

Converti gli input in unario. Questo ci dà W¶S.

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

Scambia gli input e duplica la larghezza. Questo ci dà S¶W¶W.

r`__\G
$%`$&

Calcola il volume della cava. Questo ci dà S¶W¶V.

¶
;

Unisci gli input in una riga. Questo ci dà S;W;V.

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

Calcola la quantità di progressi per ogni giorno sulla propria riga. Ogni giorno ha il formato S;W;D, dove si Dtrova 0sulla prima riga e aumenta di Sogni giorno fino a raggiungere V.

m`^_+;
__

Elimina Se aumenta Wdi 2 su ogni riga. Questo ci dà G;Dper ogni giorno.

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

Mentre Dè diverso da zero, scava uno Do G-2dalla linea (quindi il primo e l'ultimo carattere sono sempre a sinistra), spostando la profondità alla riga successiva. Ogni riga è rientrata con una in più >rispetto alla precedente. Le righe appena scavate includono anche a <.

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

Trasforma il rientro in spazi e quanto segue _in a \.

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

Se a <sta seguendo a, \allora trasformalo in a V, se sta seguendo a, _quindi trasformalo in a /. Eliminare tutti i <s e ;s.


Retina mi stupisce per qualche motivo ._. Buon lavoro!
Dead Possum,

1

Python 2 , 265 byte

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

Provalo online!


2x 1+i+aa i-~a.
Kevin Cruijssen,

sum(range(0,w+1,2))può esserew/2*(w/2+1)
ovs

@ovs tpuò anche essere inline, risultando in 257 byte .
Jonathan Frech,

@DeadPossum Risolto
TFeld

@TFeld Ottimo lavoro!
Dead Possum,

1
  • golf in corso

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

  • soluzione risolta duo all'errore su dispari w (grazie a @Shaggy) + riduzione di 2 byte
  • grazie a @Herman Lauenstein per la riduzione di 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}

Provalo online!

Spiegazione

(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}

Non funziona se wè dispari.
Shaggy,

@Shaggy fixed :)
DanielIndie

@HermanLauenstein potresti essere più specifico?
DanielIndie,

Non è necessario contare l'assegnazione variabile ( f=) e puoi salvare un altro byte eseguendo il curriculum dei parametri ( w=>s=>).
Shaggy,

@DeadPossum sembra funzionare per 7,3, sei sicuro? potresti mettere l'output previsto?
DanielIndie,
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.