Today's puzzle made me come up with a monster: `in...

# advent-of-codel

Leon Linhart

12/03/2019, 2:16 PMToday's puzzle made me come up with a monster:

`intersectAllBy`

https://github.com/TheMrMilchmann/AdventOfCode2019/blob/f42664c0330b1ba9010c6aac498d79d4fb094489/src/main/kotlin/day03/part2/main.kt#L67k

Kroppeb

12/03/2019, 2:54 PMI don't understand what it's doing

l

Leon Linhart

12/03/2019, 3:03 PMIt basically calculates the intersection of an arbitrary number of sets based on part of their elements. (Well that doesn't make it any better, does it? Here, an example using simple math terms:)
Let

`X = {(A, 1), (A, 2), (B, 1)}`

and `Y = {(A, 3), (B, 5), (C, 2)}`

Here, obviously no two elements of `X`

and `Y`

are equal and thus the intersection is empty, but `X.intersectBy(Y) { it.LETTER }`

would yield `{(A, 1), (A, 2), (A, 3), (B, 1), (B, 5)}`

.
At first I thought the second part would require us to deal with more than two wires so I wrote `intersectAll`

and `intersectAllBy`

to calculate the intersection of an abritrary sequence of sets.2 Views