Challenge
The shortest program by character count that accepts standard input of the form X-Y R, with the following guarantees:
Ris a non-negative decimal number less than or equal to 8XandYare non-negative angles given in decimal as multiples of 45° (0,45,90,135, etc.)Xis less thanYYis not360ifXis0
And produces on standard output an ASCII "arc" from the starting angle X to the ending angle Y of radius R, where:
- The vertex of the arc is represented by
o - Angles of
0and180are represented by- - Angles of
45and225are represented by/ - Angles of
90and270are represented by| - Angles of
135and315are represented by\ - The polygonal area enclosed by the two lines is filled with a non-whitespace character.
The program is not required to produce meaningful output if given invalid input. Solutions in any language are allowed, except of course a language written specifically for this challenge, or one that makes unfair use of an external utility. Extraneous horizontal and vertical whitespace is allowed in the output provided that the format of the output remains correct.
Happy golfing!
Numerous Examples
Input:
0-45 8
Output:
/
/x
/xx
/xxx
/xxxx
/xxxxx
/xxxxxx
/xxxxxxx
o--------
Input:
0-135 4
Output:
\xxxxxxxx
\xxxxxxx
\xxxxxx
\xxxxx
o----
Input:
180-360 2
Output:
--o-- xxxxx xxxxx
Input:
45-90 0
Output:
o
Input:
0-315 2
Output:
xxxxx xxxxx xxo-- xxx\ xxxx\
Perl,
235 211 225 211 207 196 179 177 175 168 160 156146 charsPerl using say feature,
161 149139 charsPerl without trailing newline,
153143 charsOriginal version commented:
EDIT 1: Inlined sub, relational and equality operators return 0 or 1.
EDIT 2: Added version with comments.
EDIT 3: Fixed enclosing line at 360º. Char count increased significantly.
EDIT 4: Added a shorter version, bending the rules.
EDIT 5: Smarter fix for the 360º enclosing line. Also, use a number as fill. Both things were obvious. Meh, I should sleep more :/
EDIT 6: Removed unneeded
mfrom match operator. Removed some semicolons.EDIT 7: Smarter regexp. Under 200 chars!
EDIT 8: Lots of small improvements:
splitstring -> qw (3 chars)EDIT 9: A little reordering in the conditional operators saves 2 chars.
EDIT 10: Use barewords for characters.
EDIT 11: Moved print inside of loop, inspired by Lowjacker's answer.
EDIT 12: Added version using
say.EDIT 13: Reuse angles characters for fill character, as Gwell's answer does. Output isn't as nice as Gwell's though, that would require 5 additional chars :) Also, .. operator doen't need parentheses.
EDIT 14: Apply regex directly to <>. Assign range operator to a variable, as per Adrian's suggestion to bta's answer. Add version without the final newline. Updated
sayversion.EDIT 15: More inlining. map{block}@a -> map expr,@a.