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
6 changes: 3 additions & 3 deletions .github/workflows/add-daily-article.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/schedule-add-daily-article.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions 2024/README.md
Original file line number Diff line number Diff line change
@@ -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 <dayX>.<partX>
```

## Contributing

- Please do not commit your puzzle inputs, we can not accept them as they are protected by copyright
3 changes: 3 additions & 0 deletions 2025/project.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//> using scala 3.7.4
//> using option -Wunused:all
//> using test.dep org.scalameta::munit::1.2.1
9 changes: 9 additions & 0 deletions 2025/src/inputs.scala
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions 2025/src/locations.scala
Original file line number Diff line number Diff line change
@@ -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]
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -9,6 +9,7 @@ See earlier editions:
- [2021](/2021/README.md)
- [2022](/2022/README.md)
- [2023](/2023/README.md)
- [2024](/2024/README.md)

## Website

Expand All @@ -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.

Expand All @@ -28,39 +29,39 @@ 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
```

Or, to run another solution:
```
$ scala-cli 2024 -M <dayX>.<partX>
$ scala 2025 -M <dayX>.<partX>
```

## 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