採石場のタイムラプスを掘る


11

建築物のクールなタイムラプスや他の大規模な作業を数分で見るのが好きですか?ここで作りましょう。
採石場を掘る掘削機を見ながら、毎日写真を撮って全体の進捗状況を確認します。そして、あなたの仕事はこのプロセスを見せることです!

採石場は、その最初の層の幅によって定義されます。
掘削機は、1日で掘る能力によって定義されます。

入力

採石場の幅。整数、常に1以上。
掘削機の掘削速度。整数、常に1以上。

出力

毎日の採石場の掘削の進捗。平らな手つかずの地面から始まり、完成した採石場で終わりました。

ルール

  • 最終日には、掘削機の能力よりも掘るユニットが少なくなる可能性があります。過剰な作業はどこにも使用されないため、完全に掘られた採石場を出力するだけです。

  • すべての日の進行状況が一度に出力に存在する必要があります。出力の前日の進行状況をクリアまたは上書きすることはできません。

  • 毎日の出力の末尾および先頭の改行は、妥当な数であれば受け入れられます。

  • これはなので、コードをできるだけコンパクトにします。

明確化

作業は平らな地面から始まります。表示される地面の長さは、採石場の幅+ 2です。したがって、採石場の両側には常に1つのアンダースコア文字があります。

__________

掘られた採石場は均等な幅でこのように見えます:

_        _      
 \      /
  \    /
   \  /
    \/

そして、このような奇数幅

_       _      
 \     /
  \   /
   \ /
    V

採石場の進捗状況の例を次に示します。

_ _______
 V          dug 1 unit

_  ______
 \/         dug 2 units

_     ___
 \___/      dug 5 units


_       _
 \   __/    dug 10 units
  \_/

完全な進捗の例。採石場の幅:8。掘削機の速度:1日4ユニット。

__________

_    _____
 \__/

_        _
 \______/

_        _
 \    __/
  \__/

_        _
 \      /
  \  __/
   \/

_        _
 \      /
  \    /
   \  /
    \/

コーナーケース

掘削機は最終日にその能力(速度)を正確に掘る必要があります

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

回答:


1

スタックス、65 バイト

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

実行してデバッグする

最初に掘削文字を1つのフラットな文字列で計算する場合。その後、深さが追加されます。たとえば、"_V___"1日掘り、"_\V/_"完成したフラットストリングです。

この方法を使用して、1単位の掘削を行います。

  1. 単一の「\」に加えて、適切な数の「_」文字で始まります。
  2. 「V_」が文字列に含まれている場合は、「/」に置き換えます。
  3. それ以外の場合、文字列に「/ _」がある場合は、「_ /」に置き換えます。
  4. それ以外の場合、文字列に「\ _」がある場合は、「\ V」に置き換えます。
  5. 新しい文字列は、1ユニットの掘削の結果です。手順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:1週間待つだけでした!
再帰的

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ます。

¶
;

入力を1行に結合します。これは私たちに与えS;W;Vます。

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

独自の行で毎日の進行量を計算します。毎日形式はS;W;DDである0ことにより、最初の行と増分にSそれが到達するまで毎日V

m`^_+;
__

削除しSW各行で2ずつ増やします。これはG;D毎日私たちに与えてくれます。

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

ながらDゼロで、いずれか掘るDまたはG-2ライン(最初と最後の文字は常に残されているので)、次の行に深さを移動します。各行は>、前の行よりも1つインデントされています。新たに掘られたラインにも<

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

インデントをスペースに、次_をaに変えます\

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

場合は<、次のされて\、その後にそれを回すVことは、次のいた場合、_その後にそれを回します/。すべての<sと;sを削除します。


網膜は何らかの理由で私を驚かせます。よくやった!
デッドポッサム

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

オンラインでお試しください!


2x 1+i+aからi-~a
ケビンCruijssen

sum(range(0,w+1,2))することができますw/2*(w/2+1)
-ovs

@ovs tもインライン化でき、結果として257バイトになります
ジョナサン

固定@DeadPossum
TFeld

@TFeldお疲れ様でした!
デッドポッサム

1
  • 進行中のゴルフ

JavaScriptの(Node.jsの)329 315 307 300 301の 298 285 275 260 254バイト

  • 奇数w(@Shaggyに感謝)のエラーに対する解決策のデュオを修正+ 2バイト削減
  • @Herman Lauensteinに感謝します
(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 fixed :)
DanielIndie

@HermanLauensteinより具体的に教えていただけますか?
ダニエルインディー

変数の割り当てをカウントする必要はなく(f=)、パラメーターをカリー化することで別のバイトを保存できます(w=>s=>)。
シャギー

@DeadPossumは7,3で動作するようです。期待した出力を出すことができますか?
ダニエルインディー
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.