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
import scala.io.Source | |
var TAPE = Array.empty[Int] | |
// Instructions | |
val OP_ADD = 1 | |
val OP_MUL = 2 | |
val OP_END = 99 | |
// Instruction Pointer |
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
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 |
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 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)) |