The challenge is to implement a 2-dimensional ray tracing program, text-based.
Sources of white light are @
symbols. R
, G
and B
are light filters. /
and \
are mirrors with 80% reflectivity. ?
is a light sensor. >
, <
, ^
and V
combine light in the appropriate direction (e.g. if one red and one green came into a >
the light would be emitted toward the right and it would be yellow). Other non-whitespace characters absorb all light. Light is emitted from @
symbols in four directions.
When the program is run, it should produce output the same as the input, but with traced rays. Because this is 2 dimensional, and I guarantee in the input no rays will ever cross, there will be no problem with that. Each ray should be represented by a letter; r=red, g=green, b=blue, c=cyan, m=magenta, y=yellow, w=white. There won't be any ternary colors, ever. The casing is important to differentiate it from the input. After that output, the values of light captured by the question marks (in order of their appearance, left to right top to bottom) should be outputted as percentages and colors. For example, this input:
/ @
-
\R> ?
@B/
Should give the output:
/wwwwwwwwwwwwwwwwww@w
w -
w\R>mmmmmmmmmmmmmmmmm?
w b
@B/
#1: 72% Magenta
Another important point to note - when two colors are combined using a "prism" (the arrows) the strength of the combined light becomes the average strength of the two. Output must be exactly as specified (e.g. #x: [x][x]x% Color).
If your language cannot read from STDIN and write to STDOUT, create a function (anonymous or lambda when available) that accepts the input as an argument and returns the result.
Directives to the compiler, structures required or recommended for all or most programs created in the language, etc. can be omitted. For example, #include
and using
directives (but not #define
) may be removed in C-style languages, #/usr/bin/perl -options
in Perl, and
Module Module1
Sub Main()
End Sub
End Module
in VB.NET, for example. If you import namespaces or add include directives, please note them in your answer.
Is that hard enough, now? :)
>
is capturing light which is going straight past it. And if thew
from the top goes through thatR
, so should theb
from the bottom. Finally (I think), you're wrong about rays not crossing. To give a one-line example, what would the correct output be for@R> B@
? \$\endgroup\$@
in the bottom-left emits light in all four directions, doesn't it? So in particular, it emits thatw
. And I haven't broken any spacing, at least as rendered in Chromium. As to going straight past it, my edit may clear that up. \$\endgroup\$