10
\$\begingroup\$

If you throw an ASCII egg in a given direction, you end up with an ASCII splat of size n. It "starts" with one o (the yolk), and continues in a given direction with "lines" consisting of 2 up to n *'s. The *'s are separated by one "space", and the o and all the "lines" of *'s are separated by "lines" of "space".

The direction of the splat can be any one of eight directions from o, for example:

1 2 3
4 o 5
6 7 8

Here are examples of ASCII splats of size 4 in directions 5, 2 and 3 respectively. On the left is the actual ASCII splat, and on the right is the same splat but with the "lines" of "space" replaced with actual "lines" (i.e. - or \ or | depending on the direction) just to clarify what is meant by a "line" of space.

Size 4, direction 5
      *      | | |*
    *        | |*| 
  *   *      |*| |*
o   *       o| |*| 
  *   *      |*| |*
    *        | |*| 
      *      | | |*

Size 4, direction 2
* * * *     * * * *
            -------
 * * *       * * *
            -------
  * *         * *
            -------
   o           o

Size 4, direction 3   
*           *      
            \
* *         *\*    
            \ \
* * *       *\*\*
            \ \ \ 
o * * *     o\*\*\*

Challenge

Given n ≥ 1 and one of the 8 possible directions, write a function or program that outputs the ASCII splat of size n in the given direction.

Input and output

Any consistent, reasonable input format is allowed. You don't need to map directions to the integers 1 to 8 in the same way I did - if some other way of specifying the direction is easier, go ahead. But say what you did if it isn't clear.

The output will consist of o, *, spaces (U+0020) and newlines (U+000A) that produce the ASCII splat. Leading, trailing, otherwise extra whitespace is permitted on any line.

Rules

This is . Standard rules apply.

More examples

Size 1, any direction
o

Size 3, direction 6
* * o

  * *

    *

Size 5, direction 7
    o    

   * *

  * * *

 * * * *

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

Charcoal, 20 18 bytes

↘EN×*⊕ιM↗oUE¬﹪η²⟲η

Try it online! Link is to verbose version of code. Explanation:

↘EN×*⊕ι

Draw a diagonal triangle of splats.

M↗o

Place the egg.

UE¬﹪η²

For even rotations, expand the splat horizontally to match the output requirement. This requirement doesn't match Charcoal's usual expectations. Try it online! (verbose) for how it looks without.

⟲η

Rotate the splat as required, using the following code for directions:

321
4o0
567

This 37 31-byte version avoids extraneous whitespace by only rotating in right angles:

¿﹪η²G↘←θ*«↘Eθ×*⊕ι↗»oUE¹﹪η²⟲⊗÷η²

Try it online! Link is to verbose version of code.

\$\endgroup\$
2
\$\begingroup\$

Jelly, 37 bytes

”*ẋK¥ⱮmṠ©}”oḷ""LḶ⁶ẋƲ;"ṚƊ®¡z⁶K€ZU$A}¡Y

Try it online!

Directions:

\$\left[\begin{array}c1&2&3\\4&\circ&5\\6&7&8\end{array}\right]\rightarrow\left[\begin{array}c-2&1&-3\\4&\circ&2\\-1&3&-4\end{array}\right]\$

\$\endgroup\$
1
\$\begingroup\$

Python 2, 185 bytes

lambda n,d:'\n'.join(g([(d/4*(n+~j)*' '+('*o'[[j>n-2,j<1][d/4]]+' *'*j)*i).ljust(2*n-1)for j in range(n)for i in(0,1)][1:],d%4))
g=lambda a,n:n and g(map(''.join,zip(*a))[::-1],n-1)or a

Try it online!

The numbering is from 0 to 7, as follows:

1 6 0
7 o 5
2 4 3

Notes: Most of the work is to generate the basic patterns for (in my numbering system) 0 and 4. Then the function g rotates the array a 90 degrees d%4 times via recursion to generate the other results.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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