Created
December 4, 2022 22:13
-
-
Save feoktant/7a0939b67d83a0ea90689c7861fae65c to your computer and use it in GitHub Desktop.
Day4
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
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