This commit is contained in:
Paul-Henri Froidmont 2022-12-02 16:48:27 +01:00
commit bfd82a5476
Signed by: phfroidmont
GPG key ID: BE948AFD7E7873BE
9 changed files with 2390 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
.bloop/
.direnv/
.metals/
.vscode/
.bsp/
out/

2
.scalafmt.conf Normal file
View file

@ -0,0 +1,2 @@
version = "3.0.5"
runner.dialect = scala3

2253
aoc/resources/day1Input.txt Normal file

File diff suppressed because it is too large Load diff

23
aoc/src/Day1.scala Normal file
View file

@ -0,0 +1,23 @@
import scala.io.Source
object Day1 extends App:
val calories = Source
.fromURL(getClass.getResource("day1Input.txt"))
.mkString
.split('\n')
.toList
val elvesCalories = calories
.foldLeft(List(0)) {
case (elvesTotal, caloriesValue) if caloriesValue.isEmpty =>
0 :: elvesTotal
case (elfTotal :: elveTotal, caloriesValue) =>
caloriesValue.toInt + elfTotal :: elveTotal
}
println(s"Part 1: ${elvesCalories.max}")
val top3ElvesCalories = elvesCalories.sorted.takeRight(3).sum
println(s"Part 2: ${top3ElvesCalories}")

5
build.sc Normal file
View file

@ -0,0 +1,5 @@
import mill._, scalalib._
object aoc extends ScalaModule {
def scalaVersion = "3.2.1"
}

60
flake.lock generated Normal file
View file

@ -0,0 +1,60 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1668681692,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1669791787,
"narHash": "sha256-KBfoA2fOI5+wCrm7PR+j7jHqXeTkVRPQ0m5fcKchyuU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e76c78d20685a043d23f5f9e0ccd2203997f1fb1",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

30
flake.nix Normal file
View file

@ -0,0 +1,30 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
millWithFixedJdk = pkgs.mill.override { jre = pkgs.jdk; };
in
{
devShell = pkgs.mkShell {
buildInputs = [ millWithFixedJdk ];
shellHook = ''
set -a
JAVA_HOME=${pkgs.jdk}
set +a
'';
};
}
);
}

10
shell.nix Normal file
View file

@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix