2024?
This commit is contained in:
parent
b036db60d2
commit
902917426f
9 changed files with 1234 additions and 1 deletions
24
.envrc
Normal file
24
.envrc
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copy these to a .env.local file to override in local host
|
||||
|
||||
# This is what DIESEL cli uses
|
||||
export DATABASE_URL="test_db.db"
|
||||
|
||||
## APP variables
|
||||
# /etc/stormd/stormd.db
|
||||
export STORMD_DB_PATH="stormd_db_local.db"
|
||||
export STORMD_DB_ENC_KEY_FILE="stormd_db_enc.key"
|
||||
# /etc/nebula/config.yml
|
||||
export STORMD_NEBULA_CONFIG="nebula_config.yml"
|
||||
# Auth key for admin API
|
||||
export STORMD_NEXUS_ADMIN_AUTH_FILE="stormd_auth_key"
|
||||
export STORMD_DAEMON_HTTP_PORT=37391
|
||||
|
||||
# ======
|
||||
|
||||
watch_file .env.local
|
||||
dotenv_if_exists .env.local
|
||||
|
||||
use flake
|
||||
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
**/target
|
||||
**/build
|
||||
|
|
@ -9,7 +9,7 @@ use std::fs::{self, File};
|
|||
use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
|
||||
static AOC_PUZZLE_INPUT_CACHE: &str = "aoc_puzzle_cache";
|
||||
static AOC_PUZZLE_INPUT_CACHE: &str = "aoc_puzle_cache";
|
||||
|
||||
pub async fn get_puzzle_input(day: u8) -> Result<String> {
|
||||
let file_name = format!("day_{:02}", day);
|
||||
|
|
7
2024/Cargo.lock
generated
Normal file
7
2024/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aoc_2024"
|
||||
version = "0.1.0"
|
6
2024/Cargo.toml
Normal file
6
2024/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "aoc_2024"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
1008
2024/src/day1input.rs
Normal file
1008
2024/src/day1input.rs
Normal file
File diff suppressed because it is too large
Load diff
55
2024/src/main.rs
Normal file
55
2024/src/main.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
mod day1input;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use day1input::INPUT;
|
||||
|
||||
fn main() {
|
||||
INPUT.lines().map(|line| {
|
||||
let nums = line
|
||||
.split(" ")
|
||||
.map(|item| item.parse().expect("Input was not a valid number"))
|
||||
.collect::<Vec<i32>>();
|
||||
(nums[0], nums[1])
|
||||
}).
|
||||
|
||||
// println!("Our Input\n\n{}", INPUT);
|
||||
let mut left_column: Vec<i32> = vec![];
|
||||
let mut right_column: Vec<i32> = vec![];
|
||||
|
||||
for line in INPUT.lines() {
|
||||
let nums: Vec<i32> = line
|
||||
.split(" ")
|
||||
.map(|item| item.parse().expect("Input was not a valid number"))
|
||||
.collect();
|
||||
left_column.push(nums[0]);
|
||||
right_column.push(nums[1]);
|
||||
}
|
||||
|
||||
// Part 1
|
||||
// left_column.sort();
|
||||
// right_column.sort();
|
||||
//
|
||||
// let mut total_distance = 0;
|
||||
// for i in 0..left_column.len() {
|
||||
// let distance = (left_column[i] - right_column[i]).abs();
|
||||
// total_distance += distance;
|
||||
// }
|
||||
// println!("part 1 answer: {}\n", total_distance);
|
||||
|
||||
// Part 2
|
||||
// sodifjsdjif
|
||||
let mut lookup: HashMap<i32, i32> = HashMap::new();
|
||||
for n in right_column.iter() {
|
||||
let count = lookup.entry(*n).or_insert(0);
|
||||
*count += 1;
|
||||
}
|
||||
|
||||
let mut sum = 0;
|
||||
for n in left_column.iter() {
|
||||
// how many times is `n` in the right column
|
||||
let mut r = lookup.get(n).unwrap_or(&0); // O(1)
|
||||
sum += n * r;
|
||||
}
|
||||
println!("part 2 answer: {}", sum);
|
||||
}
|
64
flake.lock
generated
Normal file
64
flake.lock
generated
Normal file
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nix-filter": {
|
||||
"locked": {
|
||||
"lastModified": 1731533336,
|
||||
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
|
||||
"owner": "numtide",
|
||||
"repo": "nix-filter",
|
||||
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "nix-filter",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1733581040,
|
||||
"narHash": "sha256-Qn3nPMSopRQJgmvHzVqPcE3I03zJyl8cSbgnnltfFDY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "22c3f2cf41a0e70184334a958e6b124fb0ce3e01",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nix-filter": "nix-filter",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1733625333,
|
||||
"narHash": "sha256-tIML2axjm4AnlKP29upVJxzBpj4Cy4ak+PKonqQtXmc=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "430c8b054e45ea44fd2c9521a378306ada507a6c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
66
flake.nix
Normal file
66
flake.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
description = "AOC.";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
nix-filter.url = "github:numtide/nix-filter";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
nix-filter,
|
||||
...
|
||||
}:
|
||||
let
|
||||
# Utilities
|
||||
inherit (nixpkgs) lib;
|
||||
# Define the systems to support (all Linux systems exposed by nixpkgs)
|
||||
systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux;
|
||||
forAllSystems = lib.genAttrs systems;
|
||||
# Create a mapping from system to corresponding nixpkgs : https://nixos.wiki/wiki/Overlays#In_a_Nix_flake
|
||||
nixpkgsFor = forAllSystems (system: (nixpkgs.legacyPackages.${system}.extend rustOverlay));
|
||||
# =========
|
||||
rustOverlay = import rust-overlay;
|
||||
rustVersion = "stable";
|
||||
rustChannel = "latest";
|
||||
in
|
||||
{
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
rust = pkgs.rust-bin.${rustVersion}.${rustChannel}.default.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
"rust-analyzer"
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
nativeBuildInputs = (
|
||||
with pkgs;
|
||||
[
|
||||
rust
|
||||
sccache
|
||||
]
|
||||
);
|
||||
|
||||
buildInputs = [ ];
|
||||
|
||||
shellHook = ''
|
||||
echo "RUST C: "$(rustc --version)" - "$(which rustc)
|
||||
export RUSTC_WRAPPER="sccache"
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue