Skip to content

Instantly share code, notes, and snippets.

@feoktant
Created December 4, 2022 22:13
Show Gist options
  • Save feoktant/7a0939b67d83a0ea90689c7861fae65c to your computer and use it in GitHub Desktop.
Save feoktant/7a0939b67d83a0ea90689c7861fae65c to your computer and use it in GitHub Desktop.
Day4
val InputRegex = "(\\d+)-(\\d+),(\\d+)-(\\d+)".r
def matchFullContain(str: String): Boolean = str match {
case InputRegex(t1, t2, e1, e2) =>
(t1.toInt <= e1.toInt && e2.toInt <= t2.toInt) ||
(e1.toInt <= t1.toInt && t2.toInt <= e2.toInt)
case _ => false
}
def matchOverlap(str: String): Boolean = str match {
case InputRegex(t1, t2, e1, e2) =>
(t2.toInt >= e1.toInt && t1.toInt <= e2.toInt) ||
(t1.toInt <= e2.toInt && e1.toInt <= t2.toInt)
case _ => false
}
val lines = Source.fromResource("day4.txt").getLines()
lines.count(matchFullContain)
lines.count(matchOverlap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment