Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2015/src/main/scala/aoc2015/Day03.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2015

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

object Day03 extends AoC:

Expand Down
2 changes: 2 additions & 0 deletions 2015/src/main/scala/aoc2015/Day11.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ object Day11 extends AoC:
case Zero extends Carry(0x00)
case One extends Carry(value = 0x01)

given CanEqual[Carry, Carry] = CanEqual.derived

val MinValue: Char = 'a'
val MaxValue: Char = 'z'
val ValueRange: Char = (MaxValue - MinValue + 1).toChar
Expand Down
2 changes: 2 additions & 0 deletions 2015/src/main/scala/aoc2015/Day12.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ object Day12 extends AoC:
case class Num(underlying: Long) extends Json
case class Arr(underlying: List[Json]) extends Json
case class Obj(underlying: Map[String,Json]) extends Json

given CanEqual[Json, Json] = CanEqual.derived

def solve(json: Json, objValueFilter: Json => Boolean = _ => true): Long =
def loop(acc: Long, json: Json): Long =
Expand Down
6 changes: 4 additions & 2 deletions 2015/src/main/scala/aoc2015/Day21.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Day21 extends AoC:
object Player:
def equip(points: Int, weapon: Weapon, armor: Option[Armor], rings: Seq[Ring]): Player =
assert(rings.size <= 2, "max 2 rings")
assert(rings == rings.distinct, "max one of a kind")
assert((rings diff rings.distinct).isEmpty, "max one of a kind")
Player( points = points
, damage = weapon.damage + rings.map(_.damage).sum
, armor = armor.map(_.armor).getOrElse(0) + rings.map(_.armor).sum
Expand Down Expand Up @@ -41,6 +41,8 @@ object Day21 extends AoC:
enum Outcome:
case Won
case Lost

given CanEqual[Outcome, Outcome] = CanEqual.derived

case class Game(player: Player, boss: Player):
import Outcome.*
Expand All @@ -67,7 +69,7 @@ object Day21 extends AoC:
w <- Weapon.values.toList
a <- Armor.values.toList.map(Option(_)) :+ Option.empty[Armor]
rs <- Ring.values.toList.map(List(_)) ++ Ring.values.toList.combinations(2) ++ List(List.empty[Ring])
if rs == rs.distinct
if (rs diff rs.distinct).isEmpty
yield
Player.equip(100, w, a, rs)

Expand Down
2 changes: 2 additions & 0 deletions 2015/src/main/scala/aoc2015/Day22.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object Day22 extends AoC:
case Recharge extends Spell(229, 5)

import Spell.*

given CanEqual[Spell, Spell] = CanEqual.derived

val Spells = Set(MagicMissile, Drain, Shield, Poison, Recharge)

Expand Down
2 changes: 1 addition & 1 deletion 2016/src/main/scala/aoc2016/Day01.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2016

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}
import scala.annotation.tailrec
import scala.util.Try

Expand Down
4 changes: 4 additions & 0 deletions 2016/src/main/scala/aoc2016/Day10.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aoc2016

import nmcb.*

import scala.CanEqual.derived
import scala.collection.mutable

object Day10 extends AoC:
Expand All @@ -10,6 +12,8 @@ object Day10 extends AoC:
case Out(override val index: Int) extends Target(index)

import Target.*

given CanEqual[Target, Target] = CanEqual.derived

enum Inst:
case Init(bot: Bot, value: Int)
Expand Down
2 changes: 1 addition & 1 deletion 2016/src/main/scala/aoc2016/Day13.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2016

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import scala.collection.*
import scala.collection.immutable.Map
Expand Down
2 changes: 1 addition & 1 deletion 2016/src/main/scala/aoc2016/Day17.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package aoc2016

import nmcb.*
import nmcb.predef.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import java.security.MessageDigest
import scala.collection.*
Expand Down
6 changes: 4 additions & 2 deletions 2016/src/main/scala/aoc2016/Day22.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2016

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

object Day22 extends AoC:

Expand All @@ -16,6 +16,8 @@ object Day22 extends AoC:
else if isMassive then '#'
else '.'

given CanEqual[Node, Node] = CanEqual.derived

val nodes: Map[Pos,Node] =
lines
.filter(_.startsWith("/dev/grid/node"))
Expand All @@ -24,7 +26,7 @@ object Day22 extends AoC:
Pos.of(x, y) -> Node(used, avail)
.toMap

def viable(nodes: Map[Pos,Node]): Vector[(Node,Node)] =
def viable(nodes: Map[Pos, Node]): Vector[(Node, Node)] =
for
(_,a) <- nodes.toVector
(_,b) <- nodes.toVector
Expand Down
2 changes: 1 addition & 1 deletion 2016/src/main/scala/aoc2016/Day24.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2016

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

object Day24 extends AoC:

Expand Down
2 changes: 1 addition & 1 deletion 2017/src/main/scala/aoc2017/Day03.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2017

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}
import nmcb.predef.*

import scala.annotation.tailrec
Expand Down
2 changes: 2 additions & 0 deletions 2017/src/main/scala/aoc2017/Day06.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ object Day06 extends AoC:
loop(next, seen :+ current)
loop(this)

given CanEqual[Area, Area] = CanEqual.derived

override lazy val answer1: Int =
Area(banks).redistribute.size - 1

Expand Down
2 changes: 2 additions & 0 deletions 2017/src/main/scala/aoc2017/Day11.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ object Day11 extends AoC:
case NW

import Dir.*

given CanEqual[Dir, Dir] = CanEqual.derived

case class Hex(x: Int, y: Int, z: Int):
assert(x + y + z == 0)
Expand Down
2 changes: 1 addition & 1 deletion 2017/src/main/scala/aoc2017/Day14.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2017

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import Day10.KnotHash
import Day12.Dijkstra
Expand Down
2 changes: 1 addition & 1 deletion 2017/src/main/scala/aoc2017/Day19.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2017

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import scala.annotation.tailrec

Expand Down
4 changes: 3 additions & 1 deletion 2017/src/main/scala/aoc2017/Day22.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2017

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}
import nmcb.predef.*

object Day22 extends AoC:
Expand All @@ -10,6 +10,8 @@ object Day22 extends AoC:
case Clean, Infected, Weakened, Flagged

import Status.*

given CanEqual[Status, Status] = CanEqual.derived

case class Carrier(nodes: Map[Pos,Status], current: Pos, dir: Dir, infected: Int = 0):

Expand Down
2 changes: 2 additions & 0 deletions 2017/src/main/scala/aoc2017/Day25.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ object Day25 extends AoC:
case L, R

import Move.*

given CanEqual[Move, Move] = CanEqual.derived

type State = String
type Value = Int
Expand Down
2 changes: 2 additions & 0 deletions 2017/src/test/scala/aoc2017/Test2017.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package aoc2017
import org.scalatest.funsuite.AnyFunSuite

class Test2017 extends AnyFunSuite:

given CanEqual[Any, Any] = CanEqual.derived

test("Day 1: Inverse Captcha"):
assertResult(1069)(Day01.answer1)
Expand Down
3 changes: 3 additions & 0 deletions 2018/src/main/scala/aoc2018/Day02.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ object Day02 extends AoC:
idLettersWith(3) >= 1

object Box:

given CanEqual[Box, Box] = CanEqual.derived

val IdCharSet: String = "abcdefghijklmnopqrstuvwxyz"
def fromString(id: String): Box = Box(id)

Expand Down
2 changes: 1 addition & 1 deletion 2018/src/main/scala/aoc2018/Day03.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

object Day03 extends AoC:

Expand Down
2 changes: 2 additions & 0 deletions 2018/src/main/scala/aoc2018/Day04.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object Day04 extends AoC:

import Event.*

given CanEqual[Event, Event] = CanEqual.derived

type Timestamp = String

case class Record(timestamp: Timestamp, event: Event):
Expand Down
2 changes: 1 addition & 1 deletion 2018/src/main/scala/aoc2018/Day06.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import scala.collection.+:
import scala.collection.immutable.Vector
Expand Down
2 changes: 1 addition & 1 deletion 2018/src/main/scala/aoc2018/Day10.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import scala.annotation.*
import scala.math.Integral.Implicits.*
Expand Down
2 changes: 1 addition & 1 deletion 2018/src/main/scala/aoc2018/Day11.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import scala.collection.*

Expand Down
2 changes: 2 additions & 0 deletions 2018/src/main/scala/aoc2018/Day13.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ object Day13 extends AoC:
case Straight => Right
case Right => Left

given CanEqual[Turn, Turn] = CanEqual.derived

case class Cart(pos: Pos, dir: Dir, atIntersection: Turn = Turn.Left):

def move(grid: Grid): Cart =
Expand Down
9 changes: 6 additions & 3 deletions 2018/src/main/scala/aoc2018/Day15.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

import scala.annotation.tailrec
import scala.util.Try
Expand All @@ -22,10 +22,13 @@ object Day15 extends AoC:

import FighterType.*

given CanEqual[FighterType, FighterType] = CanEqual.derived

case class Fighter(fighterType: FighterType, pos: Pos, hitPoints: Int = 200, attackPower: Int = 3)

given Ordering[Pos] = Ordering.by(_.toTuple.swap)
given Ordering[Fighter] = Ordering.by(_.pos)
given Ordering[Pos] = Ordering.by(_.toTuple.swap)
given Ordering[Fighter] = Ordering.by(_.pos)
given CanEqual[Fighter, Fighter] = CanEqual.derived

def targetsOf(fighter: Fighter)(using fighters: List[Fighter]): Set[Fighter] =
fighters.filter(_.fighterType == fighter.fighterType.target).toSet
Expand Down
2 changes: 2 additions & 0 deletions 2018/src/main/scala/aoc2018/Day16.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ object Day16 extends AoC:
case EQRI => mem.setRI(a, b, c, (a: Int) => (b: Int) => if a == b then 1 else 0)
case EQRR => mem.setRR(a, b, c, (a: Int) => (b: Int) => if a == b then 1 else 0)

given CanEqual[Inst, Inst] = CanEqual.derived

type Test = (Mem, Codes, Mem)

extension (test: Test)
Expand Down
4 changes: 3 additions & 1 deletion 2018/src/main/scala/aoc2018/Day17.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}

object Day17 extends AoC:

Expand All @@ -16,6 +16,8 @@ object Day17 extends AoC:
case Stopped
case Flowing

given CanEqual[Stream, Stream] = CanEqual.derived

import Stream.*

import Iterator.*
Expand Down
2 changes: 1 addition & 1 deletion 2018/src/main/scala/aoc2018/Day18.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aoc2018

import nmcb.*
import nmcb.pos.*
import nmcb.pos.{*, given}
import nmcb.predef.*

import scala.collection.*
Expand Down
6 changes: 6 additions & 0 deletions 2018/src/main/scala/aoc2018/Day22.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object Day22 extends AoC:
case Wet extends RegionType(1)
case Narrow extends RegionType(2)

given CanEqual[RegionType, RegionType] = CanEqual.derived

case class Region(x: Int, y: Int):
infix def +(x: Int, y: Int): Region = copy(x = this.x + x, y = this.y + y)
infix def manhattan(that: Region): Int = (x - that.x).abs + (y - that.y).abs
Expand All @@ -23,6 +25,8 @@ object Day22 extends AoC:


object Region:

given CanEqual[Region, Region] = CanEqual.derived

val depth: Int = 11817
val mouth: Region = Region(0, 0)
Expand Down Expand Up @@ -55,6 +59,8 @@ object Day22 extends AoC:
case Torch
case ClimbingGear

given CanEqual[Tool, Tool] = CanEqual.derived

import RegionType.*
import Tool.*

Expand Down
2 changes: 2 additions & 0 deletions 2018/src/main/scala/aoc2018/Day23.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ object Day23 extends AoC:
infix def hasOverlappingRadiusWith(that: Bot): Boolean =
loc.manhattan(that.loc) <= radius + that.radius

given CanEqual[Bot, Bot] = CanEqual.derived

val bots: Set[Bot] =
lines
.collect:
Expand Down
2 changes: 2 additions & 0 deletions 2018/src/main/scala/aoc2018/Day24.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ object Day24 extends AoC:
case Infection

import Army.*

given CanEqual[Army, Army] = CanEqual.derived

type AttackKind = String

Expand Down
Loading