162 tokens in Kotlin for part 2 by Fabian Schedler
Download solution
fun
main
(
)
=
println
(
generateSequence
(
::
readLine
)
.
toList
(
)
.
run
{
val
rowsToExpand
=
indices
.
filter
{
y
->
'
#
'
!in
this
[
y
]
}
val
columnsToExpand
=
indices
.
filter
{
x
->
none
{
it
[
x
]
==
'
#
'
}
}
flatMapIndexed
{
y
,
row
->
row
.
mapIndexedNotNull
{
x
,
value
->
if
(
value
!=
'
#
'
)
null
else
y
+
rowsToExpand
.
count
{
it
<
y
}
*
999_999
L
to
x
+
columnsToExpand
.
count
{
it
<
x
}
*
999_999
L
}
}
.
run
{
flatMap
{
map
(
it
::
to
)
}
}
.
sumOf
{
it
.
run
{
Math
.
abs
(
first
.
first
-
second
.
first
)
+
Math
.
abs
(
first
.
second
-
second
.
second
)
}
}
/
2
}
)