my solutions to advent of code
aoc advent-of-code

idk if im gonna keep doing the ts ones - day 4 2015 gleam

aylac.top 2658a98b e6cd4b0a

verified
Changed files
+163 -1
2015
template
gleam
+22
2015/4/gleam/gleam.toml
···
···
+
name = "main"
+
version = "1.0.0"
+
+
# Fill out these fields if you intend to generate HTML documentation or publish
+
# your project to the Hex package manager.
+
#
+
# description = ""
+
# licences = ["Apache-2.0"]
+
# repository = { type = "github", user = "", repo = "" }
+
# links = [{ title = "Website", href = "" }]
+
#
+
# For a full reference of all the available options, you can have a look at
+
# https://gleam.run/writing-gleam/gleam-toml/.
+
+
[dependencies]
+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+
simplifile = ">= 2.3.0 and < 3.0.0"
+
gleam_crypto = ">= 1.5.1 and < 2.0.0"
+
gleam_yielder = ">= 1.1.0 and < 2.0.0"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+18
2015/4/gleam/manifest.toml
···
···
+
# This file was generated by Gleam
+
# You typically do not need to edit this file
+
+
packages = [
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
+
{ name = "gleam_crypto", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "50774BAFFF1144E7872814C566C5D653D83A3EBF23ACC3156B757A1B6819086E" },
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" },
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
+
]
+
+
[requirements]
+
gleam_crypto = { version = ">= 1.5.1 and < 2.0.0" }
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+42
2015/4/gleam/src/main.gleam
···
···
+
import gleam/bit_array
+
import gleam/crypto.{Md5, hash}
+
import gleam/int.{to_string}
+
import gleam/io.{println}
+
import gleam/result.{unwrap}
+
import gleam/string.{trim}
+
import gleam/yielder.{Next, find, unfold}
+
import simplifile.{read}
+
+
// claude just helped me with understanding how yield works. didn't want to add that 1 manually because it's ugly. here's my pure mine attempt
+
// let res =
+
// yielder.unfold(0, fn(v) {
+
// let hash =
+
// crypto.hash(Md5, <<{ input <> to_string(v) }:utf8>>)
+
// |> bit_array.base16_encode
+
//
+
// case hash {
+
// "00000" <> _ -> yielder.Done
+
// ______ -> yielder.Next(v, v + 1)
+
// }
+
// })
+
// |> yielder.last()
+
// |> unwrap(0)
+
// |> int.add(1)
+
// |> to_string
+
+
pub fn find_first_with_leading(input: String, leading: String) {
+
unfold(0, fn(v) { Next(v, v + 1) })
+
|> find(fn(v) {
+
hash(Md5, <<{ input <> to_string(v) }:utf8>>)
+
|> bit_array.base16_encode
+
|> string.starts_with(leading)
+
})
+
|> unwrap(0)
+
|> to_string
+
}
+
+
pub fn main() {
+
let input = read(from: "../input.txt") |> unwrap("") |> trim()
+
println(find_first_with_leading(input, "00000"))
+
println(find_first_with_leading(input, "000000"))
+
}
+29
2015/4/ts/bun.lock
···
···
+
{
+
"lockfileVersion": 1,
+
"workspaces": {
+
"": {
+
"name": "ts",
+
"devDependencies": {
+
"@types/bun": "latest",
+
},
+
"peerDependencies": {
+
"typescript": "^5",
+
},
+
},
+
},
+
"packages": {
+
"@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="],
+
+
"@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="],
+
+
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
+
+
"bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
+
+
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
+
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
+
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
+
}
+
}
+1
2015/4/ts/index.ts
···
···
+
const input = (await Bun.file("../input.txt").text()).trim();
+15
2015/4/ts/package.json
···
···
+
{
+
"name": "ts",
+
"module": "index.ts",
+
"type": "module",
+
"scripts": {
+
"start": "bun index.ts"
+
},
+
"private": true,
+
"devDependencies": {
+
"@types/bun": "latest"
+
},
+
"peerDependencies": {
+
"typescript": "^5"
+
}
+
}
+29
2015/4/ts/tsconfig.json
···
···
+
{
+
"compilerOptions": {
+
// Environment setup & latest features
+
"lib": ["ESNext"],
+
"target": "ESNext",
+
"module": "Preserve",
+
"moduleDetection": "force",
+
"jsx": "react-jsx",
+
"allowJs": true,
+
+
// Bundler mode
+
"moduleResolution": "bundler",
+
"allowImportingTsExtensions": true,
+
"verbatimModuleSyntax": true,
+
"noEmit": true,
+
+
// Best practices
+
"strict": true,
+
"skipLibCheck": true,
+
"noFallthroughCasesInSwitch": true,
+
"noUncheckedIndexedAccess": true,
+
"noImplicitOverride": true,
+
+
// Some stricter flags (disabled by default)
+
"noUnusedLocals": false,
+
"noUnusedParameters": false,
+
"noPropertyAccessFromIndexSignature": false
+
}
+
}
+7 -1
template/gleam/src/main.gleam
···
import gleam/result.{unwrap}
import gleam/string.{trim}
import simplifile.{read}
pub fn main() {
let input = read(from: "../input.txt") |> unwrap("") |> trim()
-
echo input
}
···
+
import gleam/int.{to_string}
+
import gleam/io.{println}
import gleam/result.{unwrap}
import gleam/string.{trim}
import simplifile.{read}
pub fn main() {
let input = read(from: "../input.txt") |> unwrap("") |> trim()
+
+
println(
+
5
+
|> to_string,
+
)
}