adding workspace and clippy watnings

This commit is contained in:
Dylan Thies
2023-08-28 18:37:44 -04:00
parent e970fd9873
commit 8a233f61bf
24 changed files with 149 additions and 107 deletions

38
Cargo.lock generated
View File

@@ -4,18 +4,18 @@ version = 3
[[package]]
name = "day1"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day10"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day11"
version = "0.1.0"
version = "2022.0.0"
dependencies = [
"derive-getters",
"itertools 0.11.0",
"itertools",
"log",
"nom",
]
@@ -24,7 +24,7 @@ dependencies = [
name = "day12"
version = "0.1.0"
dependencies = [
"itertools 0.11.0",
"itertools",
"log",
]
@@ -32,43 +32,44 @@ dependencies = [
name = "day13"
version = "2022.0.0"
dependencies = [
"log",
"nom",
]
[[package]]
name = "day2"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day3"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day4"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day5"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day6"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day7"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "day8"
version = "0.1.0"
version = "2022.0.0"
dependencies = [
"itertools 0.10.5",
"itertools",
]
[[package]]
name = "day9"
version = "0.1.0"
version = "2022.0.0"
[[package]]
name = "derive-getters"
@@ -87,15 +88,6 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.11.0"

View File

@@ -14,6 +14,7 @@ members = [
"day12",
"day13",
]
resolver = "2"
[workspace.package]

View File

@@ -1,7 +1,9 @@
[package]
name = "day1"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::fs::File;
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
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>();
//elves.sort();
//let max = elves.len() - 1;
//part 1 is get the max
println!("Part 1: {max}");
//Part 2 is get the sum of the largest 3
//let counts: u64 = elves[(max - 2)..].iter().sum();
println!("Part 2: {counts}");
Ok(())

View File

@@ -1,7 +1,9 @@
[package]
name = "day10"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::fs::File;
use std::io::{prelude::*, BufReader};
use std::str;
@@ -7,17 +9,17 @@ fn main() -> std::io::Result<()> {
let file = File::open("input")?;
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 x_reg = 1;
let mut pc = 0;
let mut pc = 0_u32;
reader.lines().for_each(|line| {
let line = line.unwrap();
let op = match line.split(' ').collect::<Vec<_>>()[..] {
["addx", x] => Some(x.parse::<i32>().unwrap()),
["addx", x] => Some(x.parse::<u32>().unwrap()),
["noop"] => None,
_ => panic!("invalid command: {}", line),
_ => panic!("invalid command: {line}"),
};
let steps = if op.is_some() { 2 } else { 1 };
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 {
println!("Part 2: {}", str::from_utf8(&row).unwrap());
}

View File

@@ -1,13 +1,15 @@
[package]
name = "day11"
version = "0.1.0"
edition = "2021"
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
[dependencies]
derive-getters = "0.3.0"
itertools = "0.11.0"
log = "0.4.20"
nom = "7.1.3"
derive-getters.workspace = true
itertools.workspace = true
log.workspace = true
nom.workspace = true

View File

@@ -1,6 +1,8 @@
#![warn(clippy::all, clippy::pedantic)]
use derive_getters::Getters;
use itertools::Itertools;
use log::{debug, trace};
use nom::{
branch::alt,
bytes::complete::tag,
@@ -10,7 +12,6 @@ use nom::{
sequence::{delimited, preceded},
IResult, Parser,
};
use log::{debug, trace};
use std::{
collections::VecDeque, error, fmt::Display, fs::File, io::Read, num::ParseIntError,
str::FromStr,
@@ -150,8 +151,12 @@ impl Test {
let (input, true_to) = match preceded(
tag("If true: throw to monkey "),
nom::character::complete::u64.map(|x| usize::try_from(x).unwrap()),
)(input){
Err(e) => {println!("{e:?}"); Err(e)},
)(input)
{
Err(e) => {
println!("{e:?}");
Err(e)
}
x => x,
}?;
trace!("parse test 4");
@@ -348,7 +353,10 @@ fn main() {
.product::<u64>();
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 i in 0..monkeys_game2.len() {

View File

@@ -1,8 +1,9 @@
[package]
name = "day2"
version = "0.1.0"
edition = "2021"
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
[dependencies]

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::fs::File;
use std::io::{prelude::*, BufReader};
@@ -61,7 +63,7 @@ impl std::str::FromStr for Game {
let opponent: Choice = str_split[0].parse()?;
// game1
//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(),
"Y" => str_split[0].parse()?,
"Z" => opponent.loses(),

View File

@@ -1,7 +1,9 @@
[package]
name = "day3"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::fs::File;
use std::io::{prelude::*, BufReader};
@@ -28,22 +30,21 @@ fn main() -> std::io::Result<()> {
.lines()
.fold(Vec::new(), |mut acc: Vec<Vec<String>>, line| {
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
})
.iter()
.map(|group| {
let (g1, g2, g3) = match group.as_slice() {
[g1, g2, g3] => (g1, g2, g3),
_ => panic!("not get here"),
let [g1, g2, g3] = group.as_slice() else {
panic!("not get here")
};
match g1
.chars()
.fold(Vec::new(), |mut combo: Vec<char>, ch| {
if g2.contains(ch) {
combo.push(ch)
combo.push(ch);
}
combo
})

View File

@@ -1,7 +1,9 @@
[package]
name = "day4"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::fs::File;
use std::io::{prelude::*, BufReader};

View File

@@ -1,7 +1,9 @@
[package]
name = "day5"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::fs::File;
use std::io::{prelude::*, BufReader};
@@ -40,7 +42,7 @@ impl GameBoard {
self.board
.iter()
.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 {
@@ -50,12 +52,12 @@ impl From<Vec<String>> for GameBoard {
// get labels
let labels = label_vec
.split_whitespace()
.map(|x| x.to_string())
.map(std::string::ToString::to_string)
.collect::<Vec<String>>();
//TODO sscanf for crates
board_vec.reverse();
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)| {
let (begin, end) = (i * 4, std::cmp::min(i * 4 + 4, line.len()));
let crate_str = line[begin..end]
@@ -65,8 +67,8 @@ impl From<Vec<String>> for GameBoard {
if !crate_str.is_empty() {
col.push(Crate { label: crate_str });
}
})
});
}
GameBoard {
_labels: labels,
board,
@@ -94,10 +96,10 @@ fn main() -> std::io::Result<()> {
acc
},
);
println!("{:?}", board_lines);
println!("{board_lines:?}");
let mut board = GameBoard::from(board_lines);
movement_lines.iter().for_each(|line| {
for line in &movement_lines {
match line
.split_whitespace()
.filter_map(|x| x.parse::<usize>().ok())
@@ -112,7 +114,7 @@ fn main() -> std::io::Result<()> {
.collect::<Vec<usize>>()
),
};
});
}
println!("{}", board.get_tops());

View File

@@ -1,7 +1,9 @@
[package]
name = "day6"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::collections::HashMap;
use std::fs::File;
use std::io::{prelude::*, BufReader};
@@ -18,7 +20,7 @@ fn main() -> std::io::Result<()> {
}
holder.insert(c, true);
}
println!("Part 1: line: {} marker at: {}", line_no, i);
println!("Part 1: line: {line_no} marker at: {i}");
break;
}
'checker: for i in 14..line.len() {
@@ -30,7 +32,7 @@ fn main() -> std::io::Result<()> {
}
holder.insert(c, true);
}
println!("Part 2: line: {} marker at: {}", line_no, i);
println!("Part 2: line: {line_no} marker at: {i}");
break;
}
});

View File

@@ -1,7 +1,9 @@
[package]
name = "day7"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::cell::RefCell;
use std::fs::File;
use std::io::{prelude::*, BufReader};
@@ -15,7 +17,7 @@ impl Sizer for Vec<usize> {
impl<T: Sizer> Sizer for Vec<T> {
fn size(&self) -> usize {
self.iter().map(|x| x.size()).sum()
self.iter().map(Sizer::size).sum()
}
}
@@ -50,7 +52,7 @@ impl MyDir {
.iter()
.filter_map(|x| match x {
FileSystemTypes::MyDir(y) => Some(y),
_ => None,
FileSystemTypes::MyFile(_) => None,
})
.find(|x| *x.borrow().name == dir)?
.clone(),
@@ -63,7 +65,7 @@ impl MyDir {
}));
}
//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_
.borrow_mut()
.objects
@@ -136,11 +138,11 @@ fn main() -> std::io::Result<()> {
if ls_mode && line.as_bytes()[0] != b'$' {
//do adding to cursor
match line.split_whitespace().collect::<Vec<_>>()[..] {
["dir", name] => MyDir::mkdir(cursor.clone(), name),
["dir", name] => MyDir::mkdir(&cursor.clone(), name),
[size, name] => cursor
.borrow_mut()
.touch(name, size.parse::<usize>().unwrap()),
_ => panic!("oops {}", line),
_ => panic!("oops {line}"),
};
// end the for_each
return;
@@ -155,13 +157,13 @@ fn main() -> std::io::Result<()> {
["$", "cd", "/"] => root.clone(), //set current directory back to root
["$", "cd", ".."] => cursor.borrow().move_up().unwrap(),
["$", "cd", dir] => cursor.borrow().move_down(dir).unwrap(),
_ => panic!("unknown command {}", line),
_ => panic!("unknown command {line}"),
}
});
let mut part1 = Vec::new();
let max = recurse_part1(&mut part1, &root.borrow());
let part1_ans: usize = part1.iter().filter(|x| **x <= 100_000).sum();
println!("Part 1: {}", part1_ans);
println!("Part 1: {part1_ans}");
//part 2
let free_space = 70_000_000_usize - max;

View File

@@ -1,9 +1,11 @@
[package]
name = "day8"
version = "0.1.0"
edition = "2021"
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
[dependencies]
itertools = "0.10.5"
itertools.workspace = true

View File

@@ -1,27 +1,33 @@
#![warn(clippy::all, clippy::pedantic)]
use itertools::Itertools;
use std::fs::File;
use std::io::{prelude::*, BufReader};
fn main() -> std::io::Result<()> {
//Read in file
let file = File::open("input")?;
fn get_board(file: &File) -> Vec<Vec<u8>> {
let reader = BufReader::new(file);
let board = reader
reader
.lines()
.map(|line| {
line.unwrap()
.matches(char::is_numeric)
.map(|num| num.parse::<u8>().unwrap())
.collect::<Vec<_>>()
.map(|num| num.parse().unwrap())
.collect()
})
.collect::<Vec<Vec<_>>>();
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")
.collect()
}
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 max_in_row_from_left = vec![0_usize; 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();
println!("Part 1: {}", part1);
println!("Part 1: {part1}");
let part2 = scores
.iter()
.map(|x| x.iter().max().unwrap())
.max()
.unwrap();
println!("Part 2: {}", part2);
println!("Part 2: {part2}");
Ok(())
}

View File

@@ -1,7 +1,9 @@
[package]
name = "day9"
version = "0.1.0"
edition = "2021"
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

View File

@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
use std::collections::HashSet;
use std::fs::File;
use std::io::{prelude::*, BufReader};
@@ -7,7 +9,7 @@ fn main() -> std::io::Result<()> {
let file = File::open("input")?;
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];
//intialize the visited
@@ -20,7 +22,7 @@ fn main() -> std::io::Result<()> {
let line = line.unwrap();
let (direction, steps) = match line.split(' ').collect::<Vec<&str>>()[..] {
[dir, step] => (dir, step.parse::<usize>().unwrap()),
_ => panic!("failed parseing line {}", line),
_ => panic!("failed parseing line {line}"),
};
for _ in 0..steps {
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,
"U" => 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);
snake[0] = new_head_pos;
@@ -60,8 +62,8 @@ fn main() -> std::io::Result<()> {
}
});
let part1 = visited[1].len();
println!("Part 1: {}", part1);
println!("Part 1: {part1}");
let part2 = visited[9].len();
println!("Part 2: {}", part2);
println!("Part 2: {part2}");
Ok(())
}