Compare commits
No commits in common. "4df3715c5dde0d54eb20ac9f5181175ec3d3bc7f" and "e6abd89ff1d93666cf2d8d9ecfbb0db71e5996fc" have entirely different histories.
4df3715c5d
...
e6abd89ff1
6 changed files with 2 additions and 146 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -13,8 +13,6 @@ name = "advent-of-code-2024"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"indoc",
|
|
||||||
"itertools",
|
|
||||||
"ureq",
|
"ureq",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -65,12 +63,6 @@ version = "0.15.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
version = "1.0.35"
|
version = "1.0.35"
|
||||||
|
@ -240,21 +232,6 @@ dependencies = [
|
||||||
"icu_properties",
|
"icu_properties",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indoc"
|
|
||||||
version = "2.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.167"
|
version = "0.2.167"
|
||||||
|
|
|
@ -5,6 +5,4 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
indoc = "2.0.5"
|
|
||||||
itertools = "0.13.0"
|
|
||||||
ureq = "2.11.0"
|
ureq = "2.11.0"
|
||||||
|
|
|
@ -49,7 +49,7 @@ fn load(day: u8) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let token = std::env::var("TOKEN").expect("TOKEN is not set");
|
let token = std::env::var("TOKEN").expect("TOKEN is not set");
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
ureq::get(format!("https://adventofcode.com/2024/day/{day}/input").as_str())
|
ureq::get(format!("https://adventofcode.com/2023/day/{day}/input").as_str())
|
||||||
.set("Cookie", format!("session={token}").as_str())
|
.set("Cookie", format!("session={token}").as_str())
|
||||||
.call()?
|
.call()?
|
||||||
.into_string()?
|
.into_string()?
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
use itertools::Itertools;
|
|
||||||
|
|
||||||
use crate::common::{Answer, Solution};
|
|
||||||
|
|
||||||
pub struct Day01;
|
|
||||||
|
|
||||||
impl Solution for Day01 {
|
|
||||||
fn name(&self) -> &'static str {
|
|
||||||
"Historian Hysteria"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part_a(&self, input: &str) -> Answer {
|
|
||||||
let (mut left, mut right) = input
|
|
||||||
.lines()
|
|
||||||
.map(|l| l.split_once(" ").unwrap())
|
|
||||||
.map(|(n1, n2)| (n1.parse::<i32>().unwrap(), n2.parse::<i32>().unwrap()))
|
|
||||||
.collect::<(Vec<_>, Vec<_>)>();
|
|
||||||
|
|
||||||
left.sort();
|
|
||||||
right.sort();
|
|
||||||
|
|
||||||
let sum: i32 = left
|
|
||||||
.into_iter()
|
|
||||||
.zip(right)
|
|
||||||
.map(|(a, b)| (a - b).abs())
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
Answer::Number(sum as u64)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part_b(&self, input: &str) -> Answer {
|
|
||||||
let (left, right) = input
|
|
||||||
.lines()
|
|
||||||
.map(|l| l.split_once(" ").unwrap())
|
|
||||||
.map(|(n1, n2)| (n1.parse::<i32>().unwrap(), n2.parse::<i32>().unwrap()))
|
|
||||||
.collect::<(Vec<_>, Vec<_>)>();
|
|
||||||
|
|
||||||
let counts = right.into_iter().counts();
|
|
||||||
|
|
||||||
let sum = left
|
|
||||||
.into_iter()
|
|
||||||
.map(|n| counts.get(&n).unwrap_or(&0) * (n as usize))
|
|
||||||
.sum::<usize>();
|
|
||||||
|
|
||||||
Answer::Number(sum as u64)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::Day01;
|
|
||||||
use crate::common::Solution;
|
|
||||||
|
|
||||||
use indoc::indoc;
|
|
||||||
|
|
||||||
const INPUT: &str = indoc! {"
|
|
||||||
3 4
|
|
||||||
4 3
|
|
||||||
2 5
|
|
||||||
1 3
|
|
||||||
3 9
|
|
||||||
3 3
|
|
||||||
"};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn part_a() {
|
|
||||||
assert_eq!(Day01.part_a(INPUT), 11.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn part_b() {
|
|
||||||
assert_eq!(Day01.part_b(INPUT), 31.into());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,3 @@
|
||||||
use crate::common::Solution;
|
use crate::common::Solution;
|
||||||
|
|
||||||
mod day_01;
|
pub const SOLUTIONS: &[&dyn Solution] = &[];
|
||||||
|
|
||||||
pub const SOLUTIONS: &[&dyn Solution] = &[&day_01::Day01];
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
use crate::common::{Answer, Solution};
|
|
||||||
|
|
||||||
pub struct DayXX;
|
|
||||||
|
|
||||||
impl Solution for DayXX {
|
|
||||||
fn name(&self) -> &'static str {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part_a(&self, input: &str) -> Answer {
|
|
||||||
Answer::Unimplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part_b(&self, input: &str) -> Answer {
|
|
||||||
Answer::Unimplemented
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::DayXX;
|
|
||||||
use crate::common::Solution;
|
|
||||||
|
|
||||||
use indoc::indoc;
|
|
||||||
|
|
||||||
const INPUT_A: &str = indoc! {"
|
|
||||||
|
|
||||||
"};
|
|
||||||
|
|
||||||
const INPUT_B: &str = indoc! {"
|
|
||||||
|
|
||||||
"};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn part_a() {
|
|
||||||
assert_eq!(DayXX.part_a(INPUT_A), crate::common::Answer::Unimplemented);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn part_b() {
|
|
||||||
assert_eq!(DayXX.part_b(INPUT_B), crate::common::Answer::Unimplemented);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue