-
-
Save waynejo/4a2a01cff9b49684814aeff5d872160f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream | |
import scala.io.StdIn | |
@main def solve6() = | |
def solve(answers: Vector[String]): Int = { | |
answers.flatMap(_.toSet).toSet.size | |
} | |
val in = new FileInputStream("example6-1.in") | |
System.setIn(in) | |
val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null).toVector | |
val questions = inputs.foldLeft(Vector[Vector[String]](Vector())) { (acc, line) => | |
if line.trim.isEmpty then | |
acc :+ Vector() | |
else | |
acc.init :+ (acc.last :+ line) | |
} | |
println(questions.map(solve).sum) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream | |
import scala.io.StdIn | |
@main def solve6() = | |
def solve(answers: Vector[String]): Int = { | |
answers.map(_.toSet).reduce(_ intersect _).size | |
} | |
val in = new FileInputStream("example6-1.in") | |
System.setIn(in) | |
val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null).toVector | |
val questions = inputs.foldLeft(Vector[Vector[String]](Vector())) { (acc, line) => | |
if line.trim.isEmpty then | |
acc :+ Vector() | |
else | |
acc.init :+ (acc.last :+ line) | |
} | |
println(questions.map(solve).sum) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment