Name | Language | Tokens Sum | Tokens Part 1 | Tokens Part 2 | Last change | |
---|---|---|---|---|---|---|
1 | Dan Houghton | Python | 10184 | 184 | - | 12 months ago |
import
sys
cells
=
{
complex
(
i
,
j
)
:
c
for
j
,
r
in
enumerate
(
sys
.
stdin
)
for
i
,
c
in
enumerate
(
r
.
strip
(
)
)
}
visited
=
{
}
beams
=
[
(
-
1
,
1
)
]
while
beams
:
pos
,
dir
=
beams
.
pop
(
)
while
dir
not
in
visited
.
setdefault
(
pos
,
[
]
)
:
visited
[
pos
]
.
append
(
dir
)
pos
+=
dir
if
pos
not
in
cells
:
break
c
=
cells
[
pos
]
rotated
=
1j
*
dir
.
conjugate
(
)
if
c
==
"
|
"
:
dir
=
1j
beams
.
append
(
(
pos
,
-
1j
)
)
elif
c
==
"
-
"
:
dir
=
1
beams
.
append
(
(
pos
,
-
1
)
)
elif
c
==
"
/
"
:
dir
=
-
rotated
elif
c
==
"
\\
"
:
dir
=
rotated
print
(
len
(
visited
)
-
1
)