产生漩涡!


10

今天的任务是在给定单个参数的情况下创建漩涡。

此参数确定每个臂的长度(以字符为单位)。

每条手臂的每个“层”比最后一个包含更多的字符。

给定臂长,这是漩涡的外观:

0:

#

1:

 # 
###
 # 

2:

 #
  # #
 ### 
# #  
   #

3:

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

4:

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

10:

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

适用标准漏洞,尾随空白是可选的,ASCII中的任何单个非空白字符都可以替换“#”。

这是因此最短的答案以字节为单位。


规范(如存在)似乎与示例矛盾。最近两个地方的不对称来自何处?
彼得·泰勒

是更正的版本。
rahnema17年

@JonathanAllan看到我的编辑描述:删除了难看的黑色非字符,但它们仍然不对称。不,我没有接手...似乎对我构成无聊的挑战(无冒犯)
Xcoder先生17年

请重新打开它。现在很清楚。
programmer5000

1
@JonathanAllan是的,正如您所说,他们遇到了问题。固定。
Papayaman1000

Answers:


5

MATL,60字节

3<G+Eqt&OlG8M+t&(1G:8*X^Q2/kG+G:Gq+&vG2=+Z{(XJ3:"J@X!+]g35*c

在线尝试!或验证测试案例:0123410

事实证明这比我预期的要有趣。但是,解释将变得更加困难。


3

果冻,48 个字节

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

在线尝试!

(使它更所有通过更换最终方YG,加入每列之间的空间)。

怎么样?

建立#相对于中心的手臂坐标列表。从左上角将其转换为四个手臂的坐标,并添加中心坐标。建立一个包含空间中所有坐标的表,并将arms #和space设置为,并用换行符将行连接起来。

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字节

这个想法是创建一个具有功能{⌊.5+.5(-7+8#)^.5⌋,#-1}的单臂-假设中间元素的索引为(0,0),则该函数会伸出该臂的每个元素的索引。尚无人接受,但我怀疑这种想法会以更好的高尔夫语言赢得成功。然后,我将手臂旋转90度的倍数,重新索引并构造矩阵。

SparseArray看起来似乎是构建矩阵的明显选择,但可以BoxMatrix和和一起使用ReplacePart

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,""]]&

取消高尔夫(硬编码为手臂长度= 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

如果需要,我对此进行了编辑。现在看来,这值得商bat。
凯利·洛德

嗯...出于竞争的考虑,我希望您使用给出确切输出的答案。正如@HyperNeutrino所说的,它是ASCII艺术,因此应按指定。
Papayaman1000 '17

好,我修好了。
凯莉·洛德

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⁰¦⁰没有工作,出于某种原因,并。不存在当时的情况。)
尼尔
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.