Skip to main content
Notice removed Reward existing answer by Giuseppe
Bounty Ended with att's answer chosen by Giuseppe
Notice added Reward existing answer by Giuseppe
Bounty Started worth 300 reputation by Giuseppe
Became Hot Network Question
deleted 3 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular numberperfect square (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.
  • Consistent leading spaces or newlines are also ok, as long as the shape of the triangle is preserved.

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.
  • Consistent leading spaces or newlines are also ok, as long as the shape of the triangle is preserved.

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a perfect square (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.
  • Consistent leading spaces or newlines are also ok, as long as the shape of the triangle is preserved.
added 105 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.
  • Consistent leading spaces or newlines are also ok, as long as the shape of the triangle is preserved.

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.
  • Consistent leading spaces or newlines are also ok, as long as the shape of the triangle is preserved.
added 1107 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.

Challenge

Given a string of any length, write it as a triangle, spiraling out from the center. For example, abcdefghijklmnop becomes:

   g  
  fah
 edcbi
ponmlkj

Or more explicitly:

enter image description here

If you like, you can spiral counter-clockwise instead:

   g  
  haf
 ibcde
jklmnop

Or add spaces uniformly:

      g   

    f a h 

  e d c b i  

p o n m l k j 

The input characters will be ascii, but may include spaces. Also, the number of characters may not be a triangular number (Hello World!):

  W
  Ho
oller
   !dl

A couple more edge cases. 2 letter input ab:

 a
  b

And 3 letter input abc:

 a
 cb

Procedural Description

In case the above examples aren't clear, here's a procedural description of the process:

  1. Put down your initial letter.
  2. Move diagonally down and to the right (i.e., this direction \). So if you started at (0,0), you will now be at (1,-1). Put down your second letter.
  3. Move left one space a time, dropping a letter on each space, for a total of 3 spaces. That is, drop letters on (0,-1), (-1,-1), and (-2, -1).
  4. Next move diagonally up and to the right / two spaces, dropping letters on (-1,0) and (0,1).
  5. Now cycle back to moving diagonally down and to the right, continuing to step and drop letters as long as your current position is left-right adjacent to an existing letter.
  6. Next move left again, continuing to step and drop letters as long as you are diagonally adjacent / to an existing letter.
  7. Move diagonally up and to the right again /, stepping and dropping letters as long as your current position is left-right adjacent to an existing letter.
  8. Repeat steps 5-7 until all letters are used up.

More examples

Rules

  • Code golf, standard rules apply.
  • Trailing spaces or newlines are ok.
Tweeted twitter.com/StackCodeGolf/status/1300946543701352448
added 11 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading
added 107 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading