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.util.matching.Regex | |
object Day2CubeConundrum extends App { | |
// Cube RGB | |
case class CubeReveal(red: Int, green: Int, blue: Int) { | |
lazy val isValid: Boolean = red <= CubeReveal.redMax && green <= CubeReveal.greenMax && blue <= CubeReveal.blueMax | |
lazy val cubePower: Int = red * green * blue | |
def minRequiredCubes(other: CubeReveal): CubeReveal = CubeReveal(this.red max other.red, this.green max other.green, this.blue max other.blue) |
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 Day1Trebuchet2 extends App { | |
val calibrations: Vector[String] = scala.io.Source.fromFile("./Sources/2023/Day1Trebuchet.txt").getLines().toVector | |
case class Digit(digitString: String, digitInt: Int) | |
val allDigitsPartOne: Vector[Digit] = Vector( | |
Digit("1", 1), | |
Digit("2", 2), | |
Digit("3", 3), | |
Digit("4", 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
import scala.util.matching.Regex | |
object Day19Robots2 extends App { | |
val blueprintsRaw = scala.io.Source.fromFile("./Sources/Day19Robots_TEST.txt").getLines().toVector | |
val blueprintPattern: Regex = """Blueprint ([0-9]+): Each ore robot costs ([0-9]+) ore. Each clay robot costs ([0-9]+) ore. Each obsidian robot costs ([0-9]+) ore and ([0-9]+) clay. Each geode robot costs ([0-9]+) ore and ([0-9]+) obsidian.""".r | |
abstract class Resources { | |
val ore: Int | |
val clay: Int |
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 Day24Blizzard extends App { | |
val blizzardRaw: Vector[Vector[Char]] = scala.io.Source.fromFile("./Sources/Day24Blizzard.txt").getLines().toVector.map(_.toVector) | |
val blizzardWithoutLF = blizzardRaw.map(r => r.slice(1, r.length-1)) | |
val gridBody: Vector[Vector[Char]] = blizzardWithoutLF.slice(1, blizzardWithoutLF.length-1) | |
val gridX: Int = gridBody(0).length | |
val gridY: Int = gridBody.length |
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
def gridReach(inputGrid: Grid, currentFront: Set[Coord], accuRocksToKeep: Set[Coord]): Set[Coord] = { | |
if(currentFront.isEmpty) accuRocksToKeep | |
else { | |
val neigboursToCheck: Set[Coord] = currentFront.flatMap(c => c.neighbours) | |
val checkedNeighbours: Set[(Coord, Char)] = neigboursToCheck.map(c => (c,gridGet(inputGrid,c)) match { | |
case (_, None) => None | |
case (_, Some('f')) => None | |
case (_, Some('w')) => None | |
case (c, Some('.')) => Some((c,'f')) |
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.util.matching.Regex | |
object Day16Valves extends App { | |
val valvesInputRaw: Vector[String] = scala.io.Source.fromFile("./Sources/Day16Valves.txt").getLines.toVector | |
val valvesPattern: Regex = "Valve ([A-Z][A-Z]) has flow rate=([0-9]+); tunnel(?:[s]?) lead(?:[s]?) to valve(?:[s]?) ([A-Z, ]+)".r | |
val valvesParsed: Vector[(String, Int, Vector[String])] = valvesInputRaw.map(vr => vr match { | |
case valvesPattern(v, r, ov) => (v, r.toInt, ov.split(", ").toVector) |
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 | |
import scala.util.matching.Regex | |
object Day15Beacons extends App { | |
type DimCoord = Long | |
//val checkY: DimCoord = 10 // TEST | |
//val searchSpaceMax: Long = 20 // TEST |
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 Day14DropSand extends App { | |
// -= Coordinates and Grid =- | |
type DimCoord = Int | |
case class Coord(x: DimCoord, y: DimCoord) { | |
def up: Coord = Coord(x, y - 1) | |
def down: Coord = Coord(x, y + 1) |
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.util.parsing.combinator._ | |
object Day13DistressSignal extends App { | |
// -= Packet =- | |
abstract class PacketData | |
case class PacketInteger(integer: Int) extends PacketData { | |
override def toString: String = integer.toString | |
} |
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 Day12HillClimbing extends App { | |
val startGrid = scala.io.Source.fromFile("./Sources/Day12HillClimbing.txt").getLines().toVector.map(_.toVector) | |
val sizeY = startGrid.length | |
val sizeX = startGrid(0).length | |
val startPosition: (Int, Int) = (0 to sizeY-1).flatMap(y => (0 to sizeX-1).map(x => if(startGrid(y)(x)== 'S') Some(y,x) else None )).filter(_.isDefined).map(_.get)(0) |
NewerOlder