diff options
author | HJ <thechairman@thechairman.info> | 2023-12-17 20:35:20 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2023-12-17 20:35:20 -0500 |
commit | 7709cc9954456195d9894e092aa8d23e42125a16 (patch) | |
tree | dbe8ef13b9bfd8fbbae2f98c94ab474c5598efb4 /aoc2023/src/day15/solve.gleam | |
parent | 96c8dd61ba3804ea97927342bf7660985afed9eb (diff) | |
parent | 9f0d9e4de0e6a69b9770b227f669af75667b8c90 (diff) | |
download | gleam_aoc-7709cc9954456195d9894e092aa8d23e42125a16.tar.gz gleam_aoc-7709cc9954456195d9894e092aa8d23e42125a16.zip |
Merge branch 'main' of https://github.com/hunkyjimpjorps/AdventOfCode
Diffstat (limited to 'aoc2023/src/day15/solve.gleam')
-rw-r--r-- | aoc2023/src/day15/solve.gleam | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/aoc2023/src/day15/solve.gleam b/aoc2023/src/day15/solve.gleam index 2d863b5..a7d250c 100644 --- a/aoc2023/src/day15/solve.gleam +++ b/aoc2023/src/day15/solve.gleam @@ -12,13 +12,13 @@ fn split(input: String) -> List(String) { } fn hash_algorithm(str: String) -> Int { - str - |> string.to_utf_codepoints() - |> list.map(string.utf_codepoint_to_int) - |> list.fold(0, fn(acc, c) { - let assert Ok(acc) = int.modulo({ acc + c } * 17, 256) - acc - }) + let codepoints = + str + |> string.to_utf_codepoints() + |> list.map(string.utf_codepoint_to_int) + use acc, c <- list.fold(codepoints, 0) + let assert Ok(acc) = int.modulo({ acc + c } * 17, 256) + acc } pub fn part1(input: String) -> String { |