Push work so far
This commit is contained in:
parent
a8ece7c6d8
commit
9651b3a12c
7 changed files with 143 additions and 5 deletions
46
.vscode/aoc.code-snippets
vendored
Normal file
46
.vscode/aoc.code-snippets
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
// Place your advent-of-code-2023 workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
|
||||||
|
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
|
||||||
|
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
|
||||||
|
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
|
||||||
|
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
|
||||||
|
// Placeholders with the same ids are connected.
|
||||||
|
// Example:
|
||||||
|
// "Print to console": {
|
||||||
|
// "scope": "javascript,typescript",
|
||||||
|
// "prefix": "log",
|
||||||
|
// "body": [
|
||||||
|
// "console.log('$1');",
|
||||||
|
// "$2"
|
||||||
|
// ],
|
||||||
|
// "description": "Log output to console"
|
||||||
|
// }
|
||||||
|
"Day template": {
|
||||||
|
"scope": "rust",
|
||||||
|
"prefix": "day",
|
||||||
|
"body": [
|
||||||
|
"use crate::utils::Day;",
|
||||||
|
"",
|
||||||
|
"#[derive(Debug, Default)]",
|
||||||
|
"pub struct Day$1 {",
|
||||||
|
"\tpub input: String,",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"impl Day for Day$1 {",
|
||||||
|
"\tfn part1(&mut self) -> String {",
|
||||||
|
"\t\t",
|
||||||
|
"\t\t",
|
||||||
|
"\t\ttodo!()",
|
||||||
|
"\t}",
|
||||||
|
"",
|
||||||
|
"\tfn part2(&mut self) -> String {",
|
||||||
|
"\t\t",
|
||||||
|
"\t\t",
|
||||||
|
"\t\ttodo!()",
|
||||||
|
"\t}",
|
||||||
|
"}"
|
||||||
|
|
||||||
|
],
|
||||||
|
"description": "Creates a template for an AOC day"
|
||||||
|
}
|
||||||
|
}
|
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -21,6 +21,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
name = "advent"
|
name = "advent"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"array2d",
|
||||||
"clru",
|
"clru",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
@ -122,6 +123,12 @@ dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "array2d"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8b39cb2c1bf5a7c0dd097aa95ab859cf87dab5a4328900f5388942dc1889f74"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
|
@ -160,9 +160,10 @@ async fn main() {
|
||||||
let deviation = (((max - min).pow(2) / 16) as f64).sqrt() as u128;
|
let deviation = (((max - min).pow(2) / 16) as f64).sqrt() as u128;
|
||||||
let range = max - min;
|
let range = max - min;
|
||||||
let median = if timings.len() % 2 == 0 {
|
let median = if timings.len() % 2 == 0 {
|
||||||
(timings[timings.len()/2-1]+timings[timings.len()/2]).as_nanos() as f64 / 2.0
|
(timings[timings.len() / 2 - 1] + timings[timings.len() / 2]).as_nanos() as f64
|
||||||
|
/ 2.0
|
||||||
} else {
|
} else {
|
||||||
timings[timings.len()/2].as_nanos() as f64
|
timings[timings.len() / 2].as_nanos() as f64
|
||||||
};
|
};
|
||||||
|
|
||||||
let (avg, avg_units) = utils::unitify(avg as f64);
|
let (avg, avg_units) = utils::unitify(avg as f64);
|
||||||
|
|
|
@ -12,6 +12,7 @@ scraper = "0.18.1"
|
||||||
reqwest = "0.11.22"
|
reqwest = "0.11.22"
|
||||||
itertools = "0.12.0"
|
itertools = "0.12.0"
|
||||||
clru = "0.6.1"
|
clru = "0.6.1"
|
||||||
|
array2d = "0.3.2"
|
||||||
|
|
||||||
[dependencies.getrandom]
|
[dependencies.getrandom]
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
|
80
lib/src/day17/mod.rs
Normal file
80
lib/src/day17/mod.rs
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
use crate::utils::Day;
|
||||||
|
use array2d::Array2D;
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Day17 {
|
||||||
|
pub input: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
pub enum Direction {
|
||||||
|
North,
|
||||||
|
East,
|
||||||
|
South,
|
||||||
|
West,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct State {
|
||||||
|
cost: usize,
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
tentative_distance: Option<usize>,
|
||||||
|
last_direction: Option<Direction>,
|
||||||
|
moves_without_turn: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day for Day17 {
|
||||||
|
fn part1(&mut self) -> String {
|
||||||
|
let columns = self.input.find('\n').unwrap();
|
||||||
|
let rows = (self.input.len() + 1) / columns - 1;
|
||||||
|
|
||||||
|
let mut parsed = Array2D::from_iter_row_major(
|
||||||
|
self.input.split('\n').enumerate().flat_map(|(i, str)| {
|
||||||
|
str.chars().enumerate().map(move |(j, b)| State {
|
||||||
|
cost: b.to_digit(10).unwrap() as usize,
|
||||||
|
x: i,
|
||||||
|
y: j,
|
||||||
|
tentative_distance: if i == 0 && j == 0 {
|
||||||
|
Some(b.to_digit(10).unwrap() as usize)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
moves_without_turn: if i == 0 && j == 0 {
|
||||||
|
Some(1)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
last_direction: if i == 0 && j == 0 {
|
||||||
|
Some(Direction::East)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
rows,
|
||||||
|
columns,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let unvisited = Vec::<(usize, usize)>::from_iter(
|
||||||
|
(0..columns).flat_map(|i| (0..rows).map(move |j| (i, j))),
|
||||||
|
);
|
||||||
|
let mut current = (0usize, 0usize);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let current = &parsed[current];
|
||||||
|
|
||||||
|
if current.last_direction != Some(Direction::North)
|
||||||
|
&& !(current.last_direction == Some(Direction::West) && current.moves_without_turn == Some(3))
|
||||||
|
&& let Some(neighbor) = parsed.get_mut(current.x - 1, current.y)
|
||||||
|
{ // Going west
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn part2(&mut self) -> String {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(inline_const)]
|
#![feature(inline_const, let_chains)]
|
||||||
|
|
||||||
use std::{collections::HashMap, num::NonZeroUsize};
|
use std::{collections::HashMap, num::NonZeroUsize};
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ use day13::Day13;
|
||||||
use day14::Day14;
|
use day14::Day14;
|
||||||
use day15::Day15;
|
use day15::Day15;
|
||||||
use day16::Day16;
|
use day16::Day16;
|
||||||
|
use day17::Day17;
|
||||||
use day2::Day2;
|
use day2::Day2;
|
||||||
use day3::Day3;
|
use day3::Day3;
|
||||||
use day4::Day4;
|
use day4::Day4;
|
||||||
|
@ -32,6 +33,7 @@ pub mod day13;
|
||||||
pub mod day14;
|
pub mod day14;
|
||||||
pub mod day15;
|
pub mod day15;
|
||||||
pub mod day16;
|
pub mod day16;
|
||||||
|
pub mod day17;
|
||||||
pub mod day2;
|
pub mod day2;
|
||||||
pub mod day3;
|
pub mod day3;
|
||||||
pub mod day4;
|
pub mod day4;
|
||||||
|
@ -79,6 +81,7 @@ pub fn get_day(day: u8, input: String) -> Box<dyn Day> {
|
||||||
14 => Box::new(Day14 { input }),
|
14 => Box::new(Day14 { input }),
|
||||||
15 => Box::new(Day15 { input }),
|
15 => Box::new(Day15 { input }),
|
||||||
16 => Box::new(Day16 { input }),
|
16 => Box::new(Day16 { input }),
|
||||||
|
17 => Box::new(Day17 { input }),
|
||||||
_ => panic!("Invalid day #"),
|
_ => panic!("Invalid day #"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue