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

lalallala

aylac.top c56b4780 1dd3d980

verified
Changed files
+164
2015
+20
2015/19/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"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2015/19/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_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ 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_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+14
2015/19/gleam/src/main.gleam
···
···
+
import gleam/int
+
import gleam/io
+
import gleam/string
+
import simplifile as file
+
+
pub fn main() {
+
let assert Ok(input) = file.read(from: "../input.txt")
+
as "Input file not found"
+
let input = input |> string.trim
+
+
5
+
|> int.to_string
+
|> io.println
+
}
+77
2015/4/rust/Cargo.lock
···
···
+
# This file is automatically @generated by Cargo.
+
# It is not intended for manual editing.
+
version = 4
+
+
[[package]]
+
name = "block-buffer"
+
version = "0.10.4"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
+
dependencies = [
+
"generic-array",
+
]
+
+
[[package]]
+
name = "cfg-if"
+
version = "1.0.4"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
+
+
[[package]]
+
name = "crypto-common"
+
version = "0.1.7"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
+
dependencies = [
+
"generic-array",
+
"typenum",
+
]
+
+
[[package]]
+
name = "digest"
+
version = "0.10.7"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
+
dependencies = [
+
"block-buffer",
+
"crypto-common",
+
]
+
+
[[package]]
+
name = "generic-array"
+
version = "0.14.7"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
+
dependencies = [
+
"typenum",
+
"version_check",
+
]
+
+
[[package]]
+
name = "md-5"
+
version = "0.10.6"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
+
dependencies = [
+
"cfg-if",
+
"digest",
+
]
+
+
[[package]]
+
name = "rust"
+
version = "0.1.0"
+
dependencies = [
+
"md-5",
+
]
+
+
[[package]]
+
name = "typenum"
+
version = "1.19.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
+
+
[[package]]
+
name = "version_check"
+
version = "0.9.5"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
+7
2015/4/rust/Cargo.toml
···
···
+
[package]
+
name = "rust"
+
version = "0.1.0"
+
edition = "2024"
+
+
[dependencies]
+
md-5 = "0.10.6"
+32
2015/4/rust/src/main.rs
···
···
+
use md5::{Digest, Md5};
+
+
// just putting it here that the idea of analysing it as bytes instead of a string and of putting the main hasher outside the loop was gemini
+
fn find(input: &str, requires: usize) -> u32 {
+
let mut i = 1;
+
let div_ceiled = requires.div_ceil(2) - 1;
+
let starts_with = &[0_u8].repeat(requires / 2);
+
+
let mut hasher_main = Md5::new();
+
hasher_main.update(input.as_bytes());
+
+
loop {
+
let mut hasher = hasher_main.clone();
+
hasher.update(i.to_string().as_bytes());
+
let result = hasher.finalize();
+
if result[div_ceiled] < 16 && result.starts_with(starts_with) {
+
return i;
+
}
+
i += 1;
+
}
+
}
+
+
fn main() {
+
let input = std::fs::read_to_string("../input.txt").expect("invalid input!!");
+
let input = input.trim();
+
+
let res = find(input, 5);
+
println!("{}", &res);
+
+
let res = find(input, 6);
+
println!("{}", &res);
+
}