complete day 3

This commit is contained in:
Max Bradbury 2022-12-04 20:54:38 +00:00
parent 0ce91d44c0
commit 36ee2e7a14
3 changed files with 335 additions and 0 deletions

300
input/day_3.txt Normal file
View File

@ -0,0 +1,300 @@
ZTmtZvZLTFNLMQMNRvZncdcHwcScJvcdHnVfwV
zqjqrzqjCqrjtqWhqChqrznhcfdfVnVSVgcffcgJcSgd
rtDGpzjjqjlrGsWqBWFRsbTPFQMTbRNRFmbs
FFlnlnVlmQqcBVhBRrSrGSwVdRJbztSt
NPPNsffWfNztRZSJNG
WpgpTTHDpgTDDpMLPGgMHslmBmmHcBQnFmcqhmnjlqQm
VlVNLlPQhtnDRPnP
QgqTffzZqgvgzWmqqZmGcDthtRFvnnFnhJtJJDDt
WGTBzSqBQTQmZBWHswpNbswLbSNCNl
PFzFQDdLjMzzQDhnDNmwZmqwRsmRRmMVNM
GtSbbtlttvvtBvtHBmqqNqVVwsVgCmRw
brlvctHfrlrqvGvcTpjDdFnLDhdfjLhQpn
fTqzgFrcmzTrTNgMzFzTrgtbMtVMVPSLVbvSStRttPVV
lsHnlQhplQpsHhlDJsswNwZPZZVNwvnSZSVvVS
BJpsGWhWQQHdGHlpWpfgrmqgNBmTTBqzTrzr
PLPPrDNHDBnrWNBmjDmjbqqgzjgjQC
GJpFwpvFFsJpwvwwGwJZJRptzdQSSZTmCjTQmTSQjjZSggQQ
ffwGGtJGCfLcNMNNfNLW
nlTzllGwlQHHGMSrrhQLcvbcghgcvL
fFNpttBRFFRNtJJnfNWmqbhhZrZrcjgpvLrvrvcvbr
JBftFFsVRWtNWRsmWtRfftGHGPDDCnTDHSCwzwVnwGSw
LsrZLbLmPSTZtPcc
zpnpljpdwhRpfNLlPWPtTPcnMWPcctTV
qlhNNjldqdpgqdfhjpphdsgmmrDBBJJQgHrmDHLQJb
ndDrsBbpqspHCjzVBCHjMj
LWFcQFQtVVdcCMHC
RLthwTWLTSLwTllRLLlLNlPpPGfrGnqDdGqsZqsZsZhb
jHnJLJrcBb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rfZZLffHZHHTsTmsQgFQSFTMjjQlFTRmR
zhTTMLRVTzLbVqwVRJgDQQsSCgCDNgsZCpqp
rrmrBmmWrWnHjWnGWrnGnhDHSQgNSpQsCgSNgtNtDDHZ
fBrGPGmGPBcTMfLhJVTc
TbTCjTBSbCncHsDZDZPhZbzv
rMwplFdlWWJMJzhhpGtHtvHSSP
fMMfwWdWrNfJNdlVgMcTLTmLffjTqnLScCjL
SwhTllwJDwqqBWLBbNtfhjBB
mvllZMmRMZGFZRfctLWtWttzfNLR
MGvHMCGpVnFGlgvVFFnpnGmmsHrDJJdSsqPqJSqDJJdTTDqD
QTTcqJZJhHSpShhFpFzjDDwwsFzpdg
NBMnBvmBPvwrqvgvvqgD
bNNGmWmbbClQTQRqchhQbf

33
src/day_3.rs Normal file
View File

@ -0,0 +1,33 @@
pub fn part_1(input: &str) -> u64 {
let mut priorities_sum: u64 = 0;
let backpacks = input.lines();
for backpack in backpacks {
// todo this should be .chars() or something
let items: Vec<&str> = backpack.split("").collect();
let items_per_compartment = items.len() / 2;
let first_compartment = &items[1..items_per_compartment];
let second_compartment= &items[items_per_compartment..(items.len() - 1)];
for item in first_compartment {
if second_compartment.contains(item) {
let mut byte = item.as_bytes()[0] as u64;
// this is kind of diabolical
if item.to_string() == item.to_uppercase() {
// reduce by some lesser amount?
byte -= 38;
} else {
byte -= 96;
}
priorities_sum += byte;
break;
}
}
}
priorities_sum
}

View File

@ -1,9 +1,11 @@
mod day_1;
mod day_2;
mod day_3;
fn main() {
println!("Day 1, part 1: {}", day_1::part_1(include_str!("../input/day_1.txt")));
println!("Day 1, part 2: {}", day_1::part_2(include_str!("../input/day_1.txt")));
println!("Day 2, part 1: {}", day_2::part_1(include_str!("../input/day_2.txt")));
println!("Day 2, part 2: {}", day_2::part_2(include_str!("../input/day_2.txt")));
println!("Day 3, part 1: {}", day_3::part_1(include_str!("../input/day_3.txt")));
}