main
mat ess 2022-12-03 00:38:13 -05:00
parent e94156f204
commit 72d0c489f6
3 changed files with 393 additions and 1 deletions

6
inputs/3.small.txt Normal file
View File

@ -0,0 +1,6 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw

300
inputs/3.txt Normal file
View File

@ -0,0 +1,300 @@
NJvhJcQWTJWTNTFFMTqqGqfTmB
VwVzPldRZVLVRmfsvfjvqfmm
ZDPDHZHVcvDhbvnv
FHHwHBzzVCWWmmCzCPrVmgBwbLTtRFFbbbttRGRLjTcLpbbT
vhZZvdsNSdSMdNvjncppCLcLnGnj
CDZZsNZMZqdNSdlNZCqrzPHDzgrgzwVVWwmwwm
ndlndntsFJntFvccLjjLrjBShcBBfc
GpCGHzVwmmzqQWSSSfWHBhQL
mpCMGGCZVzVwGGVwmJsZnFtZnTSTJtdsvl
nCnPDGmDNmVCsVQDmGSWqvzchWSjjcWGqS
gTnBRLpfTRnrTdZgdLfRdrThvqcvWWhFFWvcFSSgjqqzjv
pfZfTMwrbLTTfsbmQtlVtHHnbs
wNdSdsbTvTZMTvTv
rrdRWdWQhFVdHWBGWQmmmnnMvCfmnhvmCmtZ
rJrVDRWpGddpbSlNSlspPP
chTNrthMMwWMTjfsmRzZszJpwm
BLnFFCngbcBnbbldDlpRjGpmsCzGsGsRGmmG
dqvnvlgbqtcPPMhH
QcLNqZbCzJDQBJJRpwzRpdnRldgnpf
GmmmvVGsHrWffrlwdCWd
CMsFVVFjCmFStGQbbLZNBbJBcTjc
LQVggbQvcLbQLHgvVLhWGGsChssrMWfzGccc
qDnRTTRqJttPfWMChJhGslWlzh
qRTRwPBTBtRZdnjnqqqnQVbjbNLFbbfLgVmgHLQm
cZbzwCwZPlJcMLrNSNfHWNBBNZ
vsQsDCqtsDhm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J
nwVSSzdzzqSpvQSZQG
mssLLttQrsMrMzLCRmMmrrSQpvWpDNlBTBDlvNTccDQl
HdHJwJqVPwHnqJwbjJbGjnSgSTWPpNgWWpgBBgcvDWWN
ZHVwVZGwwdndqJVJqfHbGwnwrRLtLMftMvMMRrhmLMthhLmz
RgHGLbTqlZlPRZPHfvvfZttJnvfvjnzr
sVcChDVDccwNhhvjTvVzWJjnzFff
mpNcCMTCGmLqBLGH
wVJwHJHVMtMpBmDDWPQVPWDGDD
zCrlZzCblBvnCDWNGLmvGDLPNG
dqZglgbzrzbbgZqzTFSBHHFJSSSfjjSMfwhj
NMWJSjLMCnHHNMNNHWCHMbVVGBPZTrPVPBVDrBSDGTTr
zvttlFpgdtldwwvftPDPTWQdBZrsrWrGBZ
hFlFmhRFvfCbmWJWHcnj

View File

@ -1,4 +1,5 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::HashSet;
use std::fs; use std::fs;
use anyhow::Error; use anyhow::Error;
@ -22,7 +23,7 @@ fn main() -> Result<(), Error> {
type Part = fn(String) -> u64; type Part = fn(String) -> u64;
type Day = [Part; 2]; type Day = [Part; 2];
const DAYS: usize = 2; const DAYS: usize = 3;
const SOLNS: [Day; DAYS] = [ const SOLNS: [Day; DAYS] = [
[ [
// day 1 part 1 // day 1 part 1
@ -85,6 +86,34 @@ const SOLNS: [Day; DAYS] = [
.sum() .sum()
}, },
], ],
[
// day 3 part 1
|input| {
input
.lines()
.map(|line| {
let line = String::from(line);
let rs = Rucksack::new(line);
rs.score()
})
.sum()
},
// day 3 part 2
|input| {
let lines: Vec<_> = input.lines().collect();
lines
.chunks(3)
.map(|chunks| match chunks {
[f, s, t] => {
let rs =
Rucksacks::new(String::from(*f), String::from(*s), String::from(*t));
rs.score()
}
_ => unreachable!("fooey"),
})
.sum()
},
],
]; ];
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
@ -170,3 +199,60 @@ impl Outcome {
} }
} }
} }
struct Rucksack {
first: HashSet<char>,
second: HashSet<char>,
}
impl Rucksack {
fn new(mut input: String) -> Self {
assert!(input.len() % 2 == 0);
let second = input.split_off(input.len() / 2).chars().collect();
Self {
first: input.chars().collect(),
second,
}
}
fn overlap(&self) -> HashSet<&char> {
self.first.intersection(&self.second).collect()
}
fn score(&self) -> u64 {
self.overlap().into_iter().copied().map(score_char).sum()
}
}
struct Rucksacks {
first: HashSet<char>,
second: HashSet<char>,
third: HashSet<char>,
}
impl Rucksacks {
fn new(f: String, s: String, t: String) -> Self {
Rucksacks {
first: f.chars().collect(),
second: s.chars().collect(),
third: t.chars().collect(),
}
}
fn intersection(&self) -> HashSet<char> {
let start: HashSet<_> = self.first.intersection(&self.second).copied().collect();
start.intersection(&self.third).copied().collect()
}
fn score(&self) -> u64 {
self.intersection().into_iter().map(score_char).sum()
}
}
fn score_char(c: char) -> u64 {
if c.is_lowercase() {
c as u64 - 96
} else {
c as u64 - 38
}
}