Compare commits

...

4 commits

Author SHA1 Message Date
d13125c4ad 2022 day3/rust: use bitwise arithmetic 2022-12-03 06:49:44 +01:00
c4268a0093 2022 day3/rust: cleanup 2022-12-03 06:49:24 +01:00
5ad4f56771 2022 day3/rust: add solution 2022-12-03 06:17:06 +01:00
f2f3697152 2022 day3: add data 2022-12-03 06:16:46 +01:00
6 changed files with 411 additions and 0 deletions

2
2022/data/day3.expected Normal file
View file

@ -0,0 +1,2 @@
8252
2828

300
2022/data/day3.input Normal file
View file

@ -0,0 +1,300 @@
QJRBMDMtRDCtJzBtJMfjNjhwvmNDvwjLVVgh
TPSNNPZGTjgmSmvfjL
bPlpZZbpsTlTsWprpGFCJtRtzMNdMMBBcWnJQB
tppvbQBhpQQdrzMMcLwhMc
gZnWRccRNgFGRGRFRNNgZgJMddddLLLMCPqwLCNPwqPJ
nRRmFSnWmlgZlTlTllSlSWWWTsfvfDQpBfBcpQvpVQpTfQQf
lRlsVFgTlMgRNsSNTlFgmbWnMPppPnMqWZMWPPWW
fDjgBJdCfCHHBnfLWpqnmnpZmf
GjQHHcdvJHQBHSSNsFQFslwwRg
NPwDLDHNwjLLHWjbdSbDfJJQTZsZDS
BcFBcvgFvghnFLrBpvrgcgrJSZJpQdfSTZbCsSdfZZfbCf
VrngVFRmrVWHLGVMlL
SNBBBDlfZDLqNGmgFjjmBsQgCFtF
VPPVbhpbhMhRhncnScRncbrQtCgQQFmjjjsgtRtQHmFQ
nhWcPJVhpbvMvwvwllvSlGlD
wNlNNqtqHHHPhqCz
MMMMcQSWSpQCWFnRRPchLVvPLLzhmhLzhh
CrgRSWrnrQpppRQrCTnRTRtGtBDBfbNBllbTJlZtfNBN
QNbbNrnNnCwHmNPQmzqQNPsCCfBFFGtsBBddBDtCJDJd
gvVgpZWgTWvRvlvLPDDJjGBfdsdpDDJGdd
ZRMWWRMVgRZghTggPSMZzQwwnqwmnzhNnNwHcQHm
VmPHzBmpmQHbVHSpNHBVQCtRPPCPvFFMqqntZCZqMR
d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BFhCBLlwpFccFBFftqJDQdgdTDJJCbJgCCdg
wfmsPvPwNfvmfLNFvzzJbRMnllhlnLhRLC
gjtqDDTtjgpJcbnMTzCRnCCWhC
SDqtpGSStVtdqpgBVjBGZmFPJNJmffvfPsHZPZQd
HQMBBWrQQmPBvmBWnvrTnMSsbFfcfwgfCgscsmGgwgcJGg
NzzlJLthtlgswGFcwGst
JqNNRqpzhVRWTSQrrvSQ
mFpDZjvmtPPGvFjmmGTzTcFRbHczHTbzQgRS
fNdqhJsNrnnVNhwNVdrdsVczQCcwCMHSTCHgHCRzHgcM
JlgnNhsqVqNqNpPlvZvDDDGlZZ

View file

@ -0,0 +1,8 @@
[package]
name = "rust_2022_03"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,96 @@
use std::{
io::{stdin, Read},
ops::{BitAnd, BitOr},
};
fn item_priority(item: char) -> u32 {
match item {
'a'..='z' => item as u32 - 'a' as u32 + 1,
'A'..='Z' => item as u32 - 'A' as u32 + 27,
_ => panic!("invalid item {item}"),
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct ItemSet(u64);
impl ItemSet {
pub fn priority_of_single_item(self) -> Option<u32> {
if self.0.is_power_of_two() {
Some(self.0.trailing_zeros())
} else {
None
}
}
}
impl FromIterator<char> for ItemSet {
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
Self(
iter.into_iter()
.map(item_priority)
.fold(0, |acc, i| acc | (1 << i)),
)
}
}
impl BitOr for ItemSet {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(BitOr::bitor(self.0, rhs.0))
}
}
impl BitAnd for ItemSet {
type Output = Self;
fn bitand(self, rhs: Self) -> Self::Output {
Self(BitAnd::bitand(self.0, rhs.0))
}
}
struct Rucksack {
left: ItemSet,
right: ItemSet,
}
fn main() {
let mut data = String::new();
stdin().read_to_string(&mut data).unwrap();
let sacks: Vec<_> = data
.lines()
.map(|line| {
let (left, right) = line.split_at(line.len() / 2);
assert_eq!(left.len(), right.len());
let left = left.chars().collect();
let right = right.chars().collect();
Rucksack { left, right }
})
.collect();
let sum1: u32 = sacks
.iter()
.map(|sack| (sack.left & sack.right).priority_of_single_item().unwrap())
.sum();
let sum2: u32 = sacks
.chunks(3)
.into_iter()
.map(|sacks| {
sacks
.iter()
.map(|sack| sack.left | sack.right)
.reduce(BitAnd::bitand)
.unwrap()
.priority_of_single_item()
.unwrap()
})
.sum();
println!("{}", sum1);
println!("{}", sum2);
}

4
Cargo.lock generated
View file

@ -469,6 +469,10 @@ version = "0.1.0"
name = "rust_2022_02"
version = "0.1.0"
[[package]]
name = "rust_2022_03"
version = "0.1.0"
[[package]]
name = "ryu"
version = "1.0.11"

View file

@ -11,4 +11,5 @@ members = [
"2021/day22/rust",
"2022/day1/rust",
"2022/day2/rust",
"2022/day3/rust",
]