Skip to content

Instantly share code, notes, and snippets.

@tminard
tminard / 4.scala
Created December 5, 2019 15:16
advent-of-code-2019
val candidates = Array.range(272091, 815432)
println("Initial digits: " + candidates.size)
val filteredAsc = candidates.map(_.toString.toArray).filter(a => a.sameElements(a.sortBy(_.toInt)))
println("Total digits with ascending order: " + filteredAsc.size)
val filteredDupOnly = filteredAsc.filter(a => a.toSet.size < a.size)
println("Total digits with at least 2 adjacent equal values: " + filteredDupOnly.size)
val filteredDoubleOnly = filteredDupOnly.map(_.groupBy(identity).view.mapValues(_.size)).filter(m => m.exists(_._2 == 2))
@tminard
tminard / 3.scala
Last active December 4, 2019 22:01
advent-of-code-2019
import scala.io.Source
import scala.collection.mutable.ListBuffer
import scala.math.{min,max,abs}
class Point(var x: Int, var y: Int) {
override def toString = "x: " + x + ", y: " + y
override def equals(o: Any) = o match {
case that: Point => that.x == this.x && that.y == this.y
case _ => false
@tminard
tminard / 2.scala
Created December 3, 2019 16:13
advent-of-code-2019
import scala.io.Source
var TAPE = Array.empty[Int]
// Instructions
val OP_ADD = 1
val OP_MUL = 2
val OP_END = 99
// Instruction Pointer