master
kalle 2022-12-03 16:45:45 +01:00
parent ef84a6b863
commit c7b599993c
3 changed files with 385 additions and 0 deletions

300
input/03.txt Normal file
View File

@ -0,0 +1,300 @@
dWlhclDHdFvDCCDfFq
mGdZBZBwRGjZMFgvTvgtvv
jwwJrzdzGdSbGGnNlzWczHzPHPhn
cczcbMBszhzzDBTBPPPGjtvtlt
LqJLfpwdLnvQLRGQjGtj
gSgnSJJCGSGpGSrwgfhchmmmHzcrHDmbrmMm
bVjstCsSstCLCrbSLnMpdMndcLddcqcpHR
wPZJQJwtBfJZmgBwPTcpTdcnfHMppcGMdG
gmFJzwPJJtszvNhCNC
DmjZDMZWDqGRqqRpHmmRLTTNTPTfCQJQQLJHTClc
FtzfvrfFwVgtzztgBLJNcNlTcTVNNQLN
vgsdbzzrwtqWfWRpZDdZ
rJhqRhLHhdcQqdHqfQGfPGstgGPlWttM
DzCpDDmnNCmBZBZnVBmZzBGPfsbglfNPwgPGPMWsWWft
BZFnlmpBpBzDzVZmhFHFrrrchhRqTdrc
DWCCWFNqdGFdPVcb
HllttQsTRlJlsblrHlhdmPLVcVcTccndLvPLmL
HSlstHgJltghhRrzNBNDzSwMjNZwNb
dzGSHCWSsGVVSdHVHHWWVVDCgJDpQqLTTRJpgmTLRmJTTpTR
BvNjMPZMBtBBMvvNMNttlhLQqCJpLmhTRQqQJgRJLQQg
llNncBlMCwwMnwPZrGsVHzcfFGdHGFGs
JfZhphMMQmFzDTDjSdrQjQ
sqHCbCwBVtbqbCqtrWdjzlSJTlrTSWBn
bHcwbGCGRssNscwtHNbwvmRFvpFFJFvLZMmPLFfv
qBCrzznVmDCmMMDNgrgcrvHHcgbQcW
TTTsdJRTRhhlsgbvbdCFdbWvbQ
JhGGlfRlJsnCMDMqjmfV
rqLLvDLtStDLQhQDQrQhhNdsmWdmmjjnssPnTMnTzfTsWT
ZRFFpgCgppcBcnjTsjTMTfPFMP
GCZpGlwJwBgGHcJhSSHLDDrNqrMtNq
FsPFqsDNZFNnZrcBm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jGfgfvcwfgrLrBjrBLgwdBTSRBFsRZdRsSqFFSFSSPPp
whGCLqsrjgGhhGFqrCCFGCGzTRTZJcNnzlLTnznNHcnzTH
ddvVmbfvdvVbDVQdvvdSzpNcnJzlzSRHNJpnJcSc
BPdvfQdWtPDDPfDvDQVVPmbhssCGGMqgFCFMqGMWgMjrRw
PSLbGmWPSPLQbMTPWGFWltthdDdrmBDHhdDdczzDRh
VfCngVfgsZwCftrZdhcZrdNDzz
CjVJJJqnJwQhWPPLQlGj
ntnnQmTQTQGVWGNGNNlClG
jDffjMSvqjHzHHzwNVwNVcCddPVNdD
ZszJsrrZMjsHqqvZJLRQCbTRQbJmThbt
BgLHgFDsJNWgQgflWd
mnVVcCHnCGRcVnZSjmlthftMQddlfhQctNfW
qbSGqmHSTFprvpvTTL
dvdTMvvpdLpTcSLvdLLMmhfFBftwCNhRwRNjtCTRCf
lshQWgsgrHHqlFfRqFjRFfFwCB
rsgHQbJbrsGHHlgQHgJrlHrPZdhdpMZGDSDpdPLcZhdvhZ

42
src/bin/03_1.rs Normal file
View File

@ -0,0 +1,42 @@
use std::{fs, collections::HashSet};
use anyhow::Result;
use itertools::Itertools;
fn main() -> Result<()> {
let input = fs::read_to_string("input/03.txt")?;
let lines: Vec<&str> = input
.split("\n")
.filter(|s| *s != "")
.collect::<Vec<&str>>();
let result: i32 = lines
.into_iter()
.map(|s| s.split_at(s.len() / 2))
.map(|(one, two)| (one.chars().collect::<HashSet<char>>(), two.chars().collect::<HashSet<char>>()))
.map(|(one, two)| one.intersection(&two).map(|c| c.clone()).collect_vec())
.map(sum_priority)
.sum();
// .for_each(|s| println!("{:?}", s));
println!("{:?}", result);
return Ok(());
}
fn sum_priority(entries: Vec<char>) -> i32 {
return entries
.into_iter()
.map(char_to_priority)
.sum();
}
fn char_to_priority(c: char) -> i32 {
if c.is_uppercase() {
return c as i32 - 65 + 27;
} else {
return c as i32 - 96;
}
}

43
src/bin/03_2.rs Normal file
View File

@ -0,0 +1,43 @@
use std::{fs, collections::HashSet};
use anyhow::Result;
use itertools::Itertools;
fn main() -> Result<()> {
let input = fs::read_to_string("input/03.txt")?;
let lines: Vec<&str> = input
.split("\n")
.filter(|s| *s != "")
.collect::<Vec<&str>>();
let groups = lines
.into_iter()
.map(|s| s.chars().collect::<HashSet<char>>())
.chunks(3);
let badges = groups
.into_iter()
.map(|g| g.reduce(|acc, e| acc.intersection(&e).cloned().collect()).unwrap())
.map(|g| g.into_iter().next().unwrap())
.collect_vec();
let result: i32 = badges
.into_iter()
.map(char_to_priority)
.sum();
println!("{:?}", result);
return Ok(());
}
fn char_to_priority(c: char) -> i32 {
if c.is_uppercase() {
return c as i32 - 65 + 27;
} else {
return c as i32 - 96;
}
}