Created
December 4, 2019 14:40
-
-
Save jonathan-ostrander/b3f96df350d39598dcbdc9307f0f8058 to your computer and use it in GitHub Desktop.
AoC Day 4
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
package aoc | |
object Problem04 extends App { | |
println( | |
Some(scala.io.Source.fromResource("inputs/4.txt").getLines.next.split("-").map(_.toInt)) | |
.map(a => | |
(a(0) to a(1)) | |
.map(_.toString.sliding(2).toList) | |
.filter(s => s.exists(p => p(0) == p(1)) && s.forall(p => p(0) <= p(1))) | |
.foldLeft(List(0, 0))((l, s) => | |
l(0) + 1 :: | |
l(1) + (if (s.filter(p => p(0) == p(1)).exists(p => s.filter(_ == p).length == 1)) 1 else 0) :: | |
Nil | |
) | |
) | |
.get | |
.zipWithIndex | |
.map(v => s"Part ${v._2 + 1}: ${v._1}") | |
.mkString("\n") | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment