diff options
author | J.J <thechairman@thechairman.info> | 2024-05-30 22:08:11 -0400 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2024-05-30 22:08:11 -0400 |
commit | d3f51f8c1de71befbb3ac9fb4967a1f831c11a73 (patch) | |
tree | eecd7403a5e6aa473fb3b8627679ccecda56d1af | |
parent | 612fd986ab1e00b6d34dc1937136250e08e89325 (diff) | |
download | gleam_aoc-d3f51f8c1de71befbb3ac9fb4967a1f831c11a73.tar.gz gleam_aoc-d3f51f8c1de71befbb3ac9fb4967a1f831c11a73.zip |
gleam 2019 day 1
-rw-r--r-- | aoc2019-gleam/src/aoc2019_gleam.gleam | 5 | ||||
-rw-r--r-- | aoc2019_gleam/.github/workflows/test.yml (renamed from aoc2019-gleam/.github/workflows/test.yml) | 0 | ||||
-rw-r--r-- | aoc2019_gleam/.gitignore (renamed from aoc2019-gleam/.gitignore) | 2 | ||||
-rw-r--r-- | aoc2019_gleam/README.md (renamed from aoc2019-gleam/README.md) | 0 | ||||
-rw-r--r-- | aoc2019_gleam/gleam.toml (renamed from aoc2019-gleam/gleam.toml) | 5 | ||||
-rw-r--r-- | aoc2019_gleam/manifest.toml (renamed from aoc2019-gleam/manifest.toml) | 25 | ||||
-rw-r--r-- | aoc2019_gleam/src/aoc2019_gleam.gleam | 5 | ||||
-rw-r--r-- | aoc2019_gleam/src/aoc_2019/day_1.gleam | 32 | ||||
-rw-r--r-- | aoc2019_gleam/test/aoc2019_gleam_test.gleam | 12 |
9 files changed, 62 insertions, 24 deletions
diff --git a/aoc2019-gleam/src/aoc2019_gleam.gleam b/aoc2019-gleam/src/aoc2019_gleam.gleam deleted file mode 100644 index 3ab0f4c..0000000 --- a/aoc2019-gleam/src/aoc2019_gleam.gleam +++ /dev/null @@ -1,5 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("Hello from aoc2019_gleam!") -} diff --git a/aoc2019-gleam/.github/workflows/test.yml b/aoc2019_gleam/.github/workflows/test.yml index dd5e246..dd5e246 100644 --- a/aoc2019-gleam/.github/workflows/test.yml +++ b/aoc2019_gleam/.github/workflows/test.yml diff --git a/aoc2019-gleam/.gitignore b/aoc2019_gleam/.gitignore index a98602e..599be4e 100644 --- a/aoc2019-gleam/.gitignore +++ b/aoc2019_gleam/.gitignore @@ -2,5 +2,3 @@ *.ez /build erl_crash.dump - -aoc.toml
\ No newline at end of file diff --git a/aoc2019-gleam/README.md b/aoc2019_gleam/README.md index bbf8121..bbf8121 100644 --- a/aoc2019-gleam/README.md +++ b/aoc2019_gleam/README.md diff --git a/aoc2019-gleam/gleam.toml b/aoc2019_gleam/gleam.toml index 36967f2..c9bed2a 100644 --- a/aoc2019-gleam/gleam.toml +++ b/aoc2019_gleam/gleam.toml @@ -13,9 +13,8 @@ version = "1.0.0" # https://gleam.run/writing-gleam/gleam-toml/. [dependencies] -gleam_stdlib = ">= 0.36.0 and < 2.0.0" -startest = ">= 0.2.0 and < 1.0.0" +gleam_stdlib = ">= 0.34.0 and < 2.0.0" +gladvent = ">= 0.7.3 and < 1.0.0" [dev-dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" -adglent = { path = "../adglent"} diff --git a/aoc2019-gleam/manifest.toml b/aoc2019_gleam/manifest.toml index af970a1..d41f27a 100644 --- a/aoc2019-gleam/manifest.toml +++ b/aoc2019_gleam/manifest.toml @@ -2,33 +2,30 @@ # You typically do not need to edit this file packages = [ - { name = "adglent", version = "1.2.0", build_tools = ["gleam"], requirements = ["gap", "gleam_community_ansi", "gleam_erlang", "gleam_http", "gleam_httpc", "gleam_otp", "gleam_stdlib", "glint", "simplifile", "snag", "tom"], source = "local", path = "../adglent" }, { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, - { name = "birl", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "B1FA529E7BE3FF12CADF32814AB8EC7294E74CEDEE8CC734505707B929A98985" }, - { name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" }, { name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" }, - { name = "gap", version = "1.1.3", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_stdlib"], otp_app = "gap", source = "hex", outer_checksum = "6EF5E3B523FDFBC317E9EA28D5163EE04744A97C007106F90207569789612291" }, + { name = "gladvent", version = "0.7.3", build_tools = ["gleam"], requirements = ["argv", "filepath", "gleam_erlang", "gleam_json", "gleam_otp", "gleam_package_interface", "gleam_stdlib", "glint", "parallel_map", "shellout", "simplifile", "snag", "spinner", "tom"], otp_app = "gladvent", source = "hex", outer_checksum = "59D93FD759427BCE8EE9828C0B62A3CD18362225F948C9789D334DCEAD621358" }, { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" }, { name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" }, { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, - { name = "gleam_http", version = "3.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8C07DF9DF8CC7F054C650839A51C30A7D3C26482AC241C899C1CEA86B22DBE51" }, - { name = "gleam_httpc", version = "2.2.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "CF76C71002DEECF6DC5D9CA83D962728FAE166B57926BE442D827004D3C7DF1B" }, - { name = "gleam_javascript", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "14D5B7E1A70681E0776BF0A0357F575B822167960C844D3D3FA114D3A75F05A8" }, { name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" }, { name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" }, + { name = "gleam_package_interface", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_package_interface", source = "hex", outer_checksum = "52A721BCA972C8099BB881195D821AAA64B9F2655BECC102165D5A1097731F01" }, { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, + { name = "glearray", version = "0.2.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "9C207E05F38D724F464FA921378DB3ABC2B0A2F5821116D8BC8B2CACC68930D5" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, - { name = "glint", version = "0.18.1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "5FB54D7732B4105E4AF4D89A7EE6D5E8CF33DA13A3575D0C6ECE470B97958454" }, - { name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" }, + { name = "glint", version = "1.0.0-rc2", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "FD5C47CE237CA67121F3946ADE7C630750BB67F5E8A4717D2DF5B5EE758CCFDB" }, + { name = "parallel_map", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "parallel_map", source = "hex", outer_checksum = "653714A9FD63EACD1A9D0A6582A972B0EC109AE275CDDD2E99CFC3DFAFAB9225" }, + { name = "repeatedly", version = "2.1.1", build_tools = ["gleam"], requirements = [], otp_app = "repeatedly", source = "hex", outer_checksum = "38808C3EC382B0CD981336D5879C24ECB37FCB9C1D1BD128F7A80B0F74404D79" }, + { name = "shellout", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "E2FCD18957F0E9F67E1F497FC9FF57393392F8A9BAEAEA4779541DE7A68DD7E0" }, { name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" }, { name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" }, - { name = "startest", version = "0.2.0", build_tools = ["gleam"], requirements = ["argv", "birl", "exception", "gleam_community_ansi", "gleam_erlang", "gleam_javascript", "gleam_stdlib", "glint", "simplifile", "tom"], otp_app = "startest", source = "hex", outer_checksum = "89F8575C91696D1713075F0B850A54160A32580A7CF415E045A0EEAD498AA30D" }, + { name = "spinner", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "glearray", "repeatedly"], otp_app = "spinner", source = "hex", outer_checksum = "200BA3D4A04D468898E63C0D316E23F526E02514BC46454091975CB5BAE41E8F" }, { name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" }, - { name = "tom", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0831C73E45405A2153091226BF98FB485ED16376988602CC01A5FD086B82D577" }, + { name = "tom", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "A5364613E3DBF77F38EFF81DA9F99324086D029EC2B2D44348762FBE38602311" }, ] [requirements] -adglent = { path = "../adglent" } -gleam_stdlib = { version = ">= 0.36.0 and < 2.0.0" } +gladvent = { version = ">= 0.7.3 and < 1.0.0"} +gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } -startest = { version = ">= 0.2.0 and < 1.0.0"} diff --git a/aoc2019_gleam/src/aoc2019_gleam.gleam b/aoc2019_gleam/src/aoc2019_gleam.gleam new file mode 100644 index 0000000..c5a7e0a --- /dev/null +++ b/aoc2019_gleam/src/aoc2019_gleam.gleam @@ -0,0 +1,5 @@ +import gladvent + +pub fn main() { + gladvent.main() +} diff --git a/aoc2019_gleam/src/aoc_2019/day_1.gleam b/aoc2019_gleam/src/aoc_2019/day_1.gleam new file mode 100644 index 0000000..7e23172 --- /dev/null +++ b/aoc2019_gleam/src/aoc_2019/day_1.gleam @@ -0,0 +1,32 @@ +import gleam/int +import gleam/list +import gleam/result +import gleam/string + +pub fn parse(input: String) -> List(Int) { + input + |> string.split("\n") + |> list.map(int.parse) + |> result.values() +} + +pub fn pt_1(input: List(Int)) { + input + |> list.fold(0, fn(total, next) { total + naive_fuel(next) }) +} + +pub fn pt_2(input: List(Int)) { + input + |> list.fold(0, fn(total, next) { total + recursive_fuel(next) }) +} + +fn naive_fuel(weight: Int) -> Int { + { weight / 3 } - 2 +} + +fn recursive_fuel(weight: Int) -> Int { + case { weight / 3 } - 2 { + n if n <= 0 -> 0 + n -> n + recursive_fuel(n) + } +} diff --git a/aoc2019_gleam/test/aoc2019_gleam_test.gleam b/aoc2019_gleam/test/aoc2019_gleam_test.gleam new file mode 100644 index 0000000..3831e7a --- /dev/null +++ b/aoc2019_gleam/test/aoc2019_gleam_test.gleam @@ -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) +} |