221 tokens in Kotlin for part 1 by Valentin Slawicek
Download solution
data
class
Grab
(
val
red
:
Int
,
val
green
:
Int
,
val
blue
:
Int
)
fun
main
(
)
=
println
(
generateSequence
(
::
readLine
)
.
sumOf
{
line
->
val
gameId
=
line
.
substringBefore
(
"
:
"
)
.
substringAfter
(
"
"
)
.
toInt
(
)
val
games
=
line
.
substringAfter
(
"
:
"
)
.
split
(
"
;
"
)
.
map
{
gameString
->
val
red
=
gameString
.
substringBefore
(
"
r
e
d
"
)
.
substringAfterLast
(
"
"
)
.
toIntOrNull
(
)
?:
0
val
green
=
gameString
.
substringBefore
(
"
g
r
e
e
n
"
)
.
substringAfterLast
(
"
"
)
.
toIntOrNull
(
)
?:
0
val
blue
=
gameString
.
substringBefore
(
"
b
l
u
e
"
)
.
substringAfterLast
(
"
"
)
.
toIntOrNull
(
)
?:
0
return@
Grab
(
red
,
green
,
blue
)
}
return@
if
(
games
.
all
{
it
.
red
<=
12
}
&&
games
.
all
{
it
.
green
<=
13
}
&&
games
.
all
{
it
.
blue
<=
14
}
)
{
gameId
}
else
{
0
}
}
)