挖掘采石场游戏中时光倒流


11

您喜欢在几分钟内观看完建筑或其他大型工作的时光倒流吗?让我们在这里做一个。
我们将看挖掘机的采石场,每天拍摄照片以查看整个进度。您的任务是向我们展示此过程!

采石场由其第一层的宽度定义。
挖掘机的定义是一天之内的挖掘能力。

输入值

采石场的宽度。整数,始终> =1。
挖掘机挖掘速度。整数,始终> = 1。

输出量

每天采石场的进度。从平坦的未接触地面开始,直至完成采石场。

规则

  • 在最后一天,挖掘的单位可能少于挖掘机的能力。过多的工作不会在任何地方使用,因此您应该只输出完全挖掘的采石场。

  • 必须整天都在输出中显示进度。您无法清除或覆盖输出中的前一天进度。

  • 每天输出的尾随换行符和前导换行符的数量均可接受。

  • 这是,因此请使代码尽可能紧凑。

澄清说明

工作从平坦的地面开始。所显示地面的长度是采石场的宽度+2。因此,在采石场的两侧始终会有一个下划线字符。

__________

挖掘采石场的宽度看起来像这样:

_        _      
 \      /
  \    /
   \  /
    \/

像这样的奇数宽度

_       _      
 \     /
  \   /
   \ /
    V

以下是采石场进度的示例:

_ _______
 V          dug 1 unit

_  ______
 \/         dug 2 units

_     ___
 \___/      dug 5 units


_       _
 \   __/    dug 10 units
  \_/

完整进度示例。采石场宽度:8.挖掘机速度:每天4台。

__________

_    _____
 \__/

_        _
 \______/

_        _
 \    __/
  \__/

_        _
 \      /
  \  __/
   \/

_        _
 \      /
  \    /
   \  /
    \/

角柜

挖掘机将需要在最后一天准确挖掘其能力(速度)

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

Answers:


1

Stax,65 个字节

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

运行并调试

如果首先计算挖掘字符,则在一个平面字符串中。然后增加深度。例如,"_V___"是一天的挖掘工作,并且"_\V/_"是完整的扁平字符串。

它使用此方法进行一个单位的挖掘。

  1. 以单个“ \”开头,再加上适当数量的“ _”字符。
  2. 如果字符串中有“ V_”,则将其替换为“ /”。
  3. 否则,如果字符串中包含“ / _”,则将其替换为“ _ /”。
  4. 否则,如果字符串中有“ \ _”,则将其替换为“ \ V”。
  5. 新字符串是一个单位的挖掘结果。从步骤2重复。

这是整个程序的解压,解包和注释。

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

运行并调试


做得好!等待解释:D
死负鼠

@DeadPossum:您只需要等待一个星期!
递归

3

视网膜0.8.2163个 156字节

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

在线尝试!说明:

.+
$*_

将输入转换为一元。这给了我们W¶S

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

交换输入并复制宽度。这给了我们S¶W¶W

r`__\G
$%`$&

计算采石场的数量。这给了我们S¶W¶V

¶
;

将输入连接成一行。这给了我们S;W;V

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

每天计算自己的进度。每一天的格式S;W;D,其中,D0由第一线和增量S每天,直到它到达V

m`^_+;
__

删除SW在每行上增加2。这给了我们G;D每一天。

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

D非零值时,从行中挖掘一个DG-2一个(因此始终保留第一个和最后一个字符),然后将深度移至下一行。每行缩进一个以上的缩进>。新近挖出的生产线还包括一个<

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

打开缩进到空间和下面_\

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

如果a <在a \之后V,则将其转换为a ;如果在a _之后,则将其转换为/。删除所有<s和;s。


视网膜出于某种原因令我惊讶。做得好!
Dead Possum

1

Python 2,265字节

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

在线尝试!


2倍1+i+ai-~a
凯文·克鲁伊森

sum(range(0,w+1,2))可以w/2*(w/2+1)
ovs '18

t也可以内联@ovs ,导致257个字节
乔纳森·弗雷奇

@DeadPossum已修复
TFeld

@TFeld干得好!
Dead Possum

1
  • 高尔夫进行中

的JavaScript(Node.js的)329 315 307 300 301个 298 285 275 260 254字节

  • 修复了解决方案二重奏在奇数w上出错的问题(感谢@Shaggy)+减少了2个字节
  • 感谢@Herman Lauenstein减少了1个字节
(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}

在线尝试!

说明

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

如果w是奇数不起作用。
Shaggy

@Shaggy固定的:)
DanielIndie

@HermanLauenstein您能更具体一点吗?
DanielIndie

您无需计算变量分配(f=),也可以通过引用参数(w=>s=>)来节省另一个字节。
粗野的

@DeadPossum它似乎适用于7,3吗?你能把预期的输出吗?
DanielIndie
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.