-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
noop |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
noop |
48 changes: 48 additions & 0 deletions
48
scala2/src/main/scala/jurisk/adventofcode/y2024/Advent22.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package jurisk.adventofcode.y2024 | ||
|
||
import jurisk.utils.FileInput._ | ||
import jurisk.utils.Parsing.StringOps | ||
|
||
object Advent22 { | ||
type Input = List[Command] | ||
type N = Long | ||
|
||
sealed trait Command extends Product with Serializable | ||
object Command { | ||
case object Noop extends Command | ||
final case class Something( | ||
values: List[N] | ||
) extends Command | ||
final case class Other(value: String) extends Command | ||
|
||
def parse(s: String): Command = | ||
s match { | ||
case "noop" => Noop | ||
case s"something $rem" => Something(rem.extractLongList) | ||
case s if s.nonEmpty => Other(s) | ||
case _ => s.failedToParse | ||
} | ||
} | ||
|
||
def parse(input: String): Input = | ||
input.parseLines(Command.parse) | ||
|
||
def part1(data: Input): N = | ||
0 | ||
|
||
def part2(data: Input): N = | ||
0 | ||
|
||
def parseFile(fileName: String): Input = | ||
parse(readFileText(fileName)) | ||
|
||
def fileName(suffix: String): String = | ||
s"2024/22$suffix.txt" | ||
|
||
def main(args: Array[String]): Unit = { | ||
val realData: Input = parseFile(fileName("")) | ||
|
||
println(s"Part 1: ${part1(realData)}") | ||
println(s"Part 2: ${part2(realData)}") | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
scala2/src/test/scala/jurisk/adventofcode/y2024/Advent22Spec.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package jurisk.adventofcode.y2024 | ||
|
||
import Advent22._ | ||
import org.scalatest.freespec.AnyFreeSpec | ||
import org.scalatest.matchers.should.Matchers._ | ||
|
||
|
||
class Advent22Spec extends AnyFreeSpec { | ||
private def testData = parseFile(fileName("-test-00")) | ||
private def realData = parseFile(fileName("")) | ||
|
||
"part 1" - { | ||
"test" in { | ||
part1(testData) shouldEqual 0 | ||
} | ||
|
||
"real" in { | ||
part1(realData) shouldEqual 0 | ||
} | ||
} | ||
|
||
"part 2" - { | ||
"test" in { | ||
part2(testData) shouldEqual 0 | ||
} | ||
|
||
"real" in { | ||
part2(realData) shouldEqual 0 | ||
} | ||
} | ||
} |