Day 3 puzzle

master
Wynd 2022-12-03 13:59:29 +02:00
parent c82535a0b0
commit 6ab8ce9f81
6 changed files with 389 additions and 3 deletions

5
Cargo.lock generated
View File

@ -8,6 +8,7 @@ version = "0.1.0"
dependencies = [
"day1",
"day2",
"day3",
]
[[package]]
@ -17,3 +18,7 @@ version = "0.1.0"
[[package]]
name = "day2"
version = "0.1.0"
[[package]]
name = "day3"
version = "0.1.0"

View File

@ -8,9 +8,11 @@ edition = "2021"
[workspace]
members = [
"day1",
"day2"
"day2",
"day3"
]
[dependencies]
day1 = { path = "./day1" }
day2 = { path = "./day2" }
day2 = { path = "./day2" }
day3 = { path = "./day3" }

8
day3/Cargo.toml 100644
View File

@ -0,0 +1,8 @@
[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]

300
day3/src/input.txt 100644
View File

@ -0,0 +1,300 @@
QLFdFCdlLcVqdvFLnFLSSShZwptfHHhfZZZpSwfmHp
rTJRjjbJTgzDJjdsRsfwtfNwtfmZpZNhmmzt
bMdJjsjglnVMFCCc
BZvZMBBBMTtZTgcCPdgtgQCrrV
VspNDDpsGDGnRmRpRplQdrrPcPCjgDCcPQCQQj
RVnsmspnpwFRlHGRwHHlnRSThSSvBTbFTZMqTMZMTZFh
ttffrVJWtWpgtQnZGVnNSLTHSZ
jRsjjmhdRcjcRsFcdwGLMZSnHMTSMNZN
RjczlvjhPCcPjcvRpbglWplJBblqrGgq
NwCWwdNQNDCwGpWNQwmJtZgPZrdJgLZcPhLddr
blqpnFTqrLbcLPtV
MnjqSSpqlFRvSqNDGHvWHQDwfWmm
jfLljlQhDLmlrMJQtJTJrQqQ
NpBbjjsdMCgCCMrb
dwspwGnSHHGsGzDDlFDjVWjfZWnP
wQhTZwvpZFZdqWLnnwSrWC
mfDmMFlDcPLdgDSCLCqg
PmzclsMclMlFsHHsJZFHpT
LfLJWNdJnBLfhndfWdZqcgDZgSqgCCSSSLDF
b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m
QfZhrhVVdZThlZlfVvVzZrTbgQnBHsCCHgJBsCsJBHmBmn
wwtvfZztlTVlhtrzzlLNpFFRjMPDpRcPFwRj
VzZhhQHQJJWJSSFWDGclbmNPgglPgVGc
ddBTqCjjBCcrqrCRrwGPGmmDGmbpBGNpNNgg
CRMjwsjwsLdLRrQFJSvMFMWZcHFW
JgJJPvtrhRPQQzSRMQFFSF
BLqsjsdLsMBqblnsGbBqVqdwSQSCSWwNFwczQWCNNwNCHn
ljqbpLbbdDlbDbqDDVtMttTTgpJJgThhJrJr
nflndmjbSnlTQGwvWGPHGRGj
NtstcMcDJMvwgHfFvDgR
qqqpLrMsLLqLNNnzbrdlbZSrznfz
ttZCCFjNjnPVCFQPPFbbStrzqzqrrrcwtmJJ
gTTMRMTWsTGGTddHTTbBzBLSmqbbJGzGmqqb
HpgpMTvRhHHTRDhMsHdHDRhjJlVPJjNFJnnFpQQVfPCjnP
VqJVQPpjQqPBbHwldmLfVVmd
tMGvrzzDGCDDddwLbgLvLwcm
TWDWCzTZDGMZtzWWtsFhbRRqRQRjhbNQBBTh
zgLgLHnnzCCvnsHSsZBZBsTRdD
rslllhJjcQNNGjpWJlSRTRdwBVSSNTPVSdPB
jGrGqjJfqccrfqGcGplrJpFvzggqmCtMzmsMnvMvvCgm

68
day3/src/lib.rs 100644
View File

@ -0,0 +1,68 @@
use std::{collections::HashSet, fs};
pub fn start() {
let input = fs::read_to_string("./day3/src/input.txt").unwrap();
let items = vec![
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
let mut sum = 0;
input
.to_owned()
.lines()
.map(|f| f.split_at(f.len() / 2))
.for_each(|f| {
let pack1_ids = priority(f.0, items.clone());
let pack2_ids = priority(f.1, items.clone());
let prio = pack1_ids
.iter()
.filter(|p| pack2_ids.contains(p))
.collect::<Vec<&usize>>()
.first()
.unwrap()
.to_owned();
sum += prio;
});
println!("{:#?}", sum);
sum = 0;
input
.lines()
.collect::<Vec<&str>>()
.chunks(3)
.map(|f| {
f.iter()
.map(|f| priority(f, items.clone()))
.collect::<Vec<Vec<usize>>>()
})
.map(|f| intersection(f).first().unwrap().clone())
.for_each(|f| sum += f);
println!("{:#?}", sum);
}
pub fn intersection(nums: Vec<Vec<usize>>) -> Vec<usize> {
let mut res: Vec<usize> = nums[0].clone();
for temp_vec in nums {
let set: HashSet<usize> = temp_vec.into_iter().collect();
res = set
.intersection(&res.into_iter().collect())
.map(|i| *i)
.collect::<Vec<_>>();
}
res
}
pub fn priority(str: &str, items: Vec<char>) -> Vec<usize> {
str.chars()
.map(|c| items.iter().position(|p| p == &c).unwrap() + 1)
.collect::<Vec<usize>>()
}

View File

@ -1,6 +1,9 @@
use day1;
use day2;
use day3;
fn main() {
// day1::start();
day2::start();
// day2::start();
day3::start();
}