11
\$\begingroup\$

Do you love watching cool timelapses of constructions or other massive work done in minutes? Lets make one here.
We will be looking at an excavator digging quarry, making pictures each day to see whole progress. And your task is to show us this process!

Quarry is defined by the width of its first layer.
Excavator is defined by its capability to dig in one day.

Input

Width of quarry. Integer number, always >= 1.
Excavator dig speed. Integer number, always >= 1.

Output

Progress of digging quarry on each day. Started with flat untouched ground and finished with completed quarry.

Rules

  • On the last day there may be less units to dig, than excavator is capable of. Excessive work won't be used anywhere, so you should just output fully dug quarry.

  • All days progress must be present in the output at once. You can't clear or overwrite previous day progress in the output.

  • Trailing and leading newlines for each day output are acceptable in any reasonable number.

  • This is , so make your code as compact as possible.

Clarifications

Work starts with a flat ground. Length of displayed ground is width of quarry + 2. So there always will be one underscore character on both sides of quarry.

__________

Dug quarry is looking like this for even width:

_        _      
 \      /
  \    /
   \  /
    \/

And like this for odd width

_       _      
 \     /
  \   /
   \ /
    V

Here are examples of quarry progress:

_ _______
 V          dug 1 unit

_  ______
 \/         dug 2 units

_     ___
 \___/      dug 5 units


_       _
 \   __/    dug 10 units
  \_/

Full progress example. Quarry width: 8. Excavator speed: 4 units per day.

__________

_    _____
 \__/

_        _
 \______/

_        _
 \    __/
  \__/

_        _
 \      /
  \  __/
   \/

_        _
 \      /
  \    /
   \  /
    \/

Cornercases

Excavator will need to dig on the last day exactly its capability (speed)

Width: 7, Speed: 3
Width: 10, Speed: 4 
\$\endgroup\$

4 Answers 4

4
\$\begingroup\$

Retina 0.8.2, 163 156 bytes

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

Try it online! Explanation:

.+
$*_

Convert the inputs to unary. This gives us W¶S.

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

Swap the inputs and duplicate the width. This gives us S¶W¶W.

r`__\G
$%`$&

Calculate the volume of the quarry. This gives us S¶W¶V.

¶
;

Join the inputs into one line. This gives us S;W;V.

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

Calculate the amount of progress for each day on its own line. Each day has the format S;W;D, where D is 0 on the first line and increments by S each day until it reaches V.

m`^_+;
__

Delete S and increase W by 2 on each line. This gives us G;D for each day.

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

While D is nonzero, dig either D or G-2 from the line (so the first and last characters are always left), moving the depth to the next line. Each line is indented with one more > than the previous. Newly dug lines also include a <.

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

Turn the indent into spaces and the following _ into a \.

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

If a < is following a \ then turn it into a V, if it's following a _ then turn it into a /. Delete all the <s and ;s.

\$\endgroup\$
1
  • \$\begingroup\$ Retina amazes me for some reason ._. Good job! \$\endgroup\$ Apr 20, 2018 at 13:21
1
\$\begingroup\$

Stax, 65 bytes

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

Run and debug it

If first calculates the digging characters, in one flat string. Then it adds depth. For instance "_V___" is one day of digging, and "_\V/_" is the completed flat string.

It uses this method for doing one unit of digging.

  1. Start with a single "\", plus the appropriate number of "_" characters.
  2. If "V_" is in the string, replace it with "/".
  3. Otherwise, if "/_" is in the string, replace it with "_/".
  4. Otherwise, if "\_" is in the string, replace it with "\V".
  5. The new string is the result from one unit of digging. Repeat from step 2.

Here's the whole program unpacked, ungolfed, and commented.

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

Run and debug it

\$\endgroup\$
2
  • \$\begingroup\$ Good job! Awaiting explanation :D \$\endgroup\$ Apr 20, 2018 at 13:21
  • \$\begingroup\$ @DeadPossum: You only had to wait a week! \$\endgroup\$
    – recursive
    Apr 27, 2018 at 22:56
1
\$\begingroup\$

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

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ 2x 1+i+a to i-~a. \$\endgroup\$ Apr 19, 2018 at 15:15
  • \$\begingroup\$ sum(range(0,w+1,2)) can be w/2*(w/2+1) \$\endgroup\$
    – ovs
    Apr 19, 2018 at 16:00
  • \$\begingroup\$ @ovs t can possibly also be inlined, resulting in 257 bytes. \$\endgroup\$ Apr 19, 2018 at 19:17
  • \$\begingroup\$ @DeadPossum Fixed \$\endgroup\$
    – TFeld
    Apr 20, 2018 at 7:07
  • \$\begingroup\$ @TFeld Good job! \$\endgroup\$ Apr 20, 2018 at 13:19
1
\$\begingroup\$
  • golf in progress

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

  • fixed solution duo to error on odd w(thanks to @Shaggy) + reduce by 2 bytes
  • thanks to @Herman Lauenstein for reducing by 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}

Try it online!

Explanation

(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}
\$\endgroup\$
7
  • \$\begingroup\$ Doesn't work if w is odd. \$\endgroup\$
    – Shaggy
    Apr 19, 2018 at 16:36
  • \$\begingroup\$ @Shaggy fixed :) \$\endgroup\$ Apr 19, 2018 at 16:42
  • \$\begingroup\$ @HermanLauenstein could you be more specific? \$\endgroup\$ Apr 19, 2018 at 16:44
  • \$\begingroup\$ You don't need to count the variable assignment (f=) and you can save another byte by currying the parameters (w=>s=>). \$\endgroup\$
    – Shaggy
    Apr 19, 2018 at 16:55
  • \$\begingroup\$ @DeadPossum its seems to work for 7,3 are you sure? could you put the expected output? \$\endgroup\$ Apr 19, 2018 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.