In this challenge you will write a piece of text which when viewed from two different angles will create two different programs.
Your string as viewed from above must take a string containing only characters ASCII 10, 32 - 126 and output it as viewed from above. Additionally your program when viewed from the left must take a string containing only characters ASCII 10, 32 - 126 and output it as viewed from the left.
A string viewed from above will be the first non-space character in every column of the string, or a space if no such character exists, in the order of the columns.
Here is a Haskell program that implements this:
stitchZip (' ' : b) (c : d) = c : stitchZip b d
stitchZip (a : b) (c : d) = a : stitchZip b d
stitchZip [] x = x
stitchZip x [] = x
main = getContents >>= (putStr . foldr1 stitchZip . lines)
A string viewed from the left will be the first non-space character in every row of the string, or a space if no such character exists, in the reverse order of the rows. We reverse the order of the rows since our left hand would be towards the bottom of the string.
Here is a Haskell program that implements this:
stitch ' ' y = y
stitch x y = x
main = getContents >>= (putStr . reverse . map (foldl stitch ' ') . lines)
Your program may use characters outside of that ASCII range, but for layout purposes all characters (other than newlines) are considered to have a width of 1. As a side effect of how the views work, your programs cannot have newlines in them (although your string almost certainly will).
Scoring
Your score will be the number of non-space characters in your submission plus the number of space characters that appear in the two programs.
For example if your program were:
sc e ex mp e
g
a
r
d
l
o
you would score 16 since there are 14 non whitespace characters in the submission, and each program (score example
and old rags
) has 1 space.
Your goal is to have as low a score as possible.