视网膜,293 + 15 = 308 314 385字节
;`\s
_
;`\\
/
;`.+
o$0iio
;+`(o(?=/.*(i)|L.*(ii)|V.*(io)|_)|i(?=/.*(io)|L.*(o)|_.*(ii)|V.*(i))).
$1$2$3$4$5$6$7$8
;`o
<empty>
;`ii$
#:0123456789
;+`^(?=i)(i*)\1{9}(?=#.*(0)|i#.*(1)|ii#.*(2)|iii#.*(3)|iiii#.*(4)|iiiii#.*(5)|iiiiii#.*(6)|iiiiiii#.*(7)|iiiiiiii#.*(8)|iiiiiiiii#.*(9))
$1#$2$3$4$5$6$7$8$9$10$11
:.*|\D
<empty>
每行都在一个单独的文件中,因此我在字节数上增加了13。或者,您可以将所有内容原样放在一个文件中并使用该-s
标志。的<empty>
立场实际上是空文件或线路。
Unfortunately, I need 187 bytes just to convert the result from unary to decimal. I guess I really should implement this some time soon.
Explanation
Retina is a regex-based language (which I wrote exactly for being able to do stuff like this with regex). Each pair of files/lines defines a replacement stage, with the first line being the pattern and the second line the replacement string. Patterns can be preceded by a `
-delimited configuration string, which may contain the usual regex modifiers, as well as some Retina-specific options. For the above program, the relevant options are ;
, which suppresses output of that stage and +
, which applies the replacement in a loop until the result stops changing.
解决方案的想法是分别计算每行,因为我们始终可以根据遇到的字符来确定我们是在多边形内部还是外部。这也意味着我可以将整个对象连接到一条直线中,因为走线的起点和终点总是在多边形之外。我们还可以注意到,_
对于行扫描算法以及\
和,and space完全相同/
。因此,第一步,我将所有换行符和空格_
全部替换为\
通过/
to simplify some code later on.
我使用字符i
和跟踪当前的内部/外部状态o
,同时还使用i
s来计算区域。为此,我首先o
在连接的行之前添加一个,以标记我们在多边形之外。我还将iio
在输入的最后添加一个,用作查找以生成新字符。
Then, the first large replacement simply replaces an i
or o
followed by one of /V_L
with the next set of characters, thereby flooding and tallying the entire thing. The replacement table looks as follows, where the columns correspond to the last character in that line and the rows to the next character (where S
is for space and <>
for an empty string). I've included all characters of the input to show the equivalences I've already made use of:
i o
/ io i
\ io i
L o ii
V i io
_ ii <>
S ii <>
请注意,最后一个字符总是指示在该字符之后是在多边形内部还是外部,而i
s 的数量对应于需要添加到多边形中的区域。作为示例,下面是最后一个示例输入的前四个迭代的结果(这是由一个旧版本生成的,该版本实际上分别淹没了每一行,但是原理仍然相同):
o /V\
o / \___
o L _/
o/\/ /V
oL__ _/
o V
o /V\
o / \___
o L _/
oi\/ /V
oii__ _/
o V
o /V\
o/ \___
oL _/
oiio/ /V
oiiii_ _/
o V
o/V\
oi \___
oii _/
oiioi /V
oiiiiii _/
oV
oiV\
oiii \___
oiiii _/
oiioiii /V
oiiiiiiii_/
oio
最后,我只是去除了所有o
s并通过删除所有匹配的行换行符[^i]
,其余的是十进制到一进制的转换,这很无聊。