Skip to content

Commit

Permalink
gleam format
Browse files Browse the repository at this point in the history
  • Loading branch information
dalanmiller committed Dec 2, 2024
1 parent 2421069 commit cc8c9ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
14 changes: 8 additions & 6 deletions 2024/src/day1.gleam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import gleam/dict
import gleam/int
import gleam/io
import gleam/list
import gleam/string
import gleam/dict
import gleam/string
import utils

pub fn main() {
Expand All @@ -14,7 +14,7 @@ pub fn main() {
part2(input)
}

pub fn part1(input) -> Int{
pub fn part1(input) -> Int {
let list_a =
input
|> string.split("\n")
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn part1(input) -> Int{
|> list.fold(0, fn(b, a) { b + int.absolute_value(a.0 - a.1) })

io.debug("part1: " <> int.to_string(result))
result
result
}

pub fn part2(input) -> Int {
Expand Down Expand Up @@ -92,9 +92,11 @@ pub fn part2(input) -> Int {
Error(_) -> Error(Nil)
}
})
|> list.fold(0, fn(acc, a) {
|> list.fold(0, fn(acc, a) {
case dict.get(counts, a) {
Ok(v) -> { acc + {a * v} }
Ok(v) -> {
acc + { a * v }
}
Error(_) -> acc
}
})
Expand Down
17 changes: 11 additions & 6 deletions 2024/src/utils.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ pub fn read_file(path: String) -> Result(String, String) {
let codespaces_path = "/workspaces/advent-of-code/2024/src"
let laptop_path = "/Users/dalan/repos/dalan_advent_of_code/2024/src"

let pre_path = case simplifile.is_directory("/workspaces") {
Ok(True) -> {codespaces_path} // This is a Github workspaces
Ok(False) | Error(_)-> {laptop_path} // This is maybe my home laptop
let pre_path = case simplifile.is_directory("/workspaces") {
Ok(True) -> {
codespaces_path
}
// This is a Github workspaces
Ok(False) | Error(_) -> {
laptop_path
}
// This is maybe my home laptop
}

let fullpath =
filepath.join(pre_path, path)

let fullpath = filepath.join(pre_path, path)
case simplifile.read(fullpath) {
Ok(result) -> Ok(result)
Error(_reason) -> {
Expand Down
4 changes: 2 additions & 2 deletions 2024/test/day1_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn main() {

// gleeunit test functions end in `_test`
pub fn day_1_part_1_test() {
"3 4
"3 4
4 3
2 5
1 3
Expand All @@ -29,4 +29,4 @@ pub fn day_1_part_2_test() {
"
|> day1.part2
|> should.equal(31)
}
}

0 comments on commit cc8c9ca

Please sign in to comment.