mirror of
https://github.com/wezm/advent-of-code.git
synced 2024-12-18 18:29:55 +00:00
Day 1 part 1
This commit is contained in:
parent
8fdb89a1b8
commit
24ed6713e9
8 changed files with 2367 additions and 0 deletions
4
2022/.gitignore
vendored
Normal file
4
2022/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
*.beam
|
||||||
|
*.ez
|
||||||
|
build
|
||||||
|
erl_crash.dump
|
24
2022/README.md
Normal file
24
2022/README.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# advent_of_code
|
||||||
|
|
||||||
|
[![Package Version](https://img.shields.io/hexpm/v/advent_of_code)](https://hex.pm/packages/advent_of_code)
|
||||||
|
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/advent_of_code/)
|
||||||
|
|
||||||
|
A Gleam project
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```sh
|
||||||
|
gleam run # Run the project
|
||||||
|
gleam test # Run the tests
|
||||||
|
gleam shell # Run an Erlang shell
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
If available on Hex this package can be added to your Gleam project:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
gleam add advent_of_code
|
||||||
|
```
|
||||||
|
|
||||||
|
and its documentation can be found at <https://hexdocs.pm/advent_of_code>.
|
17
2022/gleam.toml
Normal file
17
2022/gleam.toml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
name = "advent_of_code"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||||
|
# your project to the Hex package manager.
|
||||||
|
#
|
||||||
|
# licences = ["Apache-2.0"]
|
||||||
|
# description = "A Gleam library..."
|
||||||
|
# repository = { type = "github", user = "username", repo = "project" }
|
||||||
|
# links = [{ title = "Website", href = "https://gleam.run" }]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
gleam_stdlib = "~> 0.25"
|
||||||
|
gladvent = "~> 0.4"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
gleeunit = "~> 0.7"
|
2251
2022/input/day_1.txt
Normal file
2251
2022/input/day_1.txt
Normal file
File diff suppressed because it is too large
Load diff
18
2022/manifest.toml
Normal file
18
2022/manifest.toml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# This file was generated by Gleam
|
||||||
|
# You typically do not need to edit this file
|
||||||
|
|
||||||
|
packages = [
|
||||||
|
{ name = "gladvent", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_otp", "gleam_erlang", "gleam_stdlib", "snag", "glint"], otp_app = "gladvent", source = "hex", outer_checksum = "F3030B5A8E9F83DCCE6F09C596D5AF8412996FD336EEA5CD806D739DF07EE15F" },
|
||||||
|
{ name = "gleam_erlang", version = "0.17.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A3BB3D4A6AFC2E34CAB1A4960F0CBBC4AA1A052D5023477D16B848D86E69948A" },
|
||||||
|
{ name = "gleam_otp", version = "0.5.2", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "24B88BF1D5B8DEC2525C00ECB65B96D2FD4DC66D8B2BB4D7AD4D12B2CE2A9988" },
|
||||||
|
{ name = "gleam_stdlib", version = "0.25.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "AD0F89928E0B919C8F8EDF640484633B28DBF88630A9E6AE504617A3E3E5B9A2" },
|
||||||
|
{ name = "gleeunit", version = "0.7.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "5F4FBED3E93CDEDB0570D30E9DECB7058C2D327996B78BB2D245C739C7136010" },
|
||||||
|
{ name = "glint", version = "0.10.0", build_tools = ["gleam"], requirements = ["shellout", "snag", "gleam_stdlib"], otp_app = "glint", source = "hex", outer_checksum = "540D6435A0CE5C3660769B364CFF9BC98724DF3ED942FA80946A47C653B4ED02" },
|
||||||
|
{ name = "shellout", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "310662075CDCB6E3928B03E3FD371B1DDCD691E1C709E606AB02195E36675D4E" },
|
||||||
|
{ name = "snag", version = "0.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "35C63E478782C58236F1050297C2FDF9806A4DD55C6FAF0B6EC5E54BC119342D" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[requirements]
|
||||||
|
gladvent = "~> 0.4"
|
||||||
|
gleam_stdlib = "~> 0.25"
|
||||||
|
gleeunit = "~> 0.7"
|
5
2022/src/advent_of_code.gleam
Normal file
5
2022/src/advent_of_code.gleam
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import gladvent
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
gladvent.main()
|
||||||
|
}
|
36
2022/src/days/day_1.gleam
Normal file
36
2022/src/days/day_1.gleam
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import gleam/string
|
||||||
|
import gleam/int
|
||||||
|
import gleam/list
|
||||||
|
import gleam/io
|
||||||
|
|
||||||
|
pub fn pt_1(input: String) -> Int {
|
||||||
|
assert Ok(max) =
|
||||||
|
string.split(input, on: "\n")
|
||||||
|
|> aggregate_calories([0])
|
||||||
|
|> list.reduce(int.max)
|
||||||
|
max
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pt_2(input: String) -> Int {
|
||||||
|
todo
|
||||||
|
}
|
||||||
|
|
||||||
|
fn aggregate_calories(lines: List(String), sums: List(Int)) -> List(Int) {
|
||||||
|
case lines {
|
||||||
|
[] -> sums
|
||||||
|
["", ..rest] -> aggregate_calories(rest, [0, ..sums])
|
||||||
|
[num, ..rest] -> {
|
||||||
|
assert Ok(calories) = int.parse(num)
|
||||||
|
inc(calories, sums)
|
||||||
|
|> aggregate_calories(rest, _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inc(num: Int, sums: List(Int)) -> List(Int) {
|
||||||
|
case sums {
|
||||||
|
// should be unreachable
|
||||||
|
[] -> []
|
||||||
|
[first, ..rest] -> [first + num, ..rest]
|
||||||
|
}
|
||||||
|
}
|
12
2022/test/advent_of_code_test.gleam
Normal file
12
2022/test/advent_of_code_test.gleam
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import gleeunit
|
||||||
|
import gleeunit/should
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
gleeunit.main()
|
||||||
|
}
|
||||||
|
|
||||||
|
// gleeunit test functions end in `_test`
|
||||||
|
pub fn hello_world_test() {
|
||||||
|
1
|
||||||
|
|> should.equal(1)
|
||||||
|
}
|
Loading…
Reference in a new issue