-
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
22 changed files
with
297 additions
and
15 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,23 @@ | ||
name: Tests - 2024 - Gleam | ||
|
||
on: | ||
push: | ||
paths: | ||
- ".github/workflows/2024-gleam.yml" | ||
- "2024/puzzles/**" | ||
- "2024/solutions/gleam/**" | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: "27.1.2" | ||
gleam-version: "1.7.0" | ||
rebar3-version: "3" | ||
# elixir-version: "1" | ||
- name: Run tests | ||
run: ./2024/solutions/gleam/test-all.sh |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,27 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu | ||
{ | ||
"name": "Ubuntu", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/base:jammy", | ||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
"features": { | ||
"ghcr.io/devcontainers-extra/features/gleam:1": {} | ||
}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "./.devcontainer/post-create.sh", | ||
// Configure tool-specific properties. | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"editorconfig.editorconfig", | ||
"gleam.gleam", | ||
"github.copilot" | ||
] | ||
} | ||
} | ||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
} |
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,9 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
echo "deb http://binaries2.erlang-solutions.com/ubuntu/ jammy-esl-erlang-25 contrib" | sudo tee -a /etc/apt/sources.list | ||
wget https://binaries2.erlang-solutions.com/GPG-KEY-pmanager.asc | ||
sudo apt-key add GPG-KEY-pmanager.asc | ||
rm GPG-KEY-pmanager.asc | ||
sudo apt update | ||
sudo apt install -y esl-erlang |
Empty file.
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,3 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
} |
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,3 @@ | ||
# README | ||
|
||
To create a new day, run `gleam new day<day>`. After that delete the .github folder and the README. |
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,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
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,22 @@ | ||
name = "day01" | ||
version = "1.0.0" | ||
|
||
# Fill out these fields if you intend to generate HTML documentation or publish | ||
# your project to the Hex package manager. | ||
# | ||
# description = "" | ||
# licences = ["Apache-2.0"] | ||
# repository = { type = "github", user = "", repo = "" } | ||
# links = [{ title = "Website", href = "" }] | ||
# | ||
# For a full reference of all the available options, you can have a look at | ||
# https://gleam.run/writing-gleam/gleam-toml/. | ||
|
||
[dependencies] | ||
argv = ">= 1.0.0 and < 2.0.0" | ||
gleam_stdlib = ">= 0.44.0 and < 2.0.0" | ||
simplifile = ">= 2.2.0 and < 3.0.0" | ||
|
||
[dev-dependencies] | ||
gleeunit = ">= 1.0.0 and < 2.0.0" | ||
testbase = { path = "../testbase" } |
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,18 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
packages = [ | ||
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, | ||
{ name = "filepath", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "67A6D15FB39EEB69DD31F8C145BB5A421790581BD6AA14B33D64D5A55DBD6587" }, | ||
{ name = "gleam_stdlib", version = "0.52.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "50703862DF26453B277688FFCDBE9DD4AC45B3BD9742C0B370DB62BC1629A07D" }, | ||
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, | ||
{ name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" }, | ||
{ name = "testbase", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../testbase" }, | ||
] | ||
|
||
[requirements] | ||
argv = { version = ">= 1.0.0 and < 2.0.0" } | ||
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } | ||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" } | ||
simplifile = { version = ">= 2.2.0 and < 3.0.0" } | ||
testbase = { path = "../testbase" } |
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,51 @@ | ||
import argv | ||
import gleam/int | ||
import gleam/io | ||
import gleam/list | ||
import gleam/string | ||
import simplifile | ||
|
||
type Data = | ||
List(#(Int, Int)) | ||
|
||
pub fn parse(input: String) -> Data { | ||
string.trim(input) | ||
|> string.split("\n") | ||
|> list.map(fn(line) { | ||
let assert [x, y] = | ||
string.trim(line) | ||
|> string.split(" ") | ||
|> list.map(fn(x) { | ||
let assert Ok(number) = int.parse(x) | ||
number | ||
}) | ||
#(x, y) | ||
}) | ||
} | ||
|
||
pub fn part1(data: Data) { | ||
let #(list1, list2) = list.unzip(data) | ||
let list1_sorted = list.sort(list1, int.compare) | ||
let list2_sorted = list.sort(list2, int.compare) | ||
list.zip(list1_sorted, list2_sorted) | ||
|> list.map(fn(pair) { | ||
let #(x, y) = pair | ||
int.absolute_value(x - y) | ||
}) | ||
|> list.fold(0, int.add) | ||
} | ||
|
||
pub fn part2(_x) { | ||
42 | ||
} | ||
|
||
pub fn main() { | ||
case argv.load().arguments { | ||
[input_file] -> { | ||
let assert Ok(input) = simplifile.read(input_file) | ||
let data = parse(input) | ||
io.println("Part 1: " <> { part1(data) |> int.to_string }) | ||
} | ||
_ -> io.println("Usage: gleam run -- <input-file>") | ||
} | ||
} |
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,22 @@ | ||
import gleam/int | ||
import gleam/option.{Some} | ||
import gleeunit | ||
|
||
import day01 | ||
import testbase | ||
|
||
pub fn testset_test() { | ||
let config = | ||
testbase.Config( | ||
day: "01", | ||
part1: Some(fn(input) { | ||
day01.parse(input) |> day01.part1 |> int.to_string | ||
}), | ||
part2: option.None, | ||
) | ||
testbase.testset_test(config) | ||
} | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} |
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,19 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
for file in $(find . -name "gleam.toml") | ||
do | ||
dir=$(dirname $file) | ||
# Skip the testbase directory and all directories containing "build" in the path | ||
if [ "$dir" == *"/testbase" ] || [[ "$dir" == *"/build/"* ]]; then | ||
continue | ||
fi | ||
echo "Running tests in $dir" | ||
cd "$dir" | ||
gleam deps download | ||
gleam test | ||
gleam format --check src test | ||
cd - | ||
echo "" | ||
done | ||
echo "Success!" |
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,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
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,20 @@ | ||
name = "testbase" | ||
version = "1.0.0" | ||
|
||
# Fill out these fields if you intend to generate HTML documentation or publish | ||
# your project to the Hex package manager. | ||
# | ||
# description = "" | ||
# licences = ["Apache-2.0"] | ||
# repository = { type = "github", user = "", repo = "" } | ||
# links = [{ title = "Website", href = "" }] | ||
# | ||
# For a full reference of all the available options, you can have a look at | ||
# https://gleam.run/writing-gleam/gleam-toml/. | ||
|
||
[dependencies] | ||
gleam_stdlib = ">= 0.44.0 and < 2.0.0" | ||
gleeunit = ">= 1.0.0 and < 2.0.0" | ||
simplifile = ">= 2.2.0 and < 3.0.0" | ||
|
||
[dev-dependencies] |
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,14 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
packages = [ | ||
{ name = "filepath", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "67A6D15FB39EEB69DD31F8C145BB5A421790581BD6AA14B33D64D5A55DBD6587" }, | ||
{ name = "gleam_stdlib", version = "0.52.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "50703862DF26453B277688FFCDBE9DD4AC45B3BD9742C0B370DB62BC1629A07D" }, | ||
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, | ||
{ name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" }, | ||
] | ||
|
||
[requirements] | ||
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } | ||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" } | ||
simplifile = { version = ">= 2.2.0 and < 3.0.0" } |
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,56 @@ | ||
import gleam/io | ||
import gleam/list | ||
import gleam/option.{type Option, None, Some} | ||
import gleam/string | ||
import gleeunit/should | ||
import simplifile | ||
|
||
pub type Config { | ||
Config( | ||
day: String, | ||
part1: Option(fn(String) -> String), | ||
part2: Option(fn(String) -> String), | ||
) | ||
} | ||
|
||
fn get_output_filename(input_filename) { | ||
string.replace(input_filename, each: "-input", with: "-output") | ||
} | ||
|
||
pub fn testset_test(config: Config) { | ||
let basepath = "../../../puzzles/" <> config.day <> "/" | ||
let assert Ok(entries) = simplifile.read_directory(basepath) | ||
list.filter(entries, fn(entry) { string.ends_with(entry, "-input.txt") }) | ||
|> list.each(fn(input_file) { | ||
let assert Ok(input) = simplifile.read(basepath <> input_file) | ||
let output_file = get_output_filename(input_file) | ||
let assert Ok(output) = simplifile.read(basepath <> output_file) | ||
let assert [part1_expected, part2_expected] = | ||
output | ||
|> string.trim | ||
|> string.split("\n") | ||
|> list.map(fn(line) { | ||
let trimmed = string.trim(line) | ||
case trimmed { | ||
"-" -> None | ||
x -> Some(x) | ||
} | ||
}) | ||
case config.part1, part1_expected { | ||
Some(part1), Some(expected) -> { | ||
let actual = part1(input) | ||
io.println("Part 1: " <> actual) | ||
should.equal(actual, expected) | ||
} | ||
_, _ -> Nil | ||
} | ||
case config.part2, part2_expected { | ||
Some(part2), Some(expected) -> { | ||
let actual = part2(input) | ||
io.println("Part 2: " <> actual) | ||
should.equal(actual, expected) | ||
} | ||
_, _ -> Nil | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.