64
9
The title says it all. Your goal is to write a program that forms a w×h rectangle of characters that can be rotated and re-run to output the number of 90° Counter-Clockwise (CCW) rotations that have been done.
For example, if the 3×2 program
abc
def
solved the problem, it would initially output 0, and successive rotations of 90° CCW
cf fed da
be cba eb
ad fc
would output 1, 2, and 3 respectively.
Using comments makes this a trivial task is most languages. In Ruby for example, it can be done in a 7×7 rectangle:
###p###
### ###
###1###
p 0#2 p
###3###
### ###
###p###
The challenge is to do this without any sort of comments.
Scoring
Your score is w*h, the area of your rectangle. Newlines are excluded. In other words, code-golf, newlines not counted.
The score for the Ruby example is 49 (though of course it is invalid since it has comments).
Notes
- Your code must really be rectangular with no missing characters at the end of lines.
- If you wish you may output other legal "mod 90°" values instead of 0 1 2 3. So 8 is fine instead of 0, and -1 is fine instead of 3, etc.
- The output may go to the console or into a file.
- Standard loopholes apply.
I hope this, my first question, really intrigues some people. Enjoy!
I think since a 0x0 rectangle has no well-defined rotation, any output is acceptable--including the null output (e.g. what the Python program `` would output). – imallett – 2015-02-05T07:51:49.333
1To be more specific about what a comment is, is a comment any unevaluated code? Unparsed code? – isaacg – 2014-07-08T21:59:47.833
I mean that none of your language's traditional "comment characters" should appear in any of the 4 rotated versions. So for C++, two slashes next to each other should never appear, though one may be used alone. Likewise with /*. I hope that clarifies it. – Calvin's Hobbies – 2014-07-08T22:09:51.837
What about languages that do not have comment characters? – isaacg – 2014-07-08T22:19:22.003
So code like
echo 0;exit;e
in bash is allowed? – jimmy23013 – 2014-07-08T22:22:13.833If there is no way to comment then you needn't worry. @user23013 That bash is fine. – Calvin's Hobbies – 2014-07-08T22:40:53.393
can the program throw errors/exceptions after outputting the answer? – xem – 2014-07-09T07:42:45.990
@xem I don't think so. The program should be syntactically legal and be able to run without errors any way it is rotated. – Calvin's Hobbies – 2014-07-09T07:50:24.660
fair enough. I posted my JS solution (score=9) without error :) – xem – 2014-07-09T08:13:00.420
edit: JS score = 4 – xem – 2014-07-09T09:05:28.467