From ed130740692f03fdc38034fb2cc3df0da9d54e79 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Tue, 18 Nov 2025 14:50:41 -0500 Subject: [PATCH 1/2] prepare main branch for 2025 --- 2024/README.md | 66 ++++++++++++++++++++++++++++++++++++++++ 2025/project.scala | 3 ++ 2025/src/inputs.scala | 9 ++++++ 2025/src/locations.scala | 19 ++++++++++++ README.md | 25 +++++++-------- 5 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 2024/README.md create mode 100644 2025/project.scala create mode 100644 2025/src/inputs.scala create mode 100644 2025/src/locations.scala diff --git a/2024/README.md b/2024/README.md new file mode 100644 index 0000000000..a9b8a0ab0a --- /dev/null +++ b/2024/README.md @@ -0,0 +1,66 @@ +# Scala Advent of Code 2024 + +Solutions in Scala for the annual [Advent of Code (adventofcode.com)](https://adventofcode.com/) challenge. + +_Note: this repo is not affiliated with Advent of Code._ + +See earlier editions: + +- [2021](/2021/README.md) +- [2022](/2022/README.md) +- [2023](/2023/README.md) + +## Website + +The [Scala Advent of Code](https://scalacenter.github.io/scala-advent-of-code/) website contains: + +- some explanation of our solutions to [Advent of Code](https://adventofcode.com/) +- more solutions from the community + +## Setup + +We use Visual Studio Code with Metals to write Scala code, and scala-cli to compile and run it. + +You can follow these [steps](https://scalacenter.github.io/scala-advent-of-code/setup) to set up your environement. + +### How to open in Visual Studio Code + +After you clone the repository, open a terminal and run: +``` +$ cd scala-advent-of-code +$ scala-cli setup-ide 2024 +$ mkdir 2024/input +$ code 2024 +``` + +`code 2024` will open Visual Studio Code and start Metals. If not you may have to go to the Metals pane and click +the button labelled "Start Metals". + +When you navigate to a file, e.g. `2024/src/day01.scala` metals should index the project, and then display code lenses +above each of the main methods `part1` and `part2`, as shown in this image: +![](../img/code-lenses.png) + +To run a solution, first copy your input to the folder `2024/input`. +Then click `run` in VS Code which will run the code and display the results of the program. Or `debug`, +which will let you pause on breakpoints, and execute expressions in the debug console. + +### How to run a solution with command line + +To run a solution, first copy your input to the folder `2024/input`. + +In a terminal you can run: +``` +$ scala-cli 2024 -M day01.part1 +Compiling project (Scala 3.x.y, JVM) +Compiled project (Scala 3.x.y, JVM) +The solution is 64929 +``` + +Or, to run another solution: +``` +$ scala-cli 2024 -M . +``` + +## Contributing + +- Please do not commit your puzzle inputs, we can not accept them as they are protected by copyright diff --git a/2025/project.scala b/2025/project.scala new file mode 100644 index 0000000000..f6cb197942 --- /dev/null +++ b/2025/project.scala @@ -0,0 +1,3 @@ +//> using scala 3.7.4 +//> using option -Wunused:all +//> using test.dep org.scalameta::munit::1.2.1 diff --git a/2025/src/inputs.scala b/2025/src/inputs.scala new file mode 100644 index 0000000000..1d41e4738c --- /dev/null +++ b/2025/src/inputs.scala @@ -0,0 +1,9 @@ +package inputs + +import scala.util.Using +import scala.io.Source + +object Input: + + def loadFileSync(path: String): String = + Using.resource(Source.fromFile(path))(_.mkString) diff --git a/2025/src/locations.scala b/2025/src/locations.scala new file mode 100644 index 0000000000..986d2a3bb8 --- /dev/null +++ b/2025/src/locations.scala @@ -0,0 +1,19 @@ +package locations + +import scala.quoted.* + +object Directory: + + /** The absolute path of the parent directory of the file that calls this method + * This is stable no matter which directory runs the program. + */ + inline def currentDir: String = ${ parentDirImpl } + + private def parentDirImpl(using Quotes): Expr[String] = + // position of the call to `currentDir` in the source code + val position = quotes.reflect.Position.ofMacroExpansion + // get the path of the file calling this macro + val srcFilePath = position.sourceFile.getJPath.get + // get the parent of the path, which is the directory containing the file + val parentDir = srcFilePath.getParent().toAbsolutePath + Expr(parentDir.toString) // convert the String to Expr[String] diff --git a/README.md b/README.md index 33787309f2..966aa1fdef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Scala Advent of Code 2024 +# Scala Advent of Code 2025 Solutions in Scala for the annual [Advent of Code (adventofcode.com)](https://adventofcode.com/) challenge. @@ -9,6 +9,7 @@ See earlier editions: - [2021](/2021/README.md) - [2022](/2022/README.md) - [2023](/2023/README.md) +- [2024](/2024/README.md) ## Website @@ -19,7 +20,7 @@ The [Scala Advent of Code](https://scalacenter.github.io/scala-advent-of-code/) ## Setup -We use Visual Studio Code with Metals to write Scala code, and scala-cli to compile and run it. +We use Visual Studio Code with Metals to write Scala code, and Scala-CLI to compile and run it. (Scala-CLI has been the default `scala` command since Scala 3.5.) You can follow these [steps](https://scalacenter.github.io/scala-advent-of-code/setup) to set up your environement. @@ -28,29 +29,29 @@ You can follow these [steps](https://scalacenter.github.io/scala-advent-of-code/ After you clone the repository, open a terminal and run: ``` $ cd scala-advent-of-code -$ scala-cli setup-ide 2024 -$ mkdir 2024/input -$ code 2024 +$ scala setup-ide 2025 +$ mkdir 2025/input +$ code 2025 ``` -`code 2024` will open Visual Studio Code and start Metals. If not you may have to go to the Metals pane and click +`code 2025` will open Visual Studio Code and start Metals. If not you may have to go to the Metals pane and click the button labelled "Start Metals". -When you navigate to a file, e.g. `2024/src/day01.scala` metals should index the project, and then display code lenses +When you navigate to a file, e.g. `2025/src/day01.scala`, Metals should index the project, and then display code lenses above each of the main methods `part1` and `part2`, as shown in this image: ![](img/code-lenses.png) -To run a solution, first copy your input to the folder `2024/input`. +To run a solution, first copy your input to the folder `2025/input`. Then click `run` in VS Code which will run the code and display the results of the program. Or `debug`, which will let you pause on breakpoints, and execute expressions in the debug console. ### How to run a solution with command line -To run a solution, first copy your input to the folder `2024/input`. +To run a solution, first copy your input to the folder `2025/input`. In a terminal you can run: ``` -$ scala-cli 2024 -M day01.part1 +$ scala 2025 -M day01.part1 Compiling project (Scala 3.x.y, JVM) Compiled project (Scala 3.x.y, JVM) The solution is 64929 @@ -58,9 +59,9 @@ The solution is 64929 Or, to run another solution: ``` -$ scala-cli 2024 -M . +$ scala 2025 -M . ``` ## Contributing -- Please do not commit your puzzle inputs, we can not accept them as they are protected by copyright +Please do not commit your puzzle inputs; we can not accept them, as they are protected by copyright From 2aab672ed3f55204af4b98ca0753dd8fa904c2c6 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Tue, 18 Nov 2025 15:20:05 -0500 Subject: [PATCH 2/2] update GitHub Actions stuff --- .github/workflows/add-daily-article.yml | 6 +++--- .github/workflows/schedule-add-daily-article.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/add-daily-article.yml b/.github/workflows/add-daily-article.yml index f846169d2d..4a1aedf284 100644 --- a/.github/workflows/add-daily-article.yml +++ b/.github/workflows/add-daily-article.yml @@ -19,11 +19,11 @@ jobs: ref: website submodules: true - - uses: coursier/cache-action@v6 + - uses: coursier/cache-action@v7 - - uses: VirtusLab/scala-cli-setup@v0.1.18 + - uses: VirtusLab/scala-cli-setup@v1.10.1 with: - jvm: "temurin:17" + jvm: "temurin:21" - name: Generate todays article run: scala-cli run .github/workflows/scripts/addDay.scala diff --git a/.github/workflows/schedule-add-daily-article.yml b/.github/workflows/schedule-add-daily-article.yml index ea6fa5dfcf..72ef399500 100644 --- a/.github/workflows/schedule-add-daily-article.yml +++ b/.github/workflows/schedule-add-daily-article.yml @@ -20,11 +20,11 @@ jobs: ref: website submodules: true - - uses: coursier/cache-action@v6 + - uses: coursier/cache-action@v7 - - uses: VirtusLab/scala-cli-setup@v0.1.18 + - uses: VirtusLab/scala-cli-setup@v1.10.1 with: - jvm: "temurin:17" + jvm: "temurin:21" apps: sbt - name: Generate todays article