days 3 and 4 :3

This commit is contained in:
Suguivy 2022-12-04 17:17:34 +01:00
parent 850e41af2d
commit 837e429cc3
8 changed files with 1464 additions and 2 deletions

8
Cargo.lock generated
View File

@ -10,6 +10,14 @@ version = "0.1.0"
name = "day02" name = "day02"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "day03"
version = "0.1.0"
[[package]]
name = "day04"
version = "0.1.0"
[[package]] [[package]]
name = "tiesto" name = "tiesto"
version = "0.1.0" version = "0.1.0"

View File

@ -4,8 +4,8 @@ members = [
"tiesto", "tiesto",
"day01", "day01",
"day02", "day02",
# "day03", "day03",
# "day04", "day04",
# "day05", # "day05",
# "day06", # "day06",
# "day07", # "day07",

8
day03/Cargo.toml Normal file
View File

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

300
day03/input.txt Normal file
View File

@ -0,0 +1,300 @@
ZNNvFWHqLNPZHHqPTHHnTGBhrrpjvmwfMmpfpjBjwpmw
sbdzQgzgssgbglRtmjlwhjBlfrSrMt
zgsCRzJbsdRVQCDbcgLGWWLnZNGVLLZMNZnq
tvHhRtZGMvMHvfsrBBCTRbwbccRc
qznnlpzzDppWlDpQpCrcrwnBNwTZnBTZrn
PdVZJJqVZdllDPFtMjMgLjGMHvSgMF
csbhhVDDvzlVDcbccGGvfRjDHCjNLRHRCLfmnZfR
dFrStSTTmrrrHVfV
MMgQMMTMVTdgWtwTPwSgWSgGbbppJzlplvhBlPbzhlhbzG
FDJSTtSGhpPFDmFTZDpTFPmCBBrHqsCBhgBlqqrqrlRrHH
dQwMtfdzVwWfwctwnfnQCHllzRrsNzrrgNlCgqsr
fLfQnVjfwQfMdfvfnVvWDvtJPFGDpvZGbZpmbSPP
TzzCrJcDrTDdLDCJDvGNPCFqlZWlvNvWpq
RRHfjsQBFsjgjBQsWqGpNvZQqQlPPQPN
VnHBnRVssnnjsSfBwbMSrrbTwJTcwSDF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mmbtgwVsQRqjJMmqMjQfJfLFLD
ZvlBGzdvjGfRFJQJ
dBppnnBBhdzZncBPlznpnNdWHSsbWthbSCgHrVfgSSwVgr
VRvMtRVFHQLvMRQFQtBctrthshTTgCmhTrgWhWZsZZ
lzJlGBSPPhzjgZsTCr
wJlpJPfDSpwBnddqJDdpPpcvMFHFMvNbvnNMFHHRVVbR
CPShbbdlGCdQqlRPGPdlDWDFzjtFjggCDJgWczfF
mrHrTrrBMBsmNsrwsBpnfpggDDcjjDDpjzFJzzjtJz
BvsNvBLHrrrNvwBTNNsNGbdQhlPGGfqhhRGqLGdl
PSSlPtlStGhPNMtwPMPJzDddnbnDNTDDnJqjbz
FFVHRwVLvFvVrVHrZcLmRHggjDmdDnDnznnznzQjzdmJddbn
WrvgRgcRcRrrcRvgcVrHVrwCCSfsCsGsllhMSSSSMttlSCpG
hBPJqVZTqqPSlGlfddfddZvl
JWWMJCpnMrmztzdjnzld
RbWsrwMrpbRspbWgpwhLJPccNVqLLPSVgVPV
hcTrWqcfhwGfWrWMjHjGvDHPmJMDzF
ZtlsnZZtLBSbSssnbndjDJJFHFHJPHPsHMTHHM
ntRZtSbtZgZStTqchwQfRwNpcq
GfLqrsqQGgPgjjQGVcNvTpTpNFcWPvPPpT
bRnRLnMZFdCMcpvT
RnRhzRlmlhhHhhmhRsqLrfzrGVSrGBSGrL
fbMffwdZsncrGcfG
qDBjSSLqhLBSmDbjqNhqTLjCGrCHGrvcGWcpWcrGWnCrpm
STLDqbhTLqNTNSRhlwZlJlRQFFRwMdPQ
TVVGNFggcjPPJzwvQlRRwRvSlcSc
frsBbWhtSRzSLfRf
qDCqddbsWrqzhsdNmdJNJHjTggFFVV
NTWTDrSdFTLtPTGf
lZqjHlVRvRltLtRWFMtFLL
qvjWzzvVbZpjqllggscdchwDrCphwsdhrD

83
day03/src/main.rs Normal file
View File

@ -0,0 +1,83 @@
use std::fs;
fn main() {
const FILE_PATH: &str = "input.txt";
println!("Hi this is the third day of AOC2022, first we will read the file {}", FILE_PATH);
let contents = fs::read_to_string(FILE_PATH)
.expect("Should have been able to read the file");
println!("The sum of the priorities is: {}", &contents.lines().map(|l| get_priori(get_repeat(l))).sum::<u32>());
println!("The sum of the badges is: {}", get_groups(&contents).iter().map(|g| get_priori(grup_repeat(g))).sum::<u32>());
}
fn get_priori(c: char) -> u32{
let priori = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
priori.find(c).expect("must be a letre") as u32 + 1
}
fn get_groups(s: &str) -> Vec<Vec<&str>>{
let mut out = Vec::new();
let mut lines = s.lines();
loop {
let mut grup = Vec::new();
if let Some(line) = lines.next() {
grup.push(line);
grup.push(lines.next().expect("what"));
grup.push(lines.next().expect("Wharrr"))
}else{break;}
out.push(grup);
}
out
}
fn grup_repeat(grup: &Vec<&str>) -> char{
let mut repeated = Vec::new();
for c in grup[0].chars(){
if let Some(i) = grup[1].find(c){
repeated.push(grup[1].chars().nth(i).expect("should have failed before"));
}
};
for c in repeated {
if let Some(i) = grup[2].find(c){
return (grup[2].chars().nth(i).expect("should have failed before"));
}
};
return panic!();
}
fn get_repeat(s: &str) -> char{
let slen = s.len();
let s1 = &s[0..slen/2];
let s2 = &s[slen/2..slen];
for c in s1.chars(){
if let Some(i) = s2.find(c){
return s2.chars().nth(i).expect("should have failed before");
}
};
return panic!();
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn it_works() {
let input = r#"vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"#;
assert_eq!(input.lines().map(|l| get_priori(get_repeat(l))).sum::<u32>(), 157);
}
#[test]
fn it_works2() {
let input = r#"vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"#;
assert_eq!(get_groups(input).iter().map(|g| get_priori(grup_repeat(g))).sum::<u32>(), 70);
}
}

8
day04/Cargo.toml Normal file
View File

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

1000
day04/input Normal file

File diff suppressed because it is too large Load Diff

55
day04/src/main.rs Normal file
View File

@ -0,0 +1,55 @@
use std::fs;
use std::str::FromStr;
fn main() {
const FILE_PATH: &str = "input";
println!("Hi this is the fourth day of AOC2022, first we will read the file {}", FILE_PATH);
let contents = fs::read_to_string(FILE_PATH)
.expect("Should have been able to read the file");
println!("The ammount of subranges are: {}", contents.lines().map(|l| get_ranges(l)).filter(|t| ranges_contain(t.0,t.1)).count());
println!("The ammount of overlapped ranges are: {}", contents.lines().map(|l| get_ranges(l)).filter(|t| ranges_overlap(t.0,t.1)).count());
}
fn ranges_contain(a: (u32,u32), b: (u32,u32)) -> bool {
!((a.0 > b.0 && a.1 > b.1)||(a.0 < b.0 && a.1 < b.1))
}
fn ranges_overlap(a: (u32,u32), b: (u32,u32)) -> bool {
!((a.0 > b.1 && a.1 > b.1)||(a.0 < b.0 && a.1 < b.0))
}
fn get_ranges(s: &str) -> ((u32, u32),(u32, u32)) {
let mut out = s.split(",");
(get_range(out.next().expect("There must be something")),get_range(out.next().expect("There must be a second elf")))
}
fn get_range(s: &str) -> (u32, u32){
let mut out = s.split("-").map(|n| u32::from_str(n).expect("Must be a number"));
(out.next().expect("There must be something"), out.next().expect("There must be a second number"))
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn it_works() {
let input = r#"2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8"#;
assert_eq!(input.lines().map(|l| get_ranges(l)).filter(|t| ranges_contain(t.0,t.1)).count(), 2);
}
#[test]
fn it_works2() {
let input = r#"2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8"#;
assert_eq!(input.lines().map(|l| get_ranges(l)).filter(|t| ranges_overlap(t.0,t.1)).count(), 4);
}
}