Skip to content

Instantly share code, notes, and snippets.

@jonathan-ostrander
Created December 4, 2019 14:40
Show Gist options
  • Save jonathan-ostrander/b3f96df350d39598dcbdc9307f0f8058 to your computer and use it in GitHub Desktop.
Save jonathan-ostrander/b3f96df350d39598dcbdc9307f0f8058 to your computer and use it in GitHub Desktop.
AoC Day 4
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