Post History
Scala 3, 68 bytes _.zipWithIndex.flatMap(_.zipWithIndex.filter(_._1)map(_._2)map _.->) Try it in Scastie! Takes a List[List[Boolean]], returns a List[(Int, Int)]. This abuses underscores a ...
Answer
#2: Post edited
- # Scala 3, 68 bytes
- ```scala
- _.zipWithIndex.flatMap(_.zipWithIndex.filter(_._1)map(_._2)map _.->)
- ```
- [Try it in Scastie!](https://scastie.scala-lang.org/RDjAuL1cTmqhAmtlwpIJRQ)
Takes a `List[List[Boolean]]`, returns a `List[(Int, Int)]`.- Explanation:
- ```scala
- _.zipWithIndex //Zip each row with its index
- .flatMap( //Map every (row, index) tuple to a list of truthy indices,
- //then flatten
- _.zipWithIndex //Zip each element with its column
- .filter(_._1) //Keep the tuples where the element (_1) is true
- map(_._2) //Keep the second part of the tuple (the column)
- map _.->) //Make a 2-tuple with the row's index
- ```
- # Scala 3, 68 bytes
- ```scala
- _.zipWithIndex.flatMap(_.zipWithIndex.filter(_._1)map(_._2)map _.->)
- ```
- [Try it in Scastie!](https://scastie.scala-lang.org/RDjAuL1cTmqhAmtlwpIJRQ)
- Takes a `List[List[Boolean]]`, returns a `List[(Int, Int)]`. This abuses underscores a bit (which is why Scala 3 is needed), but I'm proud of it.
- Explanation:
- ```scala
- _.zipWithIndex //Zip each row with its index
- .flatMap( //Map every (row, index) tuple to a list of truthy indices,
- //then flatten
- _.zipWithIndex //Zip each element with its column
- .filter(_._1) //Keep the tuples where the element (_1) is true
- map(_._2) //Keep the second part of the tuple (the column)
- map _.->) //Make a 2-tuple with the row's index
- ```
#1: Initial revision
# Scala 3, 68 bytes ```scala _.zipWithIndex.flatMap(_.zipWithIndex.filter(_._1)map(_._2)map _.->) ``` [Try it in Scastie!](https://scastie.scala-lang.org/RDjAuL1cTmqhAmtlwpIJRQ) Takes a `List[List[Boolean]]`, returns a `List[(Int, Int)]`. Explanation: ```scala _.zipWithIndex //Zip each row with its index .flatMap( //Map every (row, index) tuple to a list of truthy indices, //then flatten _.zipWithIndex //Zip each element with its column .filter(_._1) //Keep the tuples where the element (_1) is true map(_._2) //Keep the second part of the tuple (the column) map _.->) //Make a 2-tuple with the row's index ```