delete accidental submodule

This commit is contained in:
Andrew Glaze 2023-12-14 10:46:45 -05:00
parent 5a87bfb681
commit 51c64d827b
37 changed files with 1637 additions and 1 deletions

@ -1 +0,0 @@
Subproject commit 78aab8ab5ed7c65461663bf6a4c1b31fcdda6cca

7
old/day01/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day1"
version = "0.1.0"

8
old/day01/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

48
old/day01/src/main.rs Normal file
View File

@ -0,0 +1,48 @@
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input = input.split('\n');
let mut sum = 0;
for line in input {
let str_nums: Vec<(&str, &str)> = vec![("one", "1"), ("two", "2"), ("three", "3"), ("four", "4"), ("five", "5"), ("six", "6"), ("seven", "7"), ("eight", "8"), ("nine", "9")];
let mut matches: Vec<(usize, &str)> = vec![];
for str_num in str_nums {
// Get every alphabetic number in the string with it's index
let str_match: Vec<_> = line.match_indices(str_num.0).collect();
// convert the string to a numeral
let mut str_match: Vec<_> = str_match.iter().map(|x| return (x.0, str_num.1)).collect();
matches.append(&mut str_match);
}
// get the numerials from the line with their index
let mut num_matches: Vec<(usize, &str)> = line.match_indices(|x: char| x.is_numeric()).collect();
matches.append(&mut num_matches);
// sort by index
matches.sort_by(|lhs, rhs| lhs.cmp(rhs));
let num = (matches.first().unwrap().1).to_owned() + (matches.last().unwrap().1);
sum += num.parse::<i32>().unwrap();
}
println!("{}", sum);
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input = input.split('\n');
// let mut sum = 0;
// for line in input {
// let chars: Vec<char>= line.chars().filter(|x| x.is_numeric()).collect();
// let mut num = chars.first().unwrap().to_string();
// num += &chars.last().unwrap().to_string();
// let num: u32 = num.parse().unwrap();
// sum += num;
// }
// println!("{}", sum);
// }

7
old/day02/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day2"
version = "0.1.0"

8
old/day02/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

83
old/day02/src/main.rs Normal file
View File

@ -0,0 +1,83 @@
use std::{fs, cmp::max};
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<_> = input.split('\n').collect();
let mut sum = 0;
for line in input {
let split:Vec<_> = line.split(':').collect();
let rounds: Vec<_> = split.last().unwrap().split(';').collect();
let rounds: Vec<_> = rounds.iter()
.map(|x| {
x.split(',').collect::<Vec<_>>()
}).collect();
let rounds: Vec<_> = rounds.iter()
.map(|x| {
x.iter().map(|x| {
x.trim().split(' ').collect::<Vec<_>>()
}).collect::<Vec<_>>()
}).collect();
let (mut r_max, mut g_max, mut b_max) = (0, 0, 0);
for round in rounds {
for set in round {
let color = set.last().unwrap();
let num: i32 = set.first().unwrap().parse().unwrap();
match *color {
"red" => r_max = max(num, r_max),
"blue" => b_max = max(num, b_max),
"green" => g_max = max(num, g_max),
&_ => todo!()
}
}
}
//println!("{}", r_max);
sum += r_max * g_max * b_max;
}
println!("{}", sum);
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split('\n').collect();
// let mut game_id = 0;
// let (r_max, g_max, b_max) = (12, 13, 14);
// let mut sum = 0;
// for line in input {
// game_id += 1;
// let split:Vec<_> = line.split(':').collect();
// let rounds: Vec<_> = split.last().unwrap().split(';').collect();
// let rounds: Vec<_> = rounds.iter().map(|x| x.split(',').collect::<Vec<_>>()).collect();
// let rounds: Vec<_> = rounds.iter().map(|x| x.iter().map(|x| x.trim().split(' ').collect::<Vec<_>>()).collect::<Vec<_>>()).collect();
// let mut sad = false;
// for round in rounds {
// let (mut r_cur, mut g_cur, mut b_cur) = (0, 0, 0);
// for set in round {
// let color = set.last().unwrap();
// let num: i32 = set.first().unwrap().parse().unwrap();
// match *color {
// "red" => r_cur += num,
// "blue" => b_cur += num,
// "green" => g_cur += num,
// &_ => todo!()
// }
// }
// if r_cur > r_max || b_cur > b_max || g_cur > g_max {
// sad = true;
// }
// }
// if !sad {
// sum += game_id;
// }
// }
// println!("{}", sum);
// }

16
old/day03/Cargo.lock generated Normal file
View File

@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "array2d"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79093d31d0a9c7832c71ad74dd945b7861f721e6f242aa67be253a5eecbac937"
[[package]]
name = "day3"
version = "0.1.0"
dependencies = [
"array2d",
]

9
old/day03/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "day3"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
array2d = "0.3.0"

193
old/day03/src/main.rs Normal file
View File

@ -0,0 +1,193 @@
use std::collections::HashMap;
use std::fs;
use array2d::Array2D;
// pub fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let array_2d = get_map(&input);
// // let mut r = Vec::new();
// let mut stars_count: HashMap<(usize, usize), Vec<u32>> = HashMap::new();
// for (y, row_iter) in array_2d.rows_iter().enumerate() {
// let mut checked = false;
// for (x, element) in row_iter.enumerate() {
// let d: char = element.clone();
// if d.is_digit(10) && !checked {
// let star_vec = get_neighboring_star(x, y, &array_2d);
// if !star_vec.is_empty() {
// let (x_star, y_star, _) = star_vec.first().unwrap().clone();
// let key = (x_star, y_star);
// let gear = get_number(x, y, &array_2d);
// if stars_count.contains_key(&key) {
// let mut v: Vec<u32> = stars_count.get(&(x_star, y_star)).unwrap().clone();
// v.push(gear);
// stars_count.insert(key, v);
// } else {
// stars_count.insert(key, vec![gear]);
// }
// checked = true
// }
// } else if !d.is_digit(10) {
// checked = false;
// }
// }
// }
// let r = stars_count.iter().fold(0u32, |acc, (_, gears)| {
// if gears.len() == 2 {
// acc + gears.first().unwrap() * gears.last().unwrap()
// } else {
// acc
// }
// });
// println!("{}", r);
// }
pub fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let array_2d = get_map(&input);
let mut r = 0;
for (y, row_iter) in array_2d.rows_iter().enumerate() {
let mut checked = false;
for (x, element) in row_iter.enumerate() {
let d: char = element.clone();
if d.is_digit(10) && !checked {
if !get_neighbors(x, y, &array_2d).is_empty() {
checked = true;
r += get_number(x, y, &array_2d)
}
} else if !d.is_digit(10) {
checked = false;
}
}
}
println!("{}", r);
}
fn get_map(input: &str) -> Array2D<char> {
let rows: Vec<&str> = input.split("\n").collect();
let mut array = Vec::new();
for row in rows {
let row_vec: Vec<char> = row.chars().collect();
array.push(row_vec);
}
Array2D::from_rows(&array).unwrap()
}
fn get_number(x: usize, y: usize, array2d: &Array2D<char>) -> u32 {
// We're dealing with only 3 digits numbers
let mut i = x.clone();
let mut j = x.clone() - 1;
let mut next_neighbors = Vec::new();
let mut prev_neighbors = Vec::new();
while array2d.get(y, i).is_some() && array2d.get(y, i).unwrap().is_digit(10) {
next_neighbors.push(array2d.get(y, i).unwrap());
i += 1
}
while array2d.get(y, j).is_some() && array2d.get(y, j).unwrap().is_digit(10) {
prev_neighbors.push(array2d.get(y, j).unwrap());
if j > 0 {
j -= 1
} else {
break;
}
}
let mut prev: Vec<&char> = prev_neighbors.clone().into_iter().rev().collect();
prev.append(&mut next_neighbors);
prev
.into_iter()
.fold(String::new(), |a, b| a + &b.to_string())
.parse()
.unwrap()
}
fn get_neighbors(x: usize, y: usize, array2d: &Array2D<char>) -> Vec<&char> {
let mut neighbors = Vec::new();
neighbors.push(array2d.get(y, x.checked_add(1).unwrap()));
if x > 0 {
neighbors.push(array2d.get(y, x.checked_sub(1).unwrap()));
neighbors.push(array2d.get(y.checked_add(1).unwrap(), x.checked_sub(1).unwrap()));
}
if y > 0 {
neighbors.push(array2d.get(y.checked_sub(1).unwrap(), x));
neighbors.push(array2d.get(y.checked_sub(1).unwrap(), x.checked_add(1).unwrap()));
}
if x > 0 && y > 0 {
neighbors.push(array2d.get(y.checked_sub(1).unwrap(), x.checked_sub(1).unwrap()));
}
neighbors.push(array2d.get(y.checked_add(1).unwrap(), x));
neighbors.push(array2d.get(y.checked_add(1).unwrap(), x.checked_add(1).unwrap()));
neighbors
.into_iter()
.flatten()
.filter(|c| !c.is_digit(10) && **c != '.')
.collect()
}
fn get_neighboring_star(x: usize, y: usize, array2d: &Array2D<char>) -> Vec<(usize, usize, Option<&char>)> {
let mut neighbors: Vec<(usize, usize, Option<&char>)> = Vec::new();
neighbors.push((x.checked_add(1).unwrap(), y, array2d.get(y, x.checked_add(1).unwrap())));
if x > 0 {
neighbors.push((x.checked_sub(1).unwrap(), y, array2d.get(y, x.checked_sub(1).unwrap())));
neighbors.push((x.checked_sub(1).unwrap(), y.checked_add(1).unwrap(), array2d.get(y.checked_add(1).unwrap(), x.checked_sub(1).unwrap())));
}
if y > 0 {
neighbors.push((x, y.checked_sub(1).unwrap(), array2d.get(y.checked_sub(1).unwrap(), x)));
neighbors.push((x.checked_add(1).unwrap(), y.checked_sub(1).unwrap(), array2d.get(y.checked_sub(1).unwrap(), x.checked_add(1).unwrap())));
}
if x > 0 && y > 0 {
neighbors.push((x.checked_sub(1).unwrap(), y.checked_sub(1).unwrap(), array2d.get(y.checked_sub(1).unwrap(), x.checked_sub(1).unwrap())));
}
neighbors.push((x, y.checked_add(1).unwrap(), array2d.get(y.checked_add(1).unwrap(), x)));
neighbors.push((x.checked_add(1).unwrap(), y.checked_add(1).unwrap(), array2d.get(y.checked_add(1).unwrap(), x.checked_add(1).unwrap())));
neighbors
.into_iter()
.filter(|(_, _, c)| c.is_some() && c.unwrap() == &'*')
.collect::<Vec<(usize, usize, Option<&char>)>>()
}
pub fn part_two(input: &str) -> Option<u32> {
let array_2d = get_map(input);
// let mut r = Vec::new();
let mut stars_count: HashMap<(usize, usize), Vec<u32>> = HashMap::new();
for (y, row_iter) in array_2d.rows_iter().enumerate() {
let mut checked = false;
for (x, element) in row_iter.enumerate() {
let d: char = element.clone();
if d.is_digit(10) && !checked {
let star_vec = get_neighboring_star(x, y, &array_2d);
if !star_vec.is_empty() {
let (x_star, y_star, _) = star_vec.first().unwrap().clone();
let key = (x_star, y_star);
let gear = get_number(x, y, &array_2d);
if stars_count.contains_key(&key) {
let mut v: Vec<u32> = stars_count.get(&(x_star, y_star)).unwrap().clone();
v.push(gear);
stars_count.insert(key, v);
} else {
stars_count.insert(key, vec![gear]);
}
checked = true
}
} else if !d.is_digit(10) {
checked = false;
}
}
}
let r = stars_count.iter().fold(0u32, |acc, (_, gears)| {
if gears.len() == 2 {
acc + gears.first().unwrap() * gears.last().unwrap()
} else {
acc
}
});
Some(r)
}

7
old/day04/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day4"
version = "0.1.0"

8
old/day04/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day4"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

99
old/day04/src/main.rs Normal file
View File

@ -0,0 +1,99 @@
use std::fs;
use std::collections::VecDeque;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
// an array in this format [[card 1: [winning nums][ our nums]]]
let input: Vec<_> = input.split('\n') // split days
.map(|card| &card[(card.find(':').unwrap() + 1)..]) // remove day numbers
.map(|card| card.trim()) // trim extra whitespace
.map(|card| {
card.split('|') // split winning/own numbers
.map(|numbers| {
numbers.trim() // trim whitespace
.split(' ') // split into individual nums
.filter(|x| !x.is_empty()) // remove empty strings
.map(|x| {return x.parse::<i32>().unwrap()}) // convert to i32
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
})
.collect();
let mut queue = VecDeque::from((0..input.len()).collect::<Vec<usize>>());
let mut total_cards = 0;
while !queue.is_empty() {
let card_num = queue.pop_front().unwrap();
let card = input.get(card_num).unwrap();
total_cards += 1;
let mut dup_cards = 0;
let winning_nums = card.first().unwrap();
let our_nums = card.last().unwrap();
//dp would kill here, but im lazy
for num in our_nums {
if winning_nums.contains(num) {
dup_cards += 1;
}
}
for card in (card_num + 1)..=(card_num + dup_cards) {
if card < input.len() {
queue.push_back(card);
}
}
}
println!("{:?}", total_cards);
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// // an array in this format [[card 1: [winning nums][ our nums]]]
// let input: Vec<_> = input.split('\n') // split days
// .map(|card| &card[(card.find(':').unwrap() + 1)..]) // remove day numbers
// .map(|card| card.trim()) // trim extra whitespace
// .map(|card| {
// card.split('|') // split winning/own numbers
// .map(|numbers| {
// numbers.trim() // trim whitespace
// .split(' ') // split into individual nums
// .filter(|x| !x.is_empty()) // remove empty strings
// .map(|x| {return x.parse::<i32>().unwrap()}) // convert to i32
// .collect::<Vec<_>>()
// })
// .collect::<Vec<_>>()
// })
// .collect();
// let mut total_pts = 0;
// for card in input {
// let mut card_pts = 0;
// let winning_nums = card.first().unwrap();
// let our_nums = card.last().unwrap();
// for num in our_nums {
// if winning_nums.contains(num) {
// if card_pts == 0 {
// card_pts = 1;
// } else {
// card_pts *= 2;
// }
// }
// }
// //println!("{}", card_pts);
// total_pts += card_pts;
// }
// println!("{:?}", total_pts);
// }

7
old/day05/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day5"
version = "0.1.0"

8
old/day05/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day5"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

93
old/day05/src/main.rs Normal file
View File

@ -0,0 +1,93 @@
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let mut mappers: Vec<_> = input.split("\n\n")
.map(|maps| &maps[(maps.find(':').unwrap() + 1)..])
.map(|maps| maps.trim())
.map(|maps| {
maps.split('\n')
.map(|range| {
range.split(' ')
.map(|num| num.parse::<i64>().unwrap())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
})
.collect();
let seeds = mappers.first().unwrap().first().unwrap().clone();
let mappers: &mut [Vec<Vec<i64>>] = mappers.get_mut(1..).unwrap();
for mapper in mappers.into_iter() {
for range in mapper {
range[2] = range[1] + range[2] - 1;
}
}
let mut cur_vals: Vec<_> = Vec::new();
for i in 0..seeds.len() / 2 {
let end = seeds[i * 2] + seeds[(i * 2) + 1];
let mut range: Vec<_> = (seeds[i * 2]..end).collect();
cur_vals.append(&mut range);
}
println!("{}", cur_vals.len());
for mapper in mappers {
for val in cur_vals.iter_mut() {
println!("{}", val);
for range in mapper.into_iter() {
if range[1] <= *val && *val <= range[2] {
let diff = *val - range[1];
*val = range[0] + diff;
break;
}
}
}
}
println!("{:?}", cur_vals.into_iter().min().unwrap())
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let mut mappers: Vec<_> = input.split("\n\n")
// .map(|maps| &maps[(maps.find(':').unwrap() + 1)..])
// .map(|maps| maps.trim())
// .map(|maps| {
// maps.split('\n')
// .map(|range| {
// range.split(' ')
// .map(|num| num.parse::<i64>().unwrap())
// .collect::<Vec<_>>()
// })
// .collect::<Vec<_>>()
// })
// .collect();
// let seeds = mappers.first().unwrap().first().unwrap().clone();
// let mappers: &mut [Vec<Vec<i64>>] = mappers.get_mut(1..).unwrap();
// for mapper in mappers.into_iter() {
// for range in mapper {
// range[2] = range[1] + range[2] - 1;
// }
// }
// let mut cur_vals: Vec<_> = seeds;
// for mapper in mappers {
// for val in cur_vals.iter_mut() {
// for range in mapper.into_iter() {
// if range[1] <= *val && *val <= range[2] {
// let diff = *val - range[1];
// *val = range[0] + diff;
// break;
// }
// }
// }
// }
// println!("{:?}", cur_vals.into_iter().min().unwrap())
// }

7
old/day06/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day6"
version = "0.1.0"

8
old/day06/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day6"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

56
old/day06/src/main.rs Normal file
View File

@ -0,0 +1,56 @@
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<_> = input.split('\n') // Separate the Time and Distance lines
.map(|line| {
line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
.split_whitespace() // Split the numbers into their own elements
.flat_map(|s| s.chars()).collect::<String>() // Combine the strings into a single one
.parse::<i64>().expect("Couldn't parse number") // Parse numbers into i32
}).collect(); // Collect into Vec
let time = input[0];
let dist = input[1];
let mut valid = 0;
for remaining_time in 0..time {
if (time - remaining_time) * remaining_time > dist {
valid += 1;
}
}
println!("{}", valid);
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split('\n') // Separate the Time and Distance lines
// .map(|line| {
// line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
// .split_whitespace() // Split the numbers into their own elements.
// .map(|num| num.parse::<i32>().expect("Couldn't parse number")) // Parse numbers into i32
// .collect::<Vec<_>>()
// }).collect(); // collect into Vec
// let mut valid_total = 1;
// for round in 0..input.first().unwrap().len() {
// let time = input[0][round];
// let dist = input[1][round];
// let mut valid = 0;
// for remaining_time in 0..time {
// if (time - remaining_time) * remaining_time > dist {
// valid += 1;
// }
// }
// valid_total *= valid;
// }
// println!("{}", valid_total);
// }

7
old/day07/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day07"
version = "0.1.0"

8
old/day07/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day07"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

183
old/day07/src/main.rs Normal file
View File

@ -0,0 +1,183 @@
use std::{fs, collections::HashMap};
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let mut input: Vec<_> = input.split('\n')
.map(|line| line.split(' ').collect::<Vec<_>>())
.collect();
for line in 0..input.len() {
let hand = input[line][0];
if hand == "JJJJJ" {
input[line].push("7");
continue;
}
let mut card_freq: HashMap<char, i16> = HashMap::new();
let joker_count: i16 = hand.chars().filter(|c| c == &'J').count().try_into().unwrap();
for card in hand.chars().filter(|c| c != &'J') {
card_freq.entry(card)
.and_modify(|count| *count += 1)
.or_insert(1);
}
// The most helpful place for the jokers will always be with the max card count
let max = card_freq.clone().into_iter().max_by(|a, b| a.1.cmp(&b.1)).unwrap();
card_freq.entry(max.0)
.and_modify(|count| *count += joker_count);
let mut set_count: HashMap<i16, i16> = HashMap::new();
for i in 1..=5 {
let card_count = card_freq.values().filter(|x| **x == i).count().try_into().unwrap();
if card_count != 0 {
set_count.insert(i, card_count);
}
}
let power = match set_count {
x if x.contains_key(&5) => "7",
x if x.contains_key(&4) => "6",
x if x.contains_key(&3) && x.contains_key(&2) => "5",
x if x.contains_key(&3) => "4",
x if x.get(&2).unwrap_or(&0) >= &2 => "3",
x if x.get(&2).unwrap_or(&0) == &1 => "2",
HashMap { .. } => "1"
};
input[line].push(power);
}
input.sort_by(|lhs, rhs| {
let lhs_power: i32 = lhs[2].parse().unwrap();
let rhs_power: i32 = rhs[2].parse().unwrap();
if lhs_power != rhs_power {
return lhs_power.cmp(&rhs_power);
}
let lhs_hand: Vec<i32> = lhs[0].chars().map(card_value).collect();
let rhs_hand: Vec<i32> = rhs[0].chars().map(card_value).collect();
for i in 0..5 {
if lhs_hand[i] == rhs_hand[i] { continue; }
return lhs_hand[i].cmp(&rhs_hand[i]);
}
panic!("Should not be reachable");
});
let mut total_winnings = 0;
for i in 0..input.len() {
let bid: usize = input[i][1].parse().unwrap();
total_winnings += (i + 1) * bid;
}
println!("{}", total_winnings);
}
fn card_value(card: char) -> i32 {
match card {
'A' => 13,
'K' => 12,
'Q' => 11,
'T' => 10,
'9' => 9,
'8' => 8,
'7' => 7,
'6' => 6,
'5' => 5,
'4' => 4,
'3' => 3,
'2' => 2,
'J' => 1,
_ => panic!("invalid card")
}
}
// use std::{fs, collections::HashMap};
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let mut input: Vec<_> = input.split('\n')
// .map(|line| line.split(' ').collect::<Vec<_>>())
// .collect();
// for line in 0..input.len() {
// let hand = input[line][0];
// let mut card_freq: HashMap<char, i16> = HashMap::new();
// for card in hand.chars() {
// card_freq.entry(card)
// .and_modify(|count| *count += 1)
// .or_insert(1);
// }
// let mut set_count: HashMap<i16, i16> = HashMap::new();
// for i in 1..=5 {
// let card_count = card_freq.values().filter(|x| **x == i).count().try_into().unwrap();
// if card_count != 0 {
// set_count.insert(i, card_count);
// }
// }
// let power = match set_count {
// x if x.contains_key(&5) => "7",
// x if x.contains_key(&4) => "6",
// x if x.contains_key(&3) && x.contains_key(&2) => "5",
// x if x.contains_key(&3) => "4",
// x if x.get(&2).unwrap_or(&0) >= &2 => "3",
// x if x.get(&2).unwrap_or(&0) == &1 => "2",
// HashMap { .. } => "1"
// };
// input[line].push(power);
// }
// input.sort_by(|lhs, rhs| {
// let lhs_power: i32 = lhs[2].parse().unwrap();
// let rhs_power: i32 = rhs[2].parse().unwrap();
// if lhs_power != rhs_power {
// return lhs_power.cmp(&rhs_power);
// }
// let lhs_hand: Vec<i32> = lhs[0].chars().map(card_value).collect();
// let rhs_hand: Vec<i32> = rhs[0].chars().map(card_value).collect();
// for i in 0..5 {
// if lhs_hand[i] == rhs_hand[i] { continue; }
// return lhs_hand[i].cmp(&rhs_hand[i]);
// }
// panic!("Should not be reachable");
// });
// let mut total_winnings = 0;
// for i in 0..input.len() {
// let bid: usize = input[i][1].parse().unwrap();
// total_winnings += (i + 1) * bid;
// }
// println!("{}", total_winnings);
// }
// fn card_value(card: char) -> i32 {
// match card {
// 'A' => 13,
// 'K' => 12,
// 'Q' => 11,
// 'J' => 10,
// 'T' => 9,
// '9' => 8,
// '8' => 7,
// '7' => 6,
// '6' => 5,
// '5' => 4,
// '4' => 3,
// '3' => 2,
// '2' => 1,
// _ => panic!("invalid card")
// }
// }

7
old/day08/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day08"
version = "0.1.0"

8
old/day08/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day08"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

122
old/day08/src/main.rs Normal file
View File

@ -0,0 +1,122 @@
use std::{fs, collections::{HashMap, VecDeque}};
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<_> = input.split("\n\n").collect();
let (directions, nodes) = (input[0], input[1]);
let directions: Vec<_> = directions.chars().map(|char| {
match char {
'L' => Direction::Left,
'R' => Direction::Right,
_ => panic!("Invalid direction!")
}
}).collect();
let nodes: HashMap<&str, (&str, &str)> = nodes.split('\n')
.map(|line| {
let line = line.split('=').map(|x| x.trim()).collect::<Vec<_>>();
let children: Vec<_> = line[1].trim_matches(|c| c == '(' || c == ')').split(", ").collect();
(line[0], (children[0], children[1]))
}).collect();
let starts: Vec<_> = nodes.keys().filter(|x| x.ends_with('A')).collect();
let dists: Vec<_> = starts.iter().map(|start| dist(&start, &directions, &nodes)).collect();
let gcf = gcf(&dists);
let step_count = gcf * dists.iter().map(|value| value / gcf).product::<i64>();
println!("{:?}", step_count);
}
fn gcf(values: &Vec<i64>) -> i64 {
let mut gcf = values[0];
for val in values {
gcf = find_gcf(gcf, *val);
if gcf == 1 {
return 1;
}
}
gcf
}
fn find_gcf(a: i64, b: i64) -> i64 {
if a == 0 {
return b;
}
find_gcf(b % a, a)
}
fn dist(cur_node: &str, directions: &Vec<Direction>, nodes: &HashMap<&str, (&str, &str)>) -> i64 {
let mut cur_node = cur_node;
let mut step_queue: VecDeque<Direction> = VecDeque::from(directions.clone());
let mut step_count = 0;
while !cur_node.ends_with('Z') {
step_count += 1;
let cur_step = step_queue.pop_front().unwrap();
match cur_step {
Direction::Left => cur_node = nodes[cur_node].0,
Direction::Right => cur_node = nodes[cur_node].1,
}
step_queue.push_back(cur_step);
}
return step_count;
}
#[derive(Clone)]
#[derive(Debug)]
enum Direction {
Left,
Right
}
// use std::{fs, collections::{HashMap, VecDeque}};
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split("\n\n").collect();
// let (directions, nodes) = (input[0], input[1]);
// let directions: Vec<_> = directions.chars().map(|char| {
// match char {
// 'L' => Direction::Left,
// 'R' => Direction::Right,
// _ => panic!("Invalid direction!")
// }
// }).collect();
// let nodes: HashMap<&str, (&str, &str)> = nodes.split('\n')
// .map(|line| {
// let line = line.split('=').map(|x| x.trim()).collect::<Vec<_>>();
// let children: Vec<_> = line[1].trim_matches(|c| c == '(' || c == ')').split(", ").collect();
// (line[0], (children[0], children[1]))
// }).collect();
// let mut cur_node = "AAA";
// let mut step_queue = VecDeque::from(directions);
// let mut step_count = 0;
// while cur_node != "ZZZ" {
// step_count += 1;
// let cur_step = step_queue.pop_front().unwrap();
// match cur_step {
// Direction::Left => cur_node = nodes[cur_node].0,
// Direction::Right => cur_node = nodes[cur_node].1,
// }
// step_queue.push_back(cur_step);
// }
// println!("{:?}", step_count);
// }
// #[derive(Debug)]
// enum Direction {
// Left,
// Right
// }

7
old/day09/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day09"
version = "0.1.0"

8
old/day09/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day09"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

70
old/day09/src/main.rs Normal file
View File

@ -0,0 +1,70 @@
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<_> = input.split('\n')
.map(|line| {
line.split_whitespace()
.map(|num| num.parse::<i64>().unwrap())
.collect::<Vec<_>>()
}).collect();
let mut total = 0;
for line in input {
let mut line_starters: Vec<i64> = vec![*line.first().unwrap()];
let mut cur_line: Vec<i64> = line;
while !cur_line.iter().all(|x| *x == 0) {
let mut next_line: Vec<i64> = vec![];
for i in 1..cur_line.len() {
let diff = cur_line[i] - cur_line[i-1];
next_line.push(diff)
}
line_starters.push(*next_line.first().unwrap());
cur_line = next_line;
}
let mut sum = 0;
for i in (1..line_starters.len()).rev() {
sum = line_starters[i - 1] - sum;
}
total += sum;
}
println!("{:?}", total)
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split('\n')
// .map(|line| {
// line.split_whitespace()
// .map(|num| num.parse::<i64>().unwrap())
// .collect::<Vec<_>>()
// }).collect();
// let mut total = 0;
// for line in input {
// let mut line_enders: Vec<i64> = vec![*line.last().unwrap()];
// let mut cur_line: Vec<i64> = line;
// while !cur_line.iter().all(|x| *x == 0) {
// let mut next_line: Vec<i64> = vec![];
// for i in 1..cur_line.len() {
// let diff = cur_line[i] - cur_line[i-1];
// next_line.push(diff)
// }
// line_enders.push(*next_line.last().unwrap());
// cur_line = next_line;
// }
// let mut sum = 0;
// for i in (1..line_enders.len()).rev() {
// sum = sum + line_enders[i - 1];
// }
// total += sum;
// }
// println!("{:?}", total)
// }

77
old/day10/Cargo.lock generated Normal file
View File

@ -0,0 +1,77 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day10"
version = "0.1.0"
dependencies = [
"strum",
"strum_macros",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "proc-macro2"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "strum"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
[[package]]
name = "strum_macros"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn",
]
[[package]]
name = "syn"
version = "2.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

10
old/day10/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "day10"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
strum = "0.25.0"
strum_macros = "0.25"

234
old/day10/src/main.rs Normal file
View File

@ -0,0 +1,234 @@
use std::fs;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input = parse_input(&input);
let start = find_start(&input);
let mut start_dirs: Vec<Direction> = vec![];
for dir in Direction::iter().filter(|x| x != &Direction::Start) {
let (x, y) = ((start.0 as i32 + dir.to_ind().1), (start.1 as i32 + dir.to_ind().0));
if x < 0 || y < 0 {
continue;
}
let neibhor = &input[x as usize][y as usize];
if neibhor.contains(&dir.reverse()) {
start_dirs.push(dir);
}
}
let mut finished = false;
let mut pre = start_dirs[0].reverse();
let mut pos = ((start.0 as i32 + start_dirs[0].to_ind().1) as usize, (start.1 as i32 + start_dirs[0].to_ind().0) as usize);
let mut the_loop = vec![start, pos];
let mut area = 0;
while !finished {
let first_next = &input[pos.0][pos.1].iter().filter(|x| x != &&pre).next().unwrap();
pos = ((pos.0 as i32 + first_next.to_ind().1) as usize, (pos.1 as i32 + first_next.to_ind().0) as usize);
pre = first_next.reverse();
finished = pos == start;
the_loop.push(pos);
}
for win in the_loop.windows(2) {
area += (win[0].1 * win[1].0) as i64;
area -= (win[0].0 * win[1].1) as i64;
}
let area = i64::abs(area) / 2;
let spaces = area - (the_loop.len() as i64 / 2) + 1;
println!("{}", spaces)
}
fn parse_input(input: &String) -> Vec<Vec<Vec<Direction>>> {
let input: Vec<_> = input.split('\n')
.map(|line| {
line.chars()
.map(|char| {
match char {
'|' => vec![Direction::North, Direction::South],
'-' => vec![Direction::East, Direction::West],
'L' => vec![Direction::North, Direction::East],
'J' => vec![Direction::North, Direction::West],
'7' => vec![Direction::South, Direction::West],
'F' => vec![Direction::South, Direction::East],
'.' => vec![],
'S' => vec![Direction::Start],
_ => panic!("Invalid pipe char")
}
}).collect::<Vec<_>>()
}).collect();
return input;
}
fn find_start(input: &Vec<Vec<Vec<Direction>>>) -> (usize, usize) {
let mut start_point: Option<(usize, usize)> = None;
for i in 0..input.len() {
for j in 0..input[0].len() {
if input[i][j].contains(&Direction::Start) {
start_point = Some((i,j));
}
}
}
match start_point {
Some(x) => x,
None => panic!("No start point found! AHHHHH")
}
}
#[derive(Debug, PartialEq, EnumIter)]
enum Direction {
North,
South,
East,
West,
Start
}
impl Direction {
pub fn to_ind(&self) -> (i32, i32) {
match self {
Direction::North => (0,-1),
Direction::South => (0,1),
Direction::East => (1,0),
Direction::West => (-1,0),
Direction::Start => panic!("Start should never be converted to an index. AHH"),
}
}
pub fn reverse(&self) -> Direction {
match self {
Direction::North => Direction::South,
Direction::South => Direction::North,
Direction::East => Direction::West,
Direction::West => Direction::East,
Direction::Start => panic!("Start should never be reversed. AHH"),
}
}
}
// use std::fs;
// use strum::IntoEnumIterator;
// use strum_macros::EnumIter;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input = parse_input(&input);
// let start = find_start(&input);
// let mut start_dirs: Vec<Direction> = vec![];
// for dir in Direction::iter().filter(|x| x != &Direction::Start) {
// let (x, y) = ((start.0 as i32 + dir.to_ind().1), (start.1 as i32 + dir.to_ind().0));
// if x < 0 || y < 0 {
// continue;
// }
// let neibhor = &input[x as usize][y as usize];
// if neibhor.contains(&dir.reverse()) {
// start_dirs.push(dir);
// }
// }
// let mut finished = false;
// let mut count = 1;
// let mut first_pre = start_dirs[0].reverse();
// let mut second_pre = start_dirs[1].reverse();
// let mut first_pos = ((start.0 as i32 + start_dirs[0].to_ind().1) as usize, (start.1 as i32 + start_dirs[0].to_ind().0) as usize);
// let mut second_pos = ((start.0 as i32 + start_dirs[1].to_ind().1) as usize, (start.1 as i32 + start_dirs[1].to_ind().0) as usize);
// while !finished {
// let first_next = &input[first_pos.0][first_pos.1].iter().filter(|x| x != &&first_pre).next().unwrap();
// first_pos = ((first_pos.0 as i32 + first_next.to_ind().1) as usize, (first_pos.1 as i32 + first_next.to_ind().0) as usize);
// first_pre = first_next.reverse();
// let second_next = &input[second_pos.0][second_pos.1].iter().filter(|x| x != &&second_pre).next().unwrap();
// second_pos = ((second_pos.0 as i32 + second_next.to_ind().1) as usize, (second_pos.1 as i32 + second_next.to_ind().0) as usize);
// second_pre = second_next.reverse();
// count += 1;
// finished = first_pos == second_pos;
// }
// println!("{:?}", count)
// }
// fn parse_input(input: &String) -> Vec<Vec<Vec<Direction>>> {
// let input: Vec<_> = input.split('\n')
// .map(|line| {
// line.chars()
// .map(|char| {
// match char {
// '|' => vec![Direction::North, Direction::South],
// '-' => vec![Direction::East, Direction::West],
// 'L' => vec![Direction::North, Direction::East],
// 'J' => vec![Direction::North, Direction::West],
// '7' => vec![Direction::South, Direction::West],
// 'F' => vec![Direction::South, Direction::East],
// '.' => vec![],
// 'S' => vec![Direction::Start],
// _ => panic!("Invalid pipe char")
// }
// }).collect::<Vec<_>>()
// }).collect();
// return input;
// }
// fn find_start(input: &Vec<Vec<Vec<Direction>>>) -> (usize, usize) {
// let mut start_point: Option<(usize, usize)> = None;
// for i in 0..input.len() {
// for j in 0..input[0].len() {
// if input[i][j].contains(&Direction::Start) {
// start_point = Some((i,j));
// }
// }
// }
// match start_point {
// Some(x) => x,
// None => panic!("No start point found! AHHHHH")
// }
// }
// #[derive(Debug, PartialEq, EnumIter)]
// enum Direction {
// North,
// South,
// East,
// West,
// Start
// }
// impl Direction {
// pub fn to_ind(&self) -> (i32, i32) {
// match self {
// Direction::North => (0,-1),
// Direction::South => (0,1),
// Direction::East => (1,0),
// Direction::West => (-1,0),
// Direction::Start => panic!("Start should never be converted to an index. AHH"),
// }
// }
// pub fn reverse(&self) -> Direction {
// match self {
// Direction::North => Direction::South,
// Direction::South => Direction::North,
// Direction::East => Direction::West,
// Direction::West => Direction::East,
// Direction::Start => panic!("Start should never be reversed. AHH"),
// }
// }
// }

7
old/day11/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day11"
version = "0.1.0"

8
old/day11/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day11"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

121
old/day11/src/main.rs Normal file
View File

@ -0,0 +1,121 @@
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<_> = input.split('\n')
.map(|x| x.chars().collect::<Vec<char>>())
.collect();
let mut y_expand: Vec<i32> = vec![];
for line in &input {
if line.iter().all(|char| char == &'.') {
y_expand.push(1);
} else {
y_expand.push(0);
}
}
let mut x_expand: Vec<i32> = vec![];
for j in 0..input[0].len() {
let mut is_empty = true;
for i in 0..input.len() {
if input[i][j] != '.' {
is_empty = false;
}
}
if is_empty {
x_expand.push(1);
} else {
x_expand.push(0);
}
}
// println!("{:?}", x_expand);
let mut galaxies: Vec<(i64, i64)> = vec![];
let mut y_offset: i64 = 0;
for (i, line) in input.iter().enumerate() {
if y_expand[i] == 1 {
y_offset += 1000000 - 1;
}
let mut x_offset: i64 = 0;
for (j, char) in line.iter().enumerate() {
if x_expand[j] == 1 {
x_offset += 1000000 - 1;
}
if char == &'#' {
galaxies.push((i as i64 + y_offset, j as i64 + x_offset));
}
}
}
let dist_total = galaxies.clone().into_iter().enumerate()
.fold(0, |mut acc, (i, gal)| {
for next in &galaxies[i + 1..] {
acc += gal.0.abs_diff(next.0) + gal.1.abs_diff(next.1);
}
acc
});
println!("{:?}", dist_total);
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split('\n')
// .map(|x| x.chars().collect::<Vec<char>>())
// .collect();
// let mut rotate: Vec<Vec<char>> = vec![];
// for j in 0..input[0].len() {
// let mut tmp: Vec<char> = vec![];
// for i in 0..input.len() {
// tmp.push(input[i][j]);
// }
// if tmp.iter().all(|x| x == &'.') {
// rotate.push(tmp.clone());
// }
// rotate.push(tmp);
// }
// let mut expanded: Vec<Vec<char>> = vec![];
// for j in 0..rotate[0].len() {
// let mut tmp: Vec<char> = vec![];
// for i in 0..rotate.len() {
// tmp.push(rotate[i][j]);
// }
// if tmp.iter().all(|x| x == &'.') {
// expanded.push(tmp.clone());
// }
// expanded.push(tmp);
// }
// let mut galaxies: Vec<(i32, i32)> = vec![];
// for (i, line) in expanded.iter().enumerate() {
// for (j, char) in line.iter().enumerate() {
// if char == &'#' {
// galaxies.push((i as i32,j as i32));
// }
// }
// }
// let dist_total = galaxies.clone().into_iter().enumerate()
// .fold(0, |mut acc, (i, gal)| {
// for next in &galaxies[i + 1..] {
// acc += gal.0.abs_diff(next.0) + gal.1.abs_diff(next.1);
// }
// acc
// });
// println!("{:?}", dist_total);
// }

25
old/day12/Cargo.lock generated Normal file
View File

@ -0,0 +1,25 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day12"
version = "0.1.0"
dependencies = [
"itertools",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "itertools"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
dependencies = [
"either",
]

9
old/day12/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "day12"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
itertools = "0.12.0"

54
old/day12/src/main.rs Normal file
View File

@ -0,0 +1,54 @@
use std::fs;
use itertools::Itertools;
fn main() {
let input = parse_input();
for (springs, groups) in input {
println!("{:?} {:?}", springs, groups);
}
}
fn parse_input() -> Vec<(Vec<Condition>, Vec<i32>)> {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<(Vec<Condition>, Vec<i32>)> = input.split('\n')
.map(|line| {
line.split(' ')
.collect_tuple()
.unwrap()
}).map(|(springs, groups)| {
let springs: Vec<Condition> = springs.chars()
.map(|char| {
char.to_condition()
}).collect();
let groups: Vec<_> = groups.split(',')
.map(|num| num.parse::<i32>().expect("Failed to parse group len"))
.collect();
(springs, groups)
}).collect();
input
}
#[derive(Debug)]
enum Condition {
Good,
Bad,
WhoKnows
}
trait ConditionConvertable {
fn to_condition(self) -> Condition;
}
impl ConditionConvertable for char {
fn to_condition(self) -> Condition {
match self {
'.' => Condition::Good,
'#' => Condition::Bad,
'?' => Condition::WhoKnows,
_ => panic!("Invalid spring char AHHH")
}
}
}