ขุด timelapse ของเหมือง


11

คุณชอบที่จะดูช่วงเวลาที่ยอดเยี่ยมของสิ่งก่อสร้างหรืองานขนาดใหญ่อื่น ๆ ในไม่กี่นาทีหรือไม่? ให้ทำที่นี่
เราจะมองไปที่เหมืองขุดขุดทำภาพในแต่ละวันเพื่อดูความคืบหน้าทั้งหมด และงานของคุณคือแสดงให้เราเห็นกระบวนการนี้!

เหมืองหินถูกกำหนดโดยความกว้างของชั้นแรก
รถขุดถูกกำหนดโดยความสามารถในการขุดในหนึ่งวัน

อินพุต

ความกว้างของเหมือง เลขจำนวนเต็มเสมอ> = 1
Excavator dig speed เลขจำนวนเต็มเสมอ> = 1

เอาท์พุต

ความคืบหน้าของการขุดเหมืองในแต่ละวัน เริ่มต้นด้วยพื้นดินที่ไม่ถูกแตะต้องและเสร็จสิ้นด้วยการทำเหมือง

กฎระเบียบ

  • ในวันสุดท้ายอาจมีหน่วยขุดน้อยกว่าความสามารถในการขุด งานที่มากเกินไปจะไม่ถูกนำไปใช้ในทุกที่ดังนั้นคุณควรส่งออกเหมืองที่ขุดได้อย่างสมบูรณ์

  • ความคืบหน้าทุกวันจะต้องมีอยู่ในผลลัพธ์ในครั้งเดียว คุณไม่สามารถล้างหรือเขียนทับความคืบหน้าของวันก่อนหน้าในผลลัพธ์

  • ขึ้นบรรทัดใหม่และนำขึ้นบรรทัดใหม่สำหรับผลลัพธ์ในแต่ละวันเป็นที่ยอมรับในจำนวนที่สมเหตุสมผล

  • นี่คือดังนั้นโปรดทำให้รหัสของคุณเล็กที่สุดเท่าที่จะทำได้

ชี้แจง

งานเริ่มต้นด้วยพื้นราบ ความยาวของพื้นดินที่แสดงคือความกว้างของเหมืองหิน +2 ดังนั้นจะมีอักขระขีดล่างหนึ่งตัวที่ทั้งสองด้านของเหมืองหิน

__________

เหมืองที่ขุดจะมีลักษณะเช่นนี้สำหรับความกว้าง:

_        _      
 \      /
  \    /
   \  /
    \/

และเช่นนี้สำหรับความกว้างที่แปลก

_       _      
 \     /
  \   /
   \ /
    V

นี่คือตัวอย่างของความคืบหน้าของเหมือง:

_ _______
 V          dug 1 unit

_  ______
 \/         dug 2 units

_     ___
 \___/      dug 5 units


_       _
 \   __/    dug 10 units
  \_/

ตัวอย่างความคืบหน้าเต็ม ความกว้างของเหมืองหิน: 8. ความเร็วของรถขุด: 4 หน่วยต่อวัน

__________

_    _____
 \__/

_        _
 \______/

_        _
 \    __/
  \__/

_        _
 \      /
  \  __/
   \/

_        _
 \      /
  \    /
   \  /
    \/

Cornercases

รถขุดจะต้องขุดในวันสุดท้ายตรงตามความสามารถ (ความเร็ว)

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

คำตอบ:


1

สแตกซ์ , 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
Dead Possum

@DeadPossum: คุณแค่รอสัปดาห์เดียว!
เรียกซ้ำ

3

เรติน่า 0.8.2 , 163 156 ไบต์

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

ลองออนไลน์! คำอธิบาย:

.+
$*_

แปลงอินพุตเป็น unary W¶Sนี้จะช่วยให้เรา

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

สลับอินพุตและทำซ้ำความกว้าง S¶W¶Wนี้จะช่วยให้เรา

r`__\G
$%`$&

คำนวณปริมาตรของเหมือง S¶W¶Vนี้จะช่วยให้เรา

¶
;

เข้าร่วมอินพุตเป็นหนึ่งบรรทัด S;W;Vนี้จะช่วยให้เรา

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

คำนวณจำนวนความคืบหน้าสำหรับแต่ละวันในสายของตัวเอง ในแต่ละวันมีรูปแบบS;W;Dที่Dเป็น0ในบรรทัดแรกและเพิ่มขึ้นโดยในแต่ละวันจนกว่าจะถึงSV

m`^_+;
__

ลบSและเพิ่มW2 ในแต่ละบรรทัด สิ่งนี้ทำให้เราG;Dในแต่ละวัน

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

ในขณะที่Dไม่ใช่ศูนย์ขุดอย่างใดอย่างหนึ่งDหรือG-2จากบรรทัด (ดังนั้นอักขระตัวแรกและตัวสุดท้ายจะถูกทิ้งเสมอ) ย้ายความลึกไปยังบรรทัดถัดไป แต่ละบรรทัดมีการย่อหน้าที่มากกว่าหนึ่งครั้ง>ก่อนหน้า <สายการขุดใหม่ยังรวมถึง

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

เปิดเยื้องลงในช่องว่างและต่อไปนี้เป็น_\

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

ถ้า<เป็นดังต่อไปนี้\แล้วทำให้มันกลายเป็นVถ้ามันต่อไปนี้แล้วทำให้มันกลายเป็น_ /ลบ<s และ;s ทั้งหมด


Retina ทำให้ฉันประหลาดใจด้วยเหตุผลบางอย่าง. เยี่ยมมาก!
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

ลองออนไลน์!


2x ไป1+i+a i-~a
Kevin Cruijssen

sum(range(0,w+1,2))สามารถw/2*(w/2+1)
ovs

@ovs tอาจถูก inlined ผลใน257 ไบต์
Jonathan Frech

@DeadPossum แก้ไข
TFeld

@TFeld ดีมาก!
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=) และคุณสามารถบันทึกไบต์อื่นได้โดยการ Curating พารามิเตอร์ ( w=>s=>)
Shaggy

@DeadPossum มันดูเหมือนว่าจะทำงานให้กับ 7,3 คุณแน่ใจหรือไม่? คุณสามารถวางสิ่งที่คาดหวังได้หรือไม่?
DanielIndie
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.