Name | Language | Tokens Sum | Tokens Part 1 | Tokens Part 2 | Last change | |
---|---|---|---|---|---|---|
1 | CornerMercury | Python | 269 | 102 | 167 | 42 days ago |
2 | dbasden | C | 561 | 251 | 310 | 42 days ago |
3 | Szabolcs Dombi | Python | 10141 | 141 | - | 42 days ago |
4 | Mechazawa | JavaScript | 10206 | 206 | - | 38 days ago |
5 | Tomáš Mach | Python | 10234 | 234 | - | 42 days ago |
#include
<stdio.h>
typedef
struct
{
int
i
;
int
j
;
}
pos_t
;
#define
ELFOFF
[
elf_pos
.
i
]
[
elf_pos
.
j
]
#define
gij
grid
[
i
]
[
j
]
char
grid
[
256
]
[
256
]
;
int
width
,
part_2_result
,
i
,
j
;
pos_t
elf_start_pos
,
oob
;
int
evi
[
4
]
=
{
-1
,
0
,
1
}
,
evj
[
4
]
=
{
0
,
1
,
0
,
-1
}
;
int
does_guard_loop
(
)
{
int
vec_idx
=
0
;
int
visited
[
256
]
[
256
]
[
4
]
=
{
}
;
pos_t
elf_pos
=
elf_start_pos
;
while
(
grid
ELFOFF
)
{
if
(
visited
ELFOFF
[
vec_idx
]
)
return
1
;
visited
ELFOFF
[
vec_idx
]
=
1
;
pos_t
forward
=
(
pos_t
)
{
elf_pos
.
i
+
evi
[
vec_idx
]
,
elf_pos
.
j
+
evj
[
vec_idx
]
}
;
if
(
grid
[
forward
.
i
]
[
forward
.
j
]
!=
35
&&
!
(
forward
.
i
==
i
&&
forward
.
j
==
j
)
)
elf_pos
=
forward
;
else
vec_idx
=
(
vec_idx
+
1
)
&
3
;
}
return
0
;
}
int
main
(
)
{
while
(
scanf
(
"
%
s
%
n
"
,
&
(
grid
[
++
i
]
[
0
]
)
,
&
width
)
==
1
)
for
(
j
=
0
;
j
<
width
;
++
j
)
if
(
gij
==
94
)
elf_start_pos
=
(
pos_t
)
{
i
,
j
}
;
for
(
i
=
1
;
i
<
width
;
++
i
)
for
(
j
=
0
;
j
<
width
;
++
j
)
part_2_result
+=
gij
!=
94
&&
does_guard_loop
(
)
;
printf
(
"
%
d
\
n
"
,
part_2_result
)
;
}