day 01 - 2026
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
target
|
||||||
|
.direnv
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
use flake
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day-01"
|
||||||
|
version = "0.1.0"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day-01"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
|||||||
|
57
|
||||||
|
57
|
||||||
|
55
|
||||||
|
57
|
||||||
|
76
|
||||||
|
78
|
||||||
|
57
|
||||||
|
45
|
||||||
|
43
|
||||||
|
78
|
||||||
|
43
|
||||||
|
76
|
||||||
|
43
|
||||||
|
78
|
||||||
|
57
|
||||||
|
45
|
||||||
|
57
|
||||||
|
76
|
||||||
|
43
|
||||||
|
43
|
||||||
|
76
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
use std::{
|
||||||
|
collections::{
|
||||||
|
BinaryHeap,
|
||||||
|
HashMap
|
||||||
|
},
|
||||||
|
env,
|
||||||
|
fs::File,
|
||||||
|
io::{
|
||||||
|
self,
|
||||||
|
BufRead,
|
||||||
|
BufReader
|
||||||
|
},
|
||||||
|
cmp::Reverse
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
struct ID {
|
||||||
|
count: u32,
|
||||||
|
val: u32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
if args.len() < 2 {
|
||||||
|
eprintln!("usage: {} <input-file.txt>", args[0]);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let f = File::open(&args[1])?;
|
||||||
|
let reader = BufReader::new(f);
|
||||||
|
let mut counts: HashMap<u32, u32> = HashMap::new();
|
||||||
|
|
||||||
|
for line in reader.lines() {
|
||||||
|
let line = line?;
|
||||||
|
let line = line.trim();
|
||||||
|
|
||||||
|
if line.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let val: u32 = line.parse().expect("not a valid u16");
|
||||||
|
*counts.entry(val).or_insert(0) += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut max_heap: BinaryHeap<ID> = counts
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|(val, count)| ID { count, val })
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut max_total: u32 = 1;
|
||||||
|
|
||||||
|
for _ in 0..3 {
|
||||||
|
if let Some(id) = max_heap.pop() {
|
||||||
|
max_total = max_total * id.val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut min_heap: BinaryHeap<Reverse<ID>> = counts
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|(val, count)| Reverse(ID { count, val }))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut min_total: u32 = 1;
|
||||||
|
|
||||||
|
for _ in 0..3 {
|
||||||
|
if let Some(Reverse(id)) = min_heap.pop() {
|
||||||
|
min_total = min_total * id.val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Part One: {}\nPart Two: {}", max_total, min_total);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Generated
+96
@@ -0,0 +1,96 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1790185690,
|
||||||
|
"narHash": "sha256-xJ+X4hBtOcAFGBOe5nAMyMUeF9foJBmIOu3NjBqBycU=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "4975466d324710c576dc11ad614684e6bd8cad8e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1744536153,
|
||||||
|
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1790234952,
|
||||||
|
"narHash": "sha256-tjQa1vDoHJir4lasZTakz/xgmsfB6SRjeQqaIbefFOk=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "ed34466c59b766481248959a21a6e46cf0c60468",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
description = "A reproducible Rust development environment";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [ (import rust-overlay) ];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Choose your preferred Rust toolchain (e.g., stable, nightly, or specific version)
|
||||||
|
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||||
|
extensions = [ "rust-src" "rust-analyzer" ];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
# Tools available in the shell environment. rustToolchain includes rust-analyzer,
|
||||||
|
# so any Neovim config (e.g. rustaceanvim) picks it up automatically via PATH.
|
||||||
|
packages = [
|
||||||
|
rustToolchain
|
||||||
|
pkgs.cargo-watch # Optional but highly useful utility
|
||||||
|
];
|
||||||
|
|
||||||
|
# System libraries and build dependencies frequently needed by Rust crates
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
openssl
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
# Environment variables required by Rust tooling
|
||||||
|
env = {
|
||||||
|
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
|
||||||
|
RUST_BACKTRACE = "1";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user