adding workspace and clippy watnings
This commit is contained in:
38
Cargo.lock
generated
38
Cargo.lock
generated
@@ -4,18 +4,18 @@ version = 3
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day1"
|
name = "day1"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day10"
|
name = "day10"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day11"
|
name = "day11"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive-getters",
|
"derive-getters",
|
||||||
"itertools 0.11.0",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
@@ -24,7 +24,7 @@ dependencies = [
|
|||||||
name = "day12"
|
name = "day12"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools 0.11.0",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -32,43 +32,44 @@ dependencies = [
|
|||||||
name = "day13"
|
name = "day13"
|
||||||
version = "2022.0.0"
|
version = "2022.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"log",
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day2"
|
name = "day2"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day3"
|
name = "day3"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day4"
|
name = "day4"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day5"
|
name = "day5"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day6"
|
name = "day6"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day7"
|
name = "day7"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day8"
|
name = "day8"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools 0.10.5",
|
"itertools",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day9"
|
name = "day9"
|
||||||
version = "0.1.0"
|
version = "2022.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive-getters"
|
name = "derive-getters"
|
||||||
@@ -87,15 +88,6 @@ version = "1.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.10.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ members = [
|
|||||||
"day12",
|
"day12",
|
||||||
"day13",
|
"day13",
|
||||||
]
|
]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day1"
|
name = "day1"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
|
|
||||||
@@ -20,16 +22,13 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
//order the elves since we don't care about position anymore
|
//order the elves since we don't care about position anymore
|
||||||
elves.sort_by(|a, b| b.cmp(a));
|
elves.sort_by(|a, b| b.cmp(a));
|
||||||
let max = *elves.get(0).expect("faliure");
|
let max = *elves.first().expect("faliure");
|
||||||
let counts = elves.iter().take(3).sum::<u64>();
|
let counts = elves.iter().take(3).sum::<u64>();
|
||||||
//elves.sort();
|
|
||||||
//let max = elves.len() - 1;
|
|
||||||
|
|
||||||
//part 1 is get the max
|
//part 1 is get the max
|
||||||
println!("Part 1: {max}");
|
println!("Part 1: {max}");
|
||||||
|
|
||||||
//Part 2 is get the sum of the largest 3
|
//Part 2 is get the sum of the largest 3
|
||||||
//let counts: u64 = elves[(max - 2)..].iter().sum();
|
|
||||||
println!("Part 2: {counts}");
|
println!("Part 2: {counts}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day10"
|
name = "day10"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
use std::str;
|
use std::str;
|
||||||
@@ -7,17 +9,17 @@ fn main() -> std::io::Result<()> {
|
|||||||
let file = File::open("input")?;
|
let file = File::open("input")?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
let mut part1: Vec<i32> = Vec::new();
|
let mut part1: Vec<_> = Vec::new();
|
||||||
let mut part2 = [[b'.'; 40]; 6];
|
let mut part2 = [[b'.'; 40]; 6];
|
||||||
let mut x_reg = 1;
|
let mut x_reg = 1;
|
||||||
let mut pc = 0;
|
let mut pc = 0_u32;
|
||||||
|
|
||||||
reader.lines().for_each(|line| {
|
reader.lines().for_each(|line| {
|
||||||
let line = line.unwrap();
|
let line = line.unwrap();
|
||||||
let op = match line.split(' ').collect::<Vec<_>>()[..] {
|
let op = match line.split(' ').collect::<Vec<_>>()[..] {
|
||||||
["addx", x] => Some(x.parse::<i32>().unwrap()),
|
["addx", x] => Some(x.parse::<u32>().unwrap()),
|
||||||
["noop"] => None,
|
["noop"] => None,
|
||||||
_ => panic!("invalid command: {}", line),
|
_ => panic!("invalid command: {line}"),
|
||||||
};
|
};
|
||||||
let steps = if op.is_some() { 2 } else { 1 };
|
let steps = if op.is_some() { 2 } else { 1 };
|
||||||
for i in 0..steps {
|
for i in 0..steps {
|
||||||
@@ -38,7 +40,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("Part 1: {}", part1.iter().sum::<i32>());
|
println!("Part 1: {}", part1.iter().sum::<u32>());
|
||||||
for row in part2 {
|
for row in part2 {
|
||||||
println!("Part 2: {}", str::from_utf8(&row).unwrap());
|
println!("Part 2: {}", str::from_utf8(&row).unwrap());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day11"
|
name = "day11"
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
description = "AOC 2022 Day 11"
|
description = "AOC 2022 Day 11"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
derive-getters = "0.3.0"
|
derive-getters.workspace = true
|
||||||
itertools = "0.11.0"
|
itertools.workspace = true
|
||||||
log = "0.4.20"
|
log.workspace = true
|
||||||
nom = "7.1.3"
|
nom.workspace = true
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use log::{debug, trace};
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::tag,
|
bytes::complete::tag,
|
||||||
@@ -10,7 +12,6 @@ use nom::{
|
|||||||
sequence::{delimited, preceded},
|
sequence::{delimited, preceded},
|
||||||
IResult, Parser,
|
IResult, Parser,
|
||||||
};
|
};
|
||||||
use log::{debug, trace};
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::VecDeque, error, fmt::Display, fs::File, io::Read, num::ParseIntError,
|
collections::VecDeque, error, fmt::Display, fs::File, io::Read, num::ParseIntError,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
@@ -150,8 +151,12 @@ impl Test {
|
|||||||
let (input, true_to) = match preceded(
|
let (input, true_to) = match preceded(
|
||||||
tag("If true: throw to monkey "),
|
tag("If true: throw to monkey "),
|
||||||
nom::character::complete::u64.map(|x| usize::try_from(x).unwrap()),
|
nom::character::complete::u64.map(|x| usize::try_from(x).unwrap()),
|
||||||
)(input){
|
)(input)
|
||||||
Err(e) => {println!("{e:?}"); Err(e)},
|
{
|
||||||
|
Err(e) => {
|
||||||
|
println!("{e:?}");
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
x => x,
|
x => x,
|
||||||
}?;
|
}?;
|
||||||
trace!("parse test 4");
|
trace!("parse test 4");
|
||||||
@@ -348,7 +353,10 @@ fn main() {
|
|||||||
.product::<u64>();
|
.product::<u64>();
|
||||||
println!("Part 1: {val}");
|
println!("Part 1: {val}");
|
||||||
|
|
||||||
let magic = monkeys_game2.iter().map(|x| x.test().divisor()).product::<u64>();
|
let magic = monkeys_game2
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.test().divisor())
|
||||||
|
.product::<u64>();
|
||||||
|
|
||||||
for _ in 0..10_000 {
|
for _ in 0..10_000 {
|
||||||
for i in 0..monkeys_game2.len() {
|
for i in 0..monkeys_game2.len() {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day2"
|
name = "day2"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ impl std::str::FromStr for Game {
|
|||||||
let opponent: Choice = str_split[0].parse()?;
|
let opponent: Choice = str_split[0].parse()?;
|
||||||
// game1
|
// game1
|
||||||
//let you: Choice = str_split[1].parse()?;
|
//let you: Choice = str_split[1].parse()?;
|
||||||
let you = match str_split[1] {
|
let you = match *str_split.get(1).expect("msg") {
|
||||||
"X" => opponent.beats(),
|
"X" => opponent.beats(),
|
||||||
"Y" => str_split[0].parse()?,
|
"Y" => str_split[0].parse()?,
|
||||||
"Z" => opponent.loses(),
|
"Z" => opponent.loses(),
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day3"
|
name = "day3"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
|
|
||||||
@@ -28,22 +30,21 @@ fn main() -> std::io::Result<()> {
|
|||||||
.lines()
|
.lines()
|
||||||
.fold(Vec::new(), |mut acc: Vec<Vec<String>>, line| {
|
.fold(Vec::new(), |mut acc: Vec<Vec<String>>, line| {
|
||||||
if acc.is_empty() || acc.last().unwrap().len() == 3 {
|
if acc.is_empty() || acc.last().unwrap().len() == 3 {
|
||||||
acc.push(Vec::new())
|
acc.push(Vec::new());
|
||||||
}
|
}
|
||||||
acc.last_mut().unwrap().push(line.unwrap());
|
acc.last_mut().unwrap().push(line.unwrap());
|
||||||
acc
|
acc
|
||||||
})
|
})
|
||||||
.iter()
|
.iter()
|
||||||
.map(|group| {
|
.map(|group| {
|
||||||
let (g1, g2, g3) = match group.as_slice() {
|
let [g1, g2, g3] = group.as_slice() else {
|
||||||
[g1, g2, g3] => (g1, g2, g3),
|
panic!("not get here")
|
||||||
_ => panic!("not get here"),
|
|
||||||
};
|
};
|
||||||
match g1
|
match g1
|
||||||
.chars()
|
.chars()
|
||||||
.fold(Vec::new(), |mut combo: Vec<char>, ch| {
|
.fold(Vec::new(), |mut combo: Vec<char>, ch| {
|
||||||
if g2.contains(ch) {
|
if g2.contains(ch) {
|
||||||
combo.push(ch)
|
combo.push(ch);
|
||||||
}
|
}
|
||||||
combo
|
combo
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day4"
|
name = "day4"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day5"
|
name = "day5"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ impl GameBoard {
|
|||||||
self.board
|
self.board
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.last().unwrap().label.clone())
|
.map(|x| x.last().unwrap().label.clone())
|
||||||
.fold("".to_string(), |acc, x| acc + &x)
|
.fold(String::new(), |acc, x| acc + &x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<Vec<String>> for GameBoard {
|
impl From<Vec<String>> for GameBoard {
|
||||||
@@ -50,12 +52,12 @@ impl From<Vec<String>> for GameBoard {
|
|||||||
// get labels
|
// get labels
|
||||||
let labels = label_vec
|
let labels = label_vec
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.map(|x| x.to_string())
|
.map(std::string::ToString::to_string)
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
//TODO sscanf for crates
|
//TODO sscanf for crates
|
||||||
board_vec.reverse();
|
board_vec.reverse();
|
||||||
let mut board = vec![Vec::new(); labels.len()];
|
let mut board = vec![Vec::new(); labels.len()];
|
||||||
board_vec.iter().for_each(|line| {
|
for line in &board_vec {
|
||||||
board.iter_mut().enumerate().for_each(|(i, col)| {
|
board.iter_mut().enumerate().for_each(|(i, col)| {
|
||||||
let (begin, end) = (i * 4, std::cmp::min(i * 4 + 4, line.len()));
|
let (begin, end) = (i * 4, std::cmp::min(i * 4 + 4, line.len()));
|
||||||
let crate_str = line[begin..end]
|
let crate_str = line[begin..end]
|
||||||
@@ -65,8 +67,8 @@ impl From<Vec<String>> for GameBoard {
|
|||||||
if !crate_str.is_empty() {
|
if !crate_str.is_empty() {
|
||||||
col.push(Crate { label: crate_str });
|
col.push(Crate { label: crate_str });
|
||||||
}
|
}
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
GameBoard {
|
GameBoard {
|
||||||
_labels: labels,
|
_labels: labels,
|
||||||
board,
|
board,
|
||||||
@@ -94,10 +96,10 @@ fn main() -> std::io::Result<()> {
|
|||||||
acc
|
acc
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
println!("{:?}", board_lines);
|
println!("{board_lines:?}");
|
||||||
let mut board = GameBoard::from(board_lines);
|
let mut board = GameBoard::from(board_lines);
|
||||||
|
|
||||||
movement_lines.iter().for_each(|line| {
|
for line in &movement_lines {
|
||||||
match line
|
match line
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.filter_map(|x| x.parse::<usize>().ok())
|
.filter_map(|x| x.parse::<usize>().ok())
|
||||||
@@ -112,7 +114,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
.collect::<Vec<usize>>()
|
.collect::<Vec<usize>>()
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
|
||||||
println!("{}", board.get_tops());
|
println!("{}", board.get_tops());
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day6"
|
name = "day6"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
@@ -18,7 +20,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
holder.insert(c, true);
|
holder.insert(c, true);
|
||||||
}
|
}
|
||||||
println!("Part 1: line: {} marker at: {}", line_no, i);
|
println!("Part 1: line: {line_no} marker at: {i}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
'checker: for i in 14..line.len() {
|
'checker: for i in 14..line.len() {
|
||||||
@@ -30,7 +32,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
holder.insert(c, true);
|
holder.insert(c, true);
|
||||||
}
|
}
|
||||||
println!("Part 2: line: {} marker at: {}", line_no, i);
|
println!("Part 2: line: {line_no} marker at: {i}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day7"
|
name = "day7"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
@@ -15,7 +17,7 @@ impl Sizer for Vec<usize> {
|
|||||||
|
|
||||||
impl<T: Sizer> Sizer for Vec<T> {
|
impl<T: Sizer> Sizer for Vec<T> {
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.iter().map(|x| x.size()).sum()
|
self.iter().map(Sizer::size).sum()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ impl MyDir {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|x| match x {
|
.filter_map(|x| match x {
|
||||||
FileSystemTypes::MyDir(y) => Some(y),
|
FileSystemTypes::MyDir(y) => Some(y),
|
||||||
_ => None,
|
FileSystemTypes::MyFile(_) => None,
|
||||||
})
|
})
|
||||||
.find(|x| *x.borrow().name == dir)?
|
.find(|x| *x.borrow().name == dir)?
|
||||||
.clone(),
|
.clone(),
|
||||||
@@ -63,7 +65,7 @@ impl MyDir {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
//has to be a static method...
|
//has to be a static method...
|
||||||
fn mkdir(self_: Rc<RefCell<MyDir>>, name: impl Into<String>) {
|
fn mkdir(self_: &Rc<RefCell<MyDir>>, name: impl Into<String>) {
|
||||||
self_
|
self_
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.objects
|
.objects
|
||||||
@@ -136,11 +138,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
if ls_mode && line.as_bytes()[0] != b'$' {
|
if ls_mode && line.as_bytes()[0] != b'$' {
|
||||||
//do adding to cursor
|
//do adding to cursor
|
||||||
match line.split_whitespace().collect::<Vec<_>>()[..] {
|
match line.split_whitespace().collect::<Vec<_>>()[..] {
|
||||||
["dir", name] => MyDir::mkdir(cursor.clone(), name),
|
["dir", name] => MyDir::mkdir(&cursor.clone(), name),
|
||||||
[size, name] => cursor
|
[size, name] => cursor
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.touch(name, size.parse::<usize>().unwrap()),
|
.touch(name, size.parse::<usize>().unwrap()),
|
||||||
_ => panic!("oops {}", line),
|
_ => panic!("oops {line}"),
|
||||||
};
|
};
|
||||||
// end the for_each
|
// end the for_each
|
||||||
return;
|
return;
|
||||||
@@ -155,13 +157,13 @@ fn main() -> std::io::Result<()> {
|
|||||||
["$", "cd", "/"] => root.clone(), //set current directory back to root
|
["$", "cd", "/"] => root.clone(), //set current directory back to root
|
||||||
["$", "cd", ".."] => cursor.borrow().move_up().unwrap(),
|
["$", "cd", ".."] => cursor.borrow().move_up().unwrap(),
|
||||||
["$", "cd", dir] => cursor.borrow().move_down(dir).unwrap(),
|
["$", "cd", dir] => cursor.borrow().move_down(dir).unwrap(),
|
||||||
_ => panic!("unknown command {}", line),
|
_ => panic!("unknown command {line}"),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let mut part1 = Vec::new();
|
let mut part1 = Vec::new();
|
||||||
let max = recurse_part1(&mut part1, &root.borrow());
|
let max = recurse_part1(&mut part1, &root.borrow());
|
||||||
let part1_ans: usize = part1.iter().filter(|x| **x <= 100_000).sum();
|
let part1_ans: usize = part1.iter().filter(|x| **x <= 100_000).sum();
|
||||||
println!("Part 1: {}", part1_ans);
|
println!("Part 1: {part1_ans}");
|
||||||
|
|
||||||
//part 2
|
//part 2
|
||||||
let free_space = 70_000_000_usize - max;
|
let free_space = 70_000_000_usize - max;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day8"
|
name = "day8"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = "0.10.5"
|
itertools.workspace = true
|
||||||
|
|||||||
@@ -1,27 +1,33 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn get_board(file: &File) -> Vec<Vec<u8>> {
|
||||||
//Read in file
|
|
||||||
let file = File::open("input")?;
|
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
let board = reader
|
reader
|
||||||
.lines()
|
.lines()
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
line.unwrap()
|
line.unwrap()
|
||||||
.matches(char::is_numeric)
|
.matches(char::is_numeric)
|
||||||
.map(|num| num.parse::<u8>().unwrap())
|
.map(|num| num.parse().unwrap())
|
||||||
.collect::<Vec<_>>()
|
.collect()
|
||||||
})
|
})
|
||||||
.collect::<Vec<Vec<_>>>();
|
.collect()
|
||||||
let y_len = board.len();
|
|
||||||
let x_len = board.iter().map(|x| x.len()).max().unwrap();
|
|
||||||
if board.iter().any(|x| x.len() != x_len) {
|
|
||||||
panic!("board isn't square")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
//Read in file
|
||||||
|
let file = File::open("input")?;
|
||||||
|
|
||||||
|
let board = get_board(&file);
|
||||||
|
|
||||||
|
let y_len = board.len();
|
||||||
|
let x_len = board.iter().map(std::vec::Vec::len).max().unwrap();
|
||||||
|
assert!(board.iter().any(|x| x.len() != x_len), "board isn't square");
|
||||||
|
|
||||||
let mut visible: Vec<(usize, usize, u8)> = Vec::new();
|
let mut visible: Vec<(usize, usize, u8)> = Vec::new();
|
||||||
let mut max_in_row_from_left = vec![0_usize; y_len];
|
let mut max_in_row_from_left = vec![0_usize; y_len];
|
||||||
let mut max_in_row_from_right = vec![x_len - 1; y_len];
|
let mut max_in_row_from_right = vec![x_len - 1; y_len];
|
||||||
@@ -142,14 +148,14 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let part1 = visible.iter().unique().count();
|
let part1 = visible.iter().unique().count();
|
||||||
println!("Part 1: {}", part1);
|
println!("Part 1: {part1}");
|
||||||
|
|
||||||
let part2 = scores
|
let part2 = scores
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.iter().max().unwrap())
|
.map(|x| x.iter().max().unwrap())
|
||||||
.max()
|
.max()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Part 2: {}", part2);
|
println!("Part 2: {part2}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "day9"
|
name = "day9"
|
||||||
version = "0.1.0"
|
version.workspace = true
|
||||||
edition = "2021"
|
edition.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{prelude::*, BufReader};
|
use std::io::{prelude::*, BufReader};
|
||||||
@@ -7,7 +9,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
let file = File::open("input")?;
|
let file = File::open("input")?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
let mut snake = vec![(0_i32, 0_i32); 10];
|
let mut snake = [(0_i32, 0_i32); 10];
|
||||||
let mut visited: Vec<HashSet<(i32, i32)>> = vec![HashSet::new(); 10];
|
let mut visited: Vec<HashSet<(i32, i32)>> = vec![HashSet::new(); 10];
|
||||||
|
|
||||||
//intialize the visited
|
//intialize the visited
|
||||||
@@ -20,7 +22,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
let line = line.unwrap();
|
let line = line.unwrap();
|
||||||
let (direction, steps) = match line.split(' ').collect::<Vec<&str>>()[..] {
|
let (direction, steps) = match line.split(' ').collect::<Vec<&str>>()[..] {
|
||||||
[dir, step] => (dir, step.parse::<usize>().unwrap()),
|
[dir, step] => (dir, step.parse::<usize>().unwrap()),
|
||||||
_ => panic!("failed parseing line {}", line),
|
_ => panic!("failed parseing line {line}"),
|
||||||
};
|
};
|
||||||
for _ in 0..steps {
|
for _ in 0..steps {
|
||||||
let (mut cur_head_x, mut cur_head_y) = snake[0];
|
let (mut cur_head_x, mut cur_head_y) = snake[0];
|
||||||
@@ -29,7 +31,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
"R" => cur_head_x += 1,
|
"R" => cur_head_x += 1,
|
||||||
"U" => cur_head_y += 1,
|
"U" => cur_head_y += 1,
|
||||||
"D" => cur_head_y -= 1,
|
"D" => cur_head_y -= 1,
|
||||||
x => panic!("invalid movement {}", x),
|
x => panic!("invalid movement {x}"),
|
||||||
};
|
};
|
||||||
let new_head_pos = (cur_head_x, cur_head_y);
|
let new_head_pos = (cur_head_x, cur_head_y);
|
||||||
snake[0] = new_head_pos;
|
snake[0] = new_head_pos;
|
||||||
@@ -60,8 +62,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
let part1 = visited[1].len();
|
let part1 = visited[1].len();
|
||||||
println!("Part 1: {}", part1);
|
println!("Part 1: {part1}");
|
||||||
let part2 = visited[9].len();
|
let part2 = visited[9].len();
|
||||||
println!("Part 2: {}", part2);
|
println!("Part 2: {part2}");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user