Finished day 3. Annoyed at rusts hashset intersection function.

This commit is contained in:
gabe 2022-12-03 01:26:51 -06:00
parent 4a9c8b37b9
commit 5d22d7975a
11 changed files with 559 additions and 15 deletions

View file

@ -22,5 +22,9 @@ path="src/day02/solve.rs"
name="day03"
path="src/day03/solve.rs"
[[bin]]
name="day04"
path="src/day04/solve.rs"
[dependencies]
regex="1"

View file

@ -0,0 +1,300 @@
PcPlnShmrLmBnmcwBhrmcmbHNGFGpwdFFwGNjNbGqNHH
tzQfRJfWZZztWzVtCTfRzFZjpFjNZjGLHbdHLDdjpb
CCQTzRLzvQVVfRzJfMPsnBlglgPmBgPmvSrl
RMfvbbszHTsssFPzDQPggpQJPQ
NSNcqVtLVGgDlpQBClVB
hmStGNNLhjNrpWLGSjWrZssbZTMMvTfMnThbRRTs
fTrTPGTbfftWBBmLjrJL
DqHwVMqVplDslmlZmpHVwNnShWZFdBBdjWBtWtdtWJSSLS
MNslpDvVHlwsmpQRgQgCfTTcvcRQ
pBBhRgDsMsswprBhvgRglZtFGFFRqZtZmRtNqtZPPN
TdmmzzmdZdqdGFtF
nmSccCVmSCpDCswMwl
NptqDsQtDTQzCvlzCpRlRp
jmZcndmjbZcjrmDvFMFFlwCvzFnF
jjgLVLrGcdDBNhWQTgHg
mLVhhfSMSTmMwClHGdpjDHjGdV
zPrZgJCgbsnrPtZzsCsbpRDjBRHnjGDRldRHppcG
JJrbsFrZqrgWbbqbrgWzJPNTwhTNCmmvfWCShhhmwwfm
ftgfljvgfgBTNvtggFDDGLGRDnMDzcQzncGt
VdbpbVdZwdwrsVVLRrMrDLDBGnBGcM
wmpWwWsHWBCCCPPvjvmSqlfTTmSNgN
jSqmzmmSSDRjLMLDwqjNcMMLTTflffWCCsRsTHnHVrfHWTsr
tdbgZpgBPdgGZGGFTHVpCsCVfVsJpnWl
FnPQFvbvhFFFbvBwScjhzcqSLLSzSN
bWdgrWwwFWbgzFWzrmNbdPqttChMSRnmqSPSnqtMRM
lcPJLDDPPfpMBCRJ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
jhGLhdjNjsLvLsshzHJPVdVmmbzHzdHJ
jvDRNjnDNGRCzjLzZZpqnrFBSccWrMcB
zggmthDDghHvtrdgrVWfSBRwTHLWHwsBWw
PGGjpCjQnJQGJcJnnQpjFWVSsZWVLRZLBcsWSZBRWS
FGQlpnJCbqqGGRCjjnlCqGMtdNmmmvdNmmmzvhbrmgMz
TstvBTdgBhqTsdTcPlfCSrNMrNnrCNNSNNgp
HwLQwQDZzDjnDbmMhNSnmm
FZLVzLLQHRRzwWHjdPlJctlJtlsllhRs
fBtPsMDDswHvBmmVdBlSBRcGGnhVhg
LWJbrpFqpTLTTjqqNWlhnRGGSnhrcSdlRlsh
JWNbbpjJzTbNNNJNJMvmvfZHvzDsHDCsZw
LPGnPNLtwGhFFnJPfsqpVVszzpsP
TcWdvlrcWddggrDBDDdDMmWzRJqfVQZqmsfZsRQzZfZzQJ
TldWrMrDdlDCDdMTcwSLVCSShLNSwHjhGF
JGsWWWQsJmPwQWbBPmccbcbqFfMMpFDVCDFVFVCDqqfFwD
ZtLnlvLnNtvLndnCmfMVSmVCClfpVp
zTzZtjnZNLNmZvdtznntHHZJbBRGBRQWcJGbGsbsJRPQWT
MLmlMTPtQtMNlhbqbbqhflBB
rcrvjpSvScbRbBvbDBPG
ZZJzSHpzPrJzHFmMVMFmHCLNtV

View file

@ -1,15 +1,58 @@
use crate::utilities::*;
pub fn part1() -> usize {
0
pub fn part1(input: &[Rucksack]) -> usize {
input
.iter()
.map(|rucksack| {
let intersection: Vec<&char> = rucksack.0.intersection(&rucksack.1).collect();
assert!(intersection.len() == 1);
intersection[0]
})
.map(find_char_score)
.sum()
}
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use super::*;
#[test]
fn test_part1() {
assert_eq!(part1(), 0);
let input = vec![
Rucksack(
HashSet::from(['v', 'J', 'r', 'w', 'p', 'W', 't', 'w', 'J', 'g', 'W', 'r']),
HashSet::from(['h', 'c', 's', 'F', 'M', 'M', 'f', 'F', 'F', 'h', 'F', 'p']),
),
Rucksack(
HashSet::from([
'j', 'q', 'H', 'R', 'N', 'q', 'R', 'j', 'q', 'z', 'j', 'G', 'D', 'L', 'G', 'L',
]),
HashSet::from([
'r', 's', 'F', 'M', 'f', 'F', 'Z', 'S', 'r', 'L', 'r', 'F', 'Z', 's', 'S', 'L',
]),
),
Rucksack(
HashSet::from(['P', 'm', 'm', 'd', 'z', 'q', 'P', 'r', 'V']),
HashSet::from(['v', 'P', 'w', 'w', 'T', 'W', 'B', 'w', 'g']),
),
Rucksack(
HashSet::from([
'w', 'M', 'q', 'v', 'L', 'M', 'Z', 'H', 'h', 'H', 'M', 'v', 'w', 'L', 'H',
]),
HashSet::from([
'j', 'b', 'v', 'c', 'j', 'n', 'n', 'S', 'B', 'n', 'v', 'T', 'Q', 'F', 'n',
]),
),
Rucksack(
HashSet::from(['t', 't', 'g', 'J', 't', 'R', 'G', 'J']),
HashSet::from(['Q', 'c', 't', 'T', 'Z', 't', 'Z', 'T']),
),
Rucksack(
HashSet::from(['C', 'r', 'Z', 's', 'J', 's', 'P', 'P', 'Z', 's', 'G', 'z']),
HashSet::from(['w', 'w', 's', 'L', 'w', 'L', 'm', 'p', 'w', 'M', 'D', 'w']),
),
];
assert_eq!(part1(&input), 157);
}
}

View file

@ -1,15 +1,89 @@
use crate::utilities::*;
use std::collections::HashSet;
pub fn part2() -> usize {
0
struct Group(HashSet<char>, HashSet<char>, HashSet<char>);
pub fn part2(input: &[Rucksack]) -> usize {
seperate_groups(input)
.iter()
.map(|group| {
//manual implementation of intersection because doing chained intersections is annoying...
group
.0
.iter()
.filter(|c| group.1.contains(c))
.filter(|c| group.2.contains(c))
.map(|x| x.to_owned())
.next()
.unwrap()
}).map(|c| find_char_score(&c)).sum()
}
fn seperate_groups(input: &[Rucksack]) -> Vec<Group> {
let mut output: Vec<Group> = Vec::new();
for group in input.chunks_exact(3) {
output.push(Group(
group[0]
.0
.union(&group[0].1)
.map(|x| x.to_owned())
.collect(),
group[1]
.0
.union(&group[1].1)
.map(|x| x.to_owned())
.collect(),
group[2]
.0
.union(&group[2].1)
.map(|x| x.to_owned())
.collect(),
));
}
output
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashSet;
#[test]
fn test_part2() {
assert_eq!(part2(), 0);
let input = vec![
Rucksack(
HashSet::from(['v', 'J', 'r', 'w', 'p', 'W', 't', 'w', 'J', 'g', 'W', 'r']),
HashSet::from(['h', 'c', 's', 'F', 'M', 'M', 'f', 'F', 'F', 'h', 'F', 'p']),
),
Rucksack(
HashSet::from([
'j', 'q', 'H', 'R', 'N', 'q', 'R', 'j', 'q', 'z', 'j', 'G', 'D', 'L', 'G', 'L',
]),
HashSet::from([
'r', 's', 'F', 'M', 'f', 'F', 'Z', 'S', 'r', 'L', 'r', 'F', 'Z', 's', 'S', 'L',
]),
),
Rucksack(
HashSet::from(['P', 'm', 'm', 'd', 'z', 'q', 'P', 'r', 'V']),
HashSet::from(['v', 'P', 'w', 'w', 'T', 'W', 'B', 'w', 'g']),
),
Rucksack(
HashSet::from([
'w', 'M', 'q', 'v', 'L', 'M', 'Z', 'H', 'h', 'H', 'M', 'v', 'w', 'L', 'H',
]),
HashSet::from([
'j', 'b', 'v', 'c', 'j', 'n', 'n', 'S', 'B', 'n', 'v', 'T', 'Q', 'F', 'n',
]),
),
Rucksack(
HashSet::from(['t', 't', 'g', 'J', 't', 'R', 'G', 'J']),
HashSet::from(['Q', 'c', 't', 'T', 'Z', 't', 'Z', 'T']),
),
Rucksack(
HashSet::from(['C', 'r', 'Z', 's', 'J', 's', 'P', 'P', 'Z', 's', 'G', 'z']),
HashSet::from(['w', 'w', 's', 'L', 'w', 'L', 'm', 'p', 'w', 'M', 'D', 'w']),
),
];
assert_eq!(part2(&input), 70);
}
}

View file

@ -7,8 +7,8 @@ fn main() {
let _structured_input = utilities::parse(_input);
println!("Part One");
println!("Result: {}", part1::part1());
println!("Result: {}", part1::part1(&_structured_input));
println!("Part Two");
println!("Result: {}", part2::part2());
println!("Result: {}", part2::part2(&_structured_input));
}

View file

@ -1,6 +1,27 @@
pub fn parse(input: &str) -> usize {
println!("{}", input);
0
use std::collections::HashSet;
#[derive(Debug, PartialEq, Eq)]
pub struct Rucksack(pub HashSet<char>, pub HashSet<char>);
pub fn parse(input: &str) -> Vec<Rucksack> {
input
.lines()
.map(|line| {
let (first, second) = line.split_at(line.len() / 2);
Rucksack(first.chars().collect(), second.chars().collect())
})
.collect()
}
pub fn find_char_score(input: &char) -> usize {
static CHARS: [char; 52] = [
'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',
];
CHARS
.iter()
.position(|character| character == input)
.unwrap()+1
}
#[cfg(test)]
@ -9,9 +30,50 @@ mod tests {
#[test]
fn test_parse() {
let input =
"test"
;
assert_eq!(parse(input), 0);
let input = "vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw";
assert_eq!(
parse(input),
vec![
Rucksack(
HashSet::from(['v', 'J', 'r', 'w', 'p', 'W', 't', 'w', 'J', 'g', 'W', 'r']),
HashSet::from(['h', 'c', 's', 'F', 'M', 'M', 'f', 'F', 'F', 'h', 'F', 'p'])
),
Rucksack(
HashSet::from([
'j', 'q', 'H', 'R', 'N', 'q', 'R', 'j', 'q', 'z', 'j', 'G', 'D', 'L', 'G',
'L'
]),
HashSet::from([
'r', 's', 'F', 'M', 'f', 'F', 'Z', 'S', 'r', 'L', 'r', 'F', 'Z', 's', 'S',
'L'
])
),
Rucksack(
HashSet::from(['P', 'm', 'm', 'd', 'z', 'q', 'P', 'r', 'V']),
HashSet::from(['v', 'P', 'w', 'w', 'T', 'W', 'B', 'w', 'g'])
),
Rucksack(
HashSet::from([
'w', 'M', 'q', 'v', 'L', 'M', 'Z', 'H', 'h', 'H', 'M', 'v', 'w', 'L', 'H',
]),
HashSet::from([
'j', 'b', 'v', 'c', 'j', 'n', 'n', 'S', 'B', 'n', 'v', 'T', 'Q', 'F', 'n',
])
),
Rucksack(
HashSet::from(['t', 't', 'g', 'J', 't', 'R', 'G', 'J',]),
HashSet::from(['Q', 'c', 't', 'T', 'Z', 't', 'Z', 'T',])
),
Rucksack(
HashSet::from(['C', 'r', 'Z', 's', 'J', 's', 'P', 'P', 'Z', 's', 'G', 'z',]),
HashSet::from(['w', 'w', 's', 'L', 'w', 'L', 'm', 'p', 'w', 'M', 'D', 'w',])
),
]
);
}
}

0
src/day04/input.txt Normal file
View file

15
src/day04/part1.rs Normal file
View file

@ -0,0 +1,15 @@
use crate::utilities::*;
pub fn part1() -> usize {
0
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part1() {
assert_eq!(part1(), 0);
}
}

15
src/day04/part2.rs Normal file
View file

@ -0,0 +1,15 @@
use crate::utilities::*;
pub fn part2() -> usize {
0
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part2() {
assert_eq!(part2(), 0);
}
}

14
src/day04/solve.rs Normal file
View file

@ -0,0 +1,14 @@
mod part1;
mod part2;
mod utilities;
fn main() {
let _input = include_str!("./input.txt");
let _structured_input = utilities::parse(_input);
println!("Part One");
println!("Result: {}", part1::part1());
println!("Part Two");
println!("Result: {}", part2::part2());
}

17
src/day04/utilities.rs Normal file
View file

@ -0,0 +1,17 @@
pub fn parse(input: &str) -> usize {
println!("{}", input);
0
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse() {
let input =
"test"
;
assert_eq!(parse(input), 0);
}
}