สร้างกระแสน้ำวน!


10

ภารกิจของคุณในวันนี้คือการสร้างกระแสน้ำวนที่มีพารามิเตอร์เดียว

พารามิเตอร์นี้พิจารณาความยาวของแขนแต่ละข้างเป็นตัวอักษร

"เลเยอร์" แต่ละอันของแขนแต่ละข้างจะมีตัวละครมากกว่าหนึ่งตัว

นี่คือรูปลักษณ์ของกระแสน้ำวนที่มีความยาวแขน:

0:

#

1:

 # 
###
 # 

2:

 #
  # #
 ### 
# #  
   #

3:

##  #
  # #
 ### 
# #  
#  ##

4:

#     #
 ##  #
   # #
  ###  
 # #   
 #  ## 
#     #

10:

             #
             #
             #     
             #   
            #      
####        #      
    ###     #      
       ##  #      
         # #       
        ###       
       # #         
       #  ##       
      #     ###    
      #        ####
      #            
     #             
     #             
     #             
     #             

ใช้ช่องโหว่มาตรฐานลากตัวเลือกช่องว่างต่อท้ายอักขระที่ไม่ใช่ช่องว่างเดี่ยวใด ๆ ใน ASCII สามารถแทนที่ "#"

นี่คือดังนั้นคำตอบที่สั้นที่สุดในหน่วยไบต์ชนะ


สเป็ค (เช่นมี) ดูเหมือนจะขัดแย้งกับตัวอย่าง ความไม่สมมาตรมาจากไหนในสองช่วงสุดท้าย
Peter Taylor

นี่คือรุ่นที่แก้ไขแล้ว
rahnema1

@JonathanAllan อ่านรายละเอียดการแก้ไขของฉัน: นำออกน่าเกลียดสีดำที่ไม่ใช่ตัวอักษร แต่พวกเขายังคง asimmetric และไม่ฉันไม่ได้ครอบครอง ... ดูเหมือนจะเป็นความท้าทายที่น่าเบื่อสำหรับฉัน (ไม่มีความผิด)
Mr. Xcoder

โปรดเปิดใหม่อีกครั้ง ตอนนี้มันชัดเจนแล้ว
programmer5000

1
@JanathanAllan Yeah พวกเขามีปัญหาตามที่คุณพูด แก้ไขแล้ว.
Papayaman1000

คำตอบ:



3

วุ้น 48 ไบต์

Rȯ1ĖŒṙ‘Ė’ḣµ;NµN0¦€U;
Ç+;ẋ2W$+⁸<3¤µFṀR,þ$e€€ị⁾# Y

ลองออนไลน์!

(ทำให้เป็นสี่เหลี่ยมจัตุรัสมากขึ้นโดยแทนที่สุดท้ายYด้วยGการเพิ่มช่องว่างระหว่างแต่ละคอลัมน์)

อย่างไร?

สร้างรายการ#พิกัดของแขนที่สัมพันธ์กับศูนย์กลาง แปลงให้เป็นพิกัดของแขนทั้งสี่จากมุมบนซ้ายและเพิ่มพิกัดกลาง สร้างตารางพิกัดทั้งหมดในพื้นที่และตั้งค่าแขนให้กับ#และช่องว่างเพื่อและรวมแถวกับ newlines

Rȯ1ĖŒṙ‘Ė’ḣµ;NµN0¦€U; - Link 1, arm coordinates relative to centre: arm-length a
R                    - range: [1,2,...,a]
 ȯ1                  - or 1 (stops Œṙ erroring with arm-length 0; builds no redundant coordinates in the end)
   Ė                 - enumerate: [[1,1],[2,2],...[a,a]]  (or [[1,1]] if a=0)
    Œṙ               - run-length decode: [1,2,2,...,a,a,...,a] (or [1] if a=0)
      ‘              - increment: [2,3,3,...,a+1,a+1,...,a+1] (or [2] if a=0)
       Ė             - enumerate: [[1,2],[2,3],...,[T(a)-a,a+1],[T(a)-a+1,a+1],...,[T(a),a+1]] where T(a)=(a+1)*a/2 (or [[1,2]] if a=0)
        ’            - decrement: [[0,1],[1,2],...,[T(a)-a-1,a],[T(a)-a,a],...a[T(a)-1),a]] (or [[0,1]] if a=0)
         ḣ           - head to a (first a of those) - these are an arm's relative coordinates from the central `#` at [0,0])
          µ          - monadic chain separation (call that list r)
           ;         - r concatenated with
            N        - negate r (gets the opposite arm)
             µ       - monadic chain separation (call that list s)
                 €   - for €ach coordinate pair in s:
               0¦    -     apply to index 0 (the right of the two values):
              N      -         negate
                  U  - upend (reverse each pair of that, gives the other two arms)
                   ; - concatenate that list with s (gives all four arms)

Ç+;ẋ2W$+⁸<3¤µFṀR,þ$e€€ị⁾# Y - Main link: arm-length a
Ç                           - call the last link(1) as a monad (get centre-relative coordinates)
 +                          - add a (make the coordinates relative to the top-left)
      $                     - last two links as a monad:
   ẋ2                       -     repeat a twice: [a,a]
     W                      -     wrap in a list: [[a,a]] (the centre coordinate)
  ;                         - concatenate (add the centre coordinate)
           ¤                - nilad followed by link(s) as a nilad:
        ⁸                   -     link's left argument, a
         <3                 -     less than three?
       +                    - add (a in 0,1,2 are special cases requiring a grid one-by-one more than all the rest)
            µ               - monadic separation (call that c)
             F              - flatten c into one list
              Ṁ             - get the maximum (the side-length of the space)
                  $         - last two links as a monad:
               R            -     range: [1,2,...,side-length]
                ,þ          -     pair table: [[[1,1],[1,2],...,[1,side-length]],[[2,1],[2,2],...,[2,side-length]],...,[[side-length,1],[side-length,2],[side-length, side-length]]]
                   e€€      - exists in c? for €ach for €ach (1 if a # coordinate, 0 otherwise)
                       ⁾#   - literal ['#',' ']
                      ị     - index into
                          Y - join with new line characters
                            - implicit print

0

วิชาคณิตศาสตร์139 172 Bytes

ความคิดคือการสร้างแขนเดียวที่มีฟังก์ชั่น - {⌊.5+.5(-7+8#)^.5⌋,#-1}ที่แยกออกดัชนีของแต่ละองค์ประกอบของแขนสมมติว่าองค์ประกอบกลางมีดัชนี (0,0) ยังไม่มีใครเลือกเรื่องนี้ได้ แต่ฉันสงสัยว่าความคิดนี้จะส่งผลให้คำตอบที่ชนะในภาษากอล์ฟที่ดีขึ้น จากนั้นฉันหมุนแขนไปหลายรายการ 90 องศาทำดัชนีใหม่และสร้างเมทริกซ์

SparseArrayดูเหมือนว่าทางเลือกที่ชัดเจนสำหรับการสร้างเมทริกซ์ แต่จะได้ไปด้วยและBoxMatrixReplacePart

Grid[SparseArray[Max@#+#+1&[Join@@Table[RotationMatrix[i Pi/2].#&/@{{0,0}}~Join~Array[{⌊.5+.5(-7+8#)^.5⌋,#-1}&,#],{i,4}]]->X,2#+1,""]]&

Ungolfed (ฮาร์ดโค้ดสำหรับความยาวแขน = 3 %หมายถึงเอาต์พุตก่อนหน้า):

{{0,0}}~Join~Table[{Floor[1/2 (1+Sqrt[-7+8x])],x-1},{x,1,3}]
Table[RotationMatrix[i Pi/2].#&/@%,{i,4}]
Flatten[%,1]
Max[%]+%+1
Normal@SparseArray[%->X,Automatic,""]
Grid[%/. 0->""]

การใช้งาน% @ 4

X                       X   
    X   X           X       
            X       X       
        X   X   X           
    X       X               
    X           X   X       
X                       X

ตามที่ฉันได้เรียนรู้ผลลัพธ์จะต้องเป็น ASCII แท้โดยไม่มีการเว้นวรรคหรือการจัดรูปแบบเพิ่มเติมรหัสจะต้องมีความยาวเพิ่มขึ้นเล็กน้อย (172 ไบต์):

StringRiffle[ReplacePart[Array[" "&,{1,1}*2#+1],Max@#+#+1&[Join@@Table[RotationMatrix[i Pi/2].#&/@{{0,0}}~Join~Array[{⌊.5+.5(-7+8 #)^.5⌋,#-1}&,#],{i,4}]]->"#"],"\n",""]

#     #  
 ##  #   
   # #   
  ###    
 # #     
 #  ##   
#     #  

สามารถลบระยะห่างพิเศษระหว่างคอลัมน์ได้หรือไม่? เนื่องจากนี่เป็นความท้าทายของ ASCII ดังนั้นผลลัพธ์ควรตรงตามที่ระบุโดยไม่มีการเว้นวรรคเพิ่มเติม (@ Papayaman1000 โปรดยืนยันว่าสามารถยกเว้นได้)
HyperNeutrino

ฉันใส่ในการแก้ไขเพื่อที่ว่ามันจะต้อง ตอนนี้ดูเหมือนว่าจะเป็นที่ถกเถียงกัน
Kelly Lowder

อืม ... ฉันต้องการที่จะทำเพื่อประโยชน์ของการแข่งขันคุณใช้คำตอบที่ให้ผลลัพธ์ที่แน่นอน ดังที่ @HyperNeutrino กล่าวว่าเป็น ASCII-art ดังนั้นจึงควรเป็นไปตามที่ระบุไว้
Papayaman1000

ตกลงฉันซ่อมมันแล้ว
Kelly Lowder

0

ถ่าน 30 ไบต์

#NβFβ«¿ι«×#⌊⟦ιβ⟧A⁻βιβ↑»»‖←⟲O²⁴⁶

คำอธิบาย

#                                    Print "#"
 Nβ                                 Input number to b
    Fβ«                  »          For i in range(b)
        ¿ι«              »           If i is truthy (to skip 0)
           ×#⌊⟦ιβ⟧                   Print "#" * minimum of i and b
                  A⁻βιβ↑            Assign b-i to b
                           ‖         Reflect right
                            ⟲O²⁴⁶  Rotate overlap 90, 180 and 270 degrees

ลองออนไลน์!


Trimดูเหมือนว่าจะทำงานออก golfier: NθFθ⁺¶#×#ιJ⁰¦⁰Tθ⁺¹θ#⟲O↖²⁴⁶( ⁺¹เป็นวิธีแก้ปัญหาเพราะT⁰¦⁰ไม่ได้ทำงานด้วยเหตุผลบางอย่างและ. ไม่ได้อยู่กลับมาแล้ว.)
นีล
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.