import java.io.File
//TIP Press twice to open the Search Everywhere dialog and type show whitespaces,
// then press . You can now see whitespace characters in your code.
fun main() {
val file = File("b.input").readLines();
val pairsOfSets = file.map {
Pair(it.substringBefore(","), it.substringAfter(","))
};
val number = pairsOfSets.filter { (a, b) -> cntains(parseRange(a), parseRange(b)) }.count();
println("The number of contained sets is $number");
val number2 = pairsOfSets.filter { (a, b) -> overlaps(parseRange(a), parseRange(b)) }.count();
println("The number of overlapping sets is $number2");
}
fun cntains(a:Pair, b:Pair): Boolean {
return ((a.first <= b.first) and (a.second >= b.second)) or
((b.first <= a.first) and (b.second >= a.second));
}
fun overlaps(a:Pair, b:Pair): Boolean {
return (a.first in b.first..b.second) or (a.second in b.first..b.second) or cntains(a,b);
}
fun parseRange(a:String): Pair {
return Pair(a.substringBefore("-").toInt(),a.substringAfter("-").toInt());
}