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.annotation.tailrec | |
object Day11MonkeyInTheMiddle extends App { | |
// -= Item =- | |
// Item used to be `type Item = Long` for Part 1. | |
class Item(val divisions: Map[Int, Int]) { | |
override def toString: String = s"Item(${divisions})" | |
// Part 2 logic: |
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.annotation.tailrec | |
object Day10CRT extends App { | |
val commandsInput = scala.io.Source.fromFile("./Sources/Day10CRT.txt").getLines().toVector | |
abstract class Command { | |
val totalCommandExecutionCycles: Int | |
val increaseRegistryBy: Int | |
def isAtLastCommandCycleWith(commandCycle: Int): Boolean = commandCycle == totalCommandExecutionCycles |
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.annotation.tailrec | |
import scala.math.abs | |
object Day9RopeBridge extends App { | |
val ropeStepsInput = scala.io.Source.fromFile("./Sources/Day9RopeBridge.txt").getLines() | |
case class Move(deltaX: Int, deltaY: Int) | |
val moves: List[Move] = ropeStepsInput.map(_.split(" ").toList).map{_ match { |
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.annotation.tailrec | |
import scala.math.abs | |
object Day9RopeBridge extends App { | |
val ropeStepsInput = scala.io.Source.fromFile("./Sources/Day9RopeBridge.txt").getLines() | |
case class Move(moveX: Int, moveY: Int) | |
val moves: List[Move] = ropeStepsInput.map(_.split(" ").toList).map{_ match { |
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.annotation.tailrec | |
import scala.math.abs | |
object Day9RopeBridge extends App { | |
val ropeStepsInput = scala.io.Source.fromFile("./Sources/Day9RopeBridge.txt").getLines() | |
case class Move(moveX: Int, moveY: Int) | |
val moves: List[Move] = ropeStepsInput.map(_.split(" ").toList).map{_ match { |
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.annotation.tailrec | |
object Day8TreetopTreeHouse extends App { | |
val forestInput: List[List[Int]] = scala.io.Source.fromFile("./Sources/Day8TreetopTreeHouse.txt").getLines().toList.map(_.toList.map(_.asDigit)) | |
// Part 1 | |
val forestWithCoords = forestInput.map(_.zipWithIndex).transpose.map(_.zipWithIndex).transpose.map(l => l.map {case( ((t,x),y) ) => (t,x,y)}) | |
@tailrec |
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.annotation.tailrec | |
object Day7NoSpaceOnDevice extends App { | |
val fileSystemBrowseContent = scala.io.Source.fromFile("./Sources/Day7NoSpaceOnDevice.txt").getLines().toList | |
val folderNamePattern = "\\$ cd ([0-9a-zA-Z_/.]+)".r | |
val fileNamePattern = "([0-9]+) ([0-9a-zA-Z_/.]+)".r | |
@tailrec |
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
object Day6TuningTrouble extends App { | |
val tuningInput: List[Char] = scala.io.Source.fromFile("./Sources/Day6TuningTrouble.txt").toList | |
def tuner(stream: List[Char], currentPosition: Int, sampleSize: Int): String = stream match { | |
case a if a.size >= sampleSize && a.take(sampleSize).toSet.size == sampleSize => s"First position with sample size ${sampleSize} detected at ${currentPosition}" | |
case a :: rest => tuner(rest, currentPosition+1, sampleSize) | |
case _ => s"Error! Packet with sample size ${sampleSize} not detected!" | |
} |
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
object Day5SupplyStacks extends App { | |
val stacksAndMovesInput: Array[String] = scala.io.Source.fromFile("./Sources/Day5SupplyStacks.txt").getLines().toArray | |
val lastStacksLine: Int = 8 | |
val firstmoveLine: Int = 11 | |
val numberOfInputStacks: Int = 9 | |
val inputStackElementPositions = (0 to numberOfInputStacks-1).map(1 + 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
object Day5SupplyStacks extends App { | |
val stacksAndMovesInput: Array[String] = scala.io.Source.fromFile("./Sources/Day5SupplyStacks.txt").getLines().toArray | |
val lastStacksLine: Int = 8 | |
val firstmoveLine: Int = 11 | |
val numberOfInputStacks: Int = 9 | |
val inputStackElementPositions = (0 to numberOfInputStacks-1).map(1 + 4 * _) | |