Compare commits
No commits in common. "9ce742fd57f7e57f0a370a3c77f80eb1b7855cda" and "c438d7d665d473d8df7517d166eb0a4361d3c658" have entirely different histories.
9ce742fd57
...
c438d7d665
@ -1,35 +0,0 @@
|
|||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct PuzzleInputs {
|
|
||||||
pub left: Vec<i32>,
|
|
||||||
pub right: Vec<i32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PuzzleInputs {
|
|
||||||
pub fn parse<P>(path: P) -> Self
|
|
||||||
where P: AsRef<Path>
|
|
||||||
{
|
|
||||||
let mut left = Vec::new();
|
|
||||||
let mut right = Vec::new();
|
|
||||||
|
|
||||||
let content = fs::read_to_string(path).unwrap();
|
|
||||||
|
|
||||||
for line in content.lines() {
|
|
||||||
let mut parts = line.split(' ');
|
|
||||||
|
|
||||||
// unwrap is very festive
|
|
||||||
let first = parts.next().unwrap();
|
|
||||||
let first = first.parse().unwrap();
|
|
||||||
let last = parts.last().unwrap();
|
|
||||||
let last = last.parse().unwrap();
|
|
||||||
|
|
||||||
left.push(first);
|
|
||||||
right.push(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
Self { left, right }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
mod common;
|
|
||||||
|
|
||||||
use common::PuzzleInputs;
|
|
||||||
|
|
||||||
|
|
||||||
const INPUT_FILE: &str = "puzzle.txt";
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut inputs = PuzzleInputs::parse(INPUT_FILE);
|
|
||||||
|
|
||||||
inputs.left.sort();
|
|
||||||
inputs.right.sort();
|
|
||||||
|
|
||||||
let mut sum = 0;
|
|
||||||
for (l, r) in inputs.left.into_iter().zip(inputs.right) {
|
|
||||||
let dist = l.abs_diff(r);
|
|
||||||
sum += dist;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{sum}");
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
mod common;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use common::PuzzleInputs;
|
|
||||||
|
|
||||||
type Hist = HashMap<i32, i32>;
|
|
||||||
|
|
||||||
|
|
||||||
const INPUT_FILE: &str = "puzzle.txt";
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let inputs = PuzzleInputs::parse(INPUT_FILE);
|
|
||||||
let mut hist = Hist::new();
|
|
||||||
|
|
||||||
for elem in inputs.right {
|
|
||||||
hist.entry(elem).and_modify(|e| *e += 1).or_insert(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut score = 0;
|
|
||||||
|
|
||||||
for elem in &inputs.left {
|
|
||||||
if let Some(x) = hist.get(elem) {
|
|
||||||
score += elem * x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{score:?}");
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
|||||||
3 4
|
|
||||||
4 3
|
|
||||||
2 5
|
|
||||||
1 3
|
|
||||||
3 9
|
|
||||||
3 3
|
|
48
flake.lock
48
flake.lock
@ -1,48 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1733024928,
|
|
||||||
"narHash": "sha256-n/DOfpKH1vkukuBnach91QBQId2dr5tkE7/7UrkV2zw=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "2c27ab2e60502d1ebb7cf38909de38663f762a79",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": "nixpkgs",
|
|
||||||
"rust-overlay": "rust-overlay"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rust-overlay": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1733020719,
|
|
||||||
"narHash": "sha256-Chv9+3zrf1DhdB9JyskjoV0vJbCQEgkVqrU3p4RPLv8=",
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"rev": "8e18f10703112e6c33e1c0d8b93e8305f6f0a75c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
43
flake.nix
43
flake.nix
@ -1,43 +0,0 @@
|
|||||||
{
|
|
||||||
description = "Advent of Code";
|
|
||||||
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
||||||
rust-overlay = {
|
|
||||||
url = "github:oxalica/rust-overlay";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = { nixpkgs, rust-overlay, ... }:
|
|
||||||
let
|
|
||||||
lib = nixpkgs.lib;
|
|
||||||
systems = ["x86_64-linux"];
|
|
||||||
|
|
||||||
forEachSystem = fn: lib.genAttrs systems (system:
|
|
||||||
let
|
|
||||||
overlays = [ (import rust-overlay) ];
|
|
||||||
pkgs = import nixpkgs { inherit system overlays; };
|
|
||||||
in fn { inherit pkgs; } );
|
|
||||||
|
|
||||||
mkRustToolchain = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
|
||||||
in {
|
|
||||||
devShells = forEachSystem ({ pkgs }: let
|
|
||||||
rustToolchain = mkRustToolchain pkgs;
|
|
||||||
rustNightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (t: t.minimal.override {
|
|
||||||
extensions = [ "rustfmt" ];
|
|
||||||
});
|
|
||||||
|
|
||||||
rustShell = pkgs.mkShell {
|
|
||||||
name = "AoC";
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
rustToolchain
|
|
||||||
rustNightlyToolchain
|
|
||||||
];
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
default = rustShell;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
[toolchain]
|
|
||||||
channel = "stable"
|
|
||||||
components = ["clippy", "rust-analyzer", "rust-src"]
|
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
|
||||||
profile = "minimal" # includes rustc, cargo, and rust-std
|
|
18
rustfmt.toml
18
rustfmt.toml
@ -1,18 +0,0 @@
|
|||||||
edition = "2021"
|
|
||||||
|
|
||||||
# Just enforce it here as well instead of relying on editorconfig alone
|
|
||||||
hard_tabs = false
|
|
||||||
tab_spaces = 4
|
|
||||||
newline_style = "Unix"
|
|
||||||
|
|
||||||
imports_granularity = "Module"
|
|
||||||
group_imports = "StdExternalCrate"
|
|
||||||
|
|
||||||
force_multiline_blocks = false
|
|
||||||
fn_single_line = false
|
|
||||||
comment_width = 100
|
|
||||||
wrap_comments = true
|
|
||||||
hex_literal_case = "Upper"
|
|
||||||
blank_lines_upper_bound = 2
|
|
||||||
overflow_delimited_expr = true
|
|
||||||
reorder_impl_items = true
|
|
Loading…
Reference in New Issue
Block a user