Skip to content

Commit

Permalink
2023, Day 01 - refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jurisk committed Dec 2, 2023
1 parent 39e2fbc commit 7437452
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
6 changes: 6 additions & 0 deletions rust/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ cargo fmt
cargo build --release
```

# Running

```shell
cargo run --bin solution_<XY>
```

# Testing

```shell
Expand Down
20 changes: 6 additions & 14 deletions scala2/src/main/scala/jurisk/adventofcode/y2023/Advent01.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package jurisk.adventofcode.y2023

import jurisk.utils.FileInput._
import org.scalatest.matchers.should.Matchers._

import scala.annotation.tailrec

object Advent01 {
Expand Down Expand Up @@ -61,19 +59,13 @@ object Advent01 {
solve(data, stringToDigitList(mappings))
}

def main(args: Array[String]): Unit = {
val testData1 = readFileText("2023/01-test-1.txt")
val testData2 = readFileText("2023/01-test-2.txt")
val realData = readFileText("2023/01.txt")

val test1 = parse(testData1)
val test2 = parse(testData2)
val real = parse(realData)
private[y2023] def parseFile(fileName: String): Parsed =
parse(readFileText(fileName))

part1(test1) shouldEqual 142
part1(real) shouldEqual 54081
def main(args: Array[String]): Unit = {
val realData: Parsed = parseFile("2023/01.txt")

part2(test2) shouldEqual 281
part2(real) shouldEqual 54649
println(s"Part 1: ${part1(realData)}")
println(s"Part 2: ${part2(realData)}")
}
}
23 changes: 23 additions & 0 deletions scala2/src/test/scala/jurisk/adventofcode/y2023/Advent01Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package jurisk.adventofcode.y2023

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import Advent01._

class Advent01Spec extends AnyFlatSpec {
"Advent01" should "test part 1" in {
part1(parseFile("2023/01-test-1.txt")) shouldEqual 142
}

it should "test part 2" in {
part2(parseFile("2023/01-test-2.txt")) shouldEqual 281
}

it should "real part 1" in {
part1(parseFile("2023/01.txt")) shouldEqual 54081
}

it should "real part 2" in {
part2(parseFile("2023/01.txt")) shouldEqual 54649
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ package jurisk.adventofcode.y2023

import org.scalatest.flatspec.AnyFlatSpec

class AllSolutionSpec extends AnyFlatSpec {
"Advent01" should "work" in {
Advent01.main(Array.empty)
}
}
class AllSolutionSpec extends AnyFlatSpec {}

0 comments on commit 7437452

Please sign in to comment.