21
This competition is over. Thanks for the interesting non-esolang entries, and congrats to Jakuje for his winning JavaScript submission.
In the great tradition of ASCII Art Challenges on this site, here's another one. Given an input, draw a spiral.
&>----v
||>--v|
|||>v||
|||@|||
||^-<||
|^---<|
^-----<
Simple, yeah? Heh, heh, heh ... Yeah...
(Inspired by the ASCII Dragons Curve post, and Optimizer's ASCII Art of the Day posts)
Input
Input will be in the form of a series of parameters, taken from the usual STDIN/function argument/etc., whatever your language equivalent, comprised of four parts. These parts can be four separate arguments, a quadruple, an array of size 4, etc. For simplicity and consistency throughout the challenge, I will represent the input as a single word.
- An integer
2 ≤ x ≤ 20
that specifies the size of the spiral in terms of "squares" with each printed character representing one "square" in size. Theoretically this could be enormous in scope, but given that we're drawing ASCII art, a safe upper limit on this will be 20 so that it fits somewhat decently on screen. - A single letter of
d u r
orl
, indicating the initial movement from the starting "square" (down, up, right, left). - An optional
c
, indicating "counter-clockwise." If thec
is omitted, assume clockwise rotation for the spiral. - A final integer
1 ≤ y ≤ 10
that specifies how many times to recurse the spiral drawing, using the finish "square" of the previous spiral as the starting "square" of the new one. I'm picking an upper limit of 10 because I want the drawing to finish at some point. - A few example inputs:
20lc5
13d2
2rc1
Of interest, do note that odd values for the size input will result in the @
always being the exact center of a spiral, but even values may have the starting "square" offset in any of the four diagonal directions, dependent upon the direction of initial travel. This can result in some ... interesting ... patterns. See the two even examples below.
Input that doesn't follow the input specification (e.g., 11q#s
) is undefined and I fully expect the program to barf appropriately. :)
Output
Output is an ASCII printable output via language-equivalent STDOUT, with the following specifications:
- The starting "square" (of each recursion) must be marked with an at-sign
@
. - The final "square" must be marked with an ampersand
&
. In the case of multiple recursions, only the very final "square" should be marked&
. - Corners of the spiral path need to "point" in the direction of travel, using
< > v ^
. - Vertical travel need to be drawn by pipes
|
. - Horizontal travel needs to be drawn with dashes
-
. - "Squares" that are overwritten by later recursions should display the most-recent direction of travel. This will result in "newer" recursions seeming to be layered on top of the "older" recursions. See the
4rc3
example below. - A final trailing newline is OK, leading spaces could be a must and so are allowed, but trailing spaces are not allowed.
- I won't dock you if you use escape sequences to draw the ASCII art going to STDOUT, but I will be silently disappointed in you. (You'll still be eligible for the bounty if you use them)
Examples
2d4
= diameter of 2, starts by going down, clockwise, 4 recursions
&@@@@
^<<<<
In this example, the drawing starts in the upper-right @
, goes down one, left one, up one. At this point, we've finished the 2d
portion, and so start the 2nd recursion, so we have another @
, down one, left one, up one; then the 3rd recursion; then the 4th and finally our &
.
4rc3
= diameter of 4, starts by going right, counter-clockwise, 3 recursions
&--<
v-<|
|@^|<
>--^|
|@^|<
>--^|
|@^|
>--^
In this example, the drawing starts in the bottom @
, goes right one, up one, spirals around, until it reaches the middle @
and finishes the 4rc
portion. This then repeats two more times to get the full 3 recursions requested. Note that 4rc1
would be just the upper-left 4x4 block of this example.
7u1
= diameter of 7, starts by going up, clockwise, 1 recursion (note the is the same as the intro)
&>----v
||>--v|
|||>v||
|||@|||
||^-<||
|^---<|
^-----<
Winning & Restrictions
This is Code Golf, so smallest answer in bytes wins. Submissions should be in the usual form of program/function/CJam Code Block/etc. Standard Loophole Restrictions Apply. Professional driver on closed course. If irritation persists, discontinue use and consult your doctor.
3
The specifics are quite different, but just for reference, here's an earlier spiral drawing challenge: http://codegolf.stackexchange.com/questions/52494/print-an-ascii-spiral-in-olog-n-memory.
– Reto Koradi – 2015-09-01T14:12:47.3532Nice challenge. +1 for "Professional driver on closed course" – jrich – 2015-09-01T16:23:06.887
3It asks for a ><> answer. – The_Basset_Hound – 2015-09-01T21:35:18.490
With 150 rep at stake, I think you should be clearer about escape sequences. Are they allowed or not? There's no middle point in code golf; we use whatever we can to make out code shorter. – Dennis – 2015-09-04T14:00:31.637
@Dennis Clarified. I meant the "silently judging" in jest, but I can see how it could have been confusing. – AdmBorkBork – 2015-09-04T15:57:52.047
2"C'mon, guys ... are you going to let Common Lisp win out? ;-)" That is the most hilarious reason for a bounty I ever saw. Thanks – coredump – 2015-09-04T17:22:56.263
the requirement with "counter-clockwise" is complicated to parse. but it looks like late for changes. – Jakuje – 2015-09-06T19:19:05.137
@Jakuje Note that the question is quite flexible about the format of inputs: "These parts can be four separate arguments, a quadruple, an array of size 4, etc.". I took advantage of this in my answer. Nice try with Lua, btw. – coredump – 2015-09-09T07:05:38.690
@coredump After writing the comment I realized it is not so complicated with limitation of recursion to 9. Looks like I will have to fight more :) – Jakuje – 2015-09-09T09:09:36.767
1I'm sitting here chuckling that Common Lisp and Lua are the two languages fighting for top spot on a code-golf question. :) – AdmBorkBork – 2015-09-09T13:31:34.560
1@TimmyD A duel of giants. Others are too scared to participate :-) – coredump – 2015-09-09T14:10:04.753
The first example input
22lc5
has22
which is greater than20
. – mbomb007 – 2015-09-10T00:15:01.353@The_Basset_Hound Upon further inspection, I'm not going to try to pump out a ><> answer. The necessary lack of trailing spaces will make it much more difficult. It'd still be a fun challenge, but I'm not going to spend the time on it trying to earn the bounty. If only trailing spaces were allowed, it would be so much easier... – mbomb007 – 2015-09-10T00:30:37.387
@mbomb007 Hah, thanks. I fixed the typo. Also, I explicitly didn't allow trailing spaces, for the precise reason you hit upon. – AdmBorkBork – 2015-09-10T13:05:16.263
aj, trailing spaces. I missed this requirement so I guess I have things to fix in the evening. – Jakuje – 2015-09-10T13:38:15.583