Name | Language | Tokens Sum | Tokens Part 1 | Tokens Part 2 | Last change | |
---|---|---|---|---|---|---|
1 | CornerMercury | Python | 290 | 145 | 145 | 38 days ago |
2 | dbasden | Python | 307 | 137 | 170 | 38 days ago |
3 | Mechazawa | JavaScript | 10143 | 143 | - | 37 days ago |
import
sys
fat
=
[
int
(
c
)
for
c
in
sys
.
stdin
.
read
(
)
.
strip
(
)
]
blockmap
=
[
None
]
*
sum
(
fat
)
pos
=
0
for
i
,
blocks
in
enumerate
(
fat
)
:
if
(
i
&
1
)
==
0
:
fileid
=
i
>>
1
blockmap
[
pos
:
pos
+
blocks
]
=
[
fileid
]
*
blocks
pos
+=
blocks
while
True
:
while
blockmap
[
-
1
]
is
None
:
blockmap
.
pop
(
)
try
:
next_free
=
blockmap
.
index
(
None
)
except
ValueError
:
break
blockmap
[
next_free
]
=
blockmap
.
pop
(
)
print
(
sum
(
a
*
b
for
a
,
b
in
enumerate
(
blockmap
)
)
)