Skip to content

Commit

Permalink
2024 - Gleam - Day 01 - Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoVIII committed Jan 6, 2025
1 parent d274797 commit 2b2b288
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 2024/solutions/gleam/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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",
"name": "Gleam",
// 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.
Expand Down
11 changes: 7 additions & 4 deletions 2024/solutions/gleam/day01/src/day01.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import gleam/string
import simplifile

type Data =
List(#(Int, Int))
#(List(Int), List(Int))

pub fn parse(input: String) -> Data {
string.trim(input)
Expand All @@ -21,10 +21,11 @@ pub fn parse(input: String) -> Data {
})
#(x, y)
})
|> list.unzip
}

pub fn part1(data: Data) {
let #(list1, list2) = list.unzip(data)
let #(list1, list2) = data
let list1_sorted = list.sort(list1, int.compare)
let list2_sorted = list.sort(list2, int.compare)
list.zip(list1_sorted, list2_sorted)
Expand All @@ -35,8 +36,10 @@ pub fn part1(data: Data) {
|> list.fold(0, int.add)
}

pub fn part2(_x) {
42
pub fn part2(data: Data) {
let #(list1, list2) = data
list.map(list1, fn(el) { list.count(list2, fn(el2) { el == el2 }) * el })
|> list.fold(0, int.add)
}

pub fn main() {
Expand Down
4 changes: 3 additions & 1 deletion 2024/solutions/gleam/day01/test/day01_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub fn testset_test() {
part1: Some(fn(input) {
day01.parse(input) |> day01.part1 |> int.to_string
}),
part2: option.None,
part2: Some(fn(input) {
day01.parse(input) |> day01.part2 |> int.to_string
}),
)
testbase.testset_test(config)
}
Expand Down

0 comments on commit 2b2b288

Please sign in to comment.