11
\$\begingroup\$

Your mission today is to create a vortex given a single parameter.

This parameter determines the length of each arm in characters.

Each "layer" of each arm contains one more character than the last.

Here's how the vortex will look, given the arm length:

0:

#

1:

 # 
###
 # 

2:

 #
  # #
 ### 
# #  
   #

3:

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

4:

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

10:

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

Standard loopholes apply, trailing whitespace optional, any single non-whitespace character in ASCII can replace "#".

This is so the shortest answer in bytes wins.

\$\endgroup\$
6
  • \$\begingroup\$ The spec (such as there is) seems to contradict the examples. Where did the asymmetry come from in the last two? \$\endgroup\$ Commented Apr 18, 2017 at 6:14
  • \$\begingroup\$ Here is a corrected version. \$\endgroup\$
    – rahnema1
    Commented Apr 18, 2017 at 7:16
  • \$\begingroup\$ @JonathanAllan see my edit's description: Removed the ugly black non-character, but they're still asimmetric. And no, I'm not taking over... Seems like a boring challenge to me (no offense) \$\endgroup\$
    – Mr. Xcoder
    Commented Apr 18, 2017 at 7:59
  • \$\begingroup\$ Please re-open this. It is clear now. \$\endgroup\$
    – user58826
    Commented Apr 18, 2017 at 13:32
  • 1
    \$\begingroup\$ @JonathanAllan Yeah, they had an issue as you said. Fixed. \$\endgroup\$
    – JessLovely
    Commented Apr 18, 2017 at 13:35

4 Answers 4

5
\$\begingroup\$

MATL, 60 bytes

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

Try it online! Or verify test cases: 0, 1, 2, 3, 4, 10.

This turned out to be funnier than I expected. Explaining is going to be harder, though...

\$\endgroup\$
3
\$\begingroup\$

Jelly, 48 bytes

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

Try it online!

(Make it all more square by replacing the final Y with G, adding a space between each column).

How?

Builds a list of # coordinates of an arm relative to the centre. Transforms that to the coordinates of the four arms from the top-left corner and adds the centre coordinate. Builds a table of all the coordinates in the space and sets the arms to # and the space to and joins up the rows with 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
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 30 bytes

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

Explanation

#                                    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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Trim seems to work out golfier: NθFθ⁺¶#×#ιJ⁰¦⁰Tθ⁺¹θ#⟲O↖²⁴⁶ (⁺¹ is a workaround because T⁰¦⁰ doesn't work for some reason. and didn't exist back then.) \$\endgroup\$
    – Neil
    Commented Dec 27, 2017 at 18:11
0
\$\begingroup\$

Mathematica 139 172 Bytes

The idea is to create a single arm with a function - {⌊.5+.5(-7+8#)^.5⌋,#-1} that spits out the index of each element of the arm assuming the middle element has index (0,0). No one has picked up on that yet, but I suspect this idea would result in a winning answer in a better golfing language. Then I rotate the arm through multiples of 90 degrees, re-index and construct the matrix.

SparseArray seemed like the obvious choice for constructing the matrix, but could have gone with BoxMatrix and 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,""]]&

Ungolfed (Hard coded for arm length=3,% means previous output):

{{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->""]

Usage %@4

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

As I've learned the output must be pure ASCII without extra spacing or formatting, the code has to get a little longer (172 bytes):

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

#     #  
 ##  #   
   # #   
  ###    
 # #     
 #  ##   
#     #  
\$\endgroup\$
4
  • \$\begingroup\$ Can the extra spacing between columns be removed? As this is an ASCII-art challenge, the output should be exactly as specified, with no extra spacing (@Papayaman1000 please confirm if this can be exempted) \$\endgroup\$
    – hyper-neutrino
    Commented Apr 20, 2017 at 3:46
  • \$\begingroup\$ I put in an edit for that if it turns out to be required. Right now it seems debatable. \$\endgroup\$ Commented Apr 20, 2017 at 4:20
  • \$\begingroup\$ Hmm... I would prefer that, for competition's sake, you use the answer that gives the exact output. As @HyperNeutrino said, it is ASCII-art, so it should be as specified. \$\endgroup\$
    – JessLovely
    Commented Apr 20, 2017 at 4:38
  • \$\begingroup\$ OK, I fixed it. \$\endgroup\$ Commented Apr 20, 2017 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.