Skip to content

Instantly share code, notes, and snippets.

@JRuumis
JRuumis / Day11MonkeyInTheMiddle.scala
Created December 11, 2022 16:50
Day11 Ruumis Day11 Ruumis
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:
@JRuumis
JRuumis / Day10CRT.scala
Last active December 10, 2022 13:06
Day10 Janis R
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
@JRuumis
JRuumis / Day9RopeBridge.scala
Last active December 9, 2022 13:10
Day9 JR
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 {
@JRuumis
JRuumis / Day9RopeBridge.scala
Created December 9, 2022 12:58
Day9 Janis Cleaned up Day9 Janis cleanup
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 {
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 {
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
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
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!"
}
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 * _)
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 * _)