From fb12dc39543ec8805d3f352d286fe92b754a5ee1 Mon Sep 17 00:00:00 2001 From: gabe Date: Tue, 6 Dec 2022 00:40:49 -0600 Subject: [PATCH] Late start, but day 6 was suprisingly easy. --- src/day06/input.txt | 1 + src/day06/part1.rs | 14 +++++++++++--- src/day06/part2.rs | 14 +++++++++++--- src/day06/solve.rs | 6 +++--- src/day06/utilities.rs | 15 +++++++++++---- src/day07/input.txt | 0 src/day07/part1.rs | 15 +++++++++++++++ src/day07/part2.rs | 15 +++++++++++++++ src/day07/solve.rs | 14 ++++++++++++++ src/day07/utilities.rs | 16 ++++++++++++++++ 10 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 src/day07/input.txt create mode 100644 src/day07/part1.rs create mode 100644 src/day07/part2.rs create mode 100644 src/day07/solve.rs create mode 100644 src/day07/utilities.rs diff --git a/src/day06/input.txt b/src/day06/input.txt index e69de29..a293ff0 100644 --- a/src/day06/input.txt +++ b/src/day06/input.txt @@ -0,0 +1 @@ +bhzhtzzsczszsjjjzddfzdfzfjfzfbbnntnzznwzzvfvrrqmrmmdzzfqfhqhsqqpwpgwpppbtbnnstthmhrrsmmvsmmhjmjfmfsfjfnfnjjvcjjszjszjsszbznzbnzndzzmlldsdgdcddmqmfqqlcllbvllztzctzczdzttlmtlthtmhtmhmmszsllvzvdzzzsqzqbqccvfvcffzsfslfsllcglclwlvwvzzdsslggtzzgzdzmzddjljvvztttsgscsstztjztjztzvzwwthtftppnmpmmcpmmjlmjjjsfjsjppgcgwcggzffzwzbbmbrbprpqqpccfncfnffvcffsqqtzqzqwzwvzwwwbjbfbcbfblltnlnhhcthtvvzzfcfgfddlggbbshsggplglqqbrbggsvvzdvvlfvlvpvhhmggbrrnppjfjhffttfpffbdfbfvfqvvtcvvbvnnhbhhglgjgzzghhwrrtntrtwwfdfdmmcmtctftpptllzqllzflfrrgqgvgdvdfdbddprrrgccqvqnnmtmvmffpzzqggfbfnfwwqdqldqqlnqnttnbttrffnmmzwzjjtrjtrtmmqsmqmffqmfqfhhbthbhdhvdhvdvmvdmdhdshsqslldzztvvmzzdcccmbbhfhshrrrpsrrqqmdmmgdmmwdmdjdqqmcmttpgtgwgpwpprbrprhrsrllhsllprlplhppfzpffbhbccwdwbbrpbpvpqqmsspjssmbbmfmrmnrnwwgbwwbpwpjwwhqqgcqcvqccgffzpfftcffqlqjjznnlflhhlcczhzvhzhmzhmhfhnnqznntstwtggqjgjhggsvslltjlttfjjgffjzjwzzqzrrhlhzhbhphmhlmlzmzsmzmccvllgrrpbrbfbjfjttqjttdrdhhggqgddppqgpqgpgtptjptpllwccmwcmcpmcppdrrtstqqczqzvvlsltlddnvdvggcqqblqqsjqjttzhtzzszllqsqfqddqdbqddwqddfzzlczcscfsfpfdpdrpddsggcqchcfcpcssstwstwtggghvhqhzzqssjddwjwbjjsnjnfnwwglwwfnfhnnscsggzgjzzhzmmqfqsqwqrwqqqdtdcttzvvnbngbbcdbdggddnmddgzghhzgghwwbjbttlwlcctlccwwdhhrqrvrjjlglssgttpllwclwwtptwptwtvthtbhbzhbzhhrsrwwwnrwrfwfnwnhhnqqdjqjpqqwdwttzhttcdttvztzltzlzmzddrsdsfdsfftdfffmwffrjrffqrfqfsfqqqgqjggwzzrnnqfnqffdbfbtbbrpbrpbptpwttjmjjzrrhhqppdzdtdjttqwwtddjdzzmgzzhwwwdsdgssprsrgsgbbphhdpdwppnfppdqqwzzpbzzqwqpqsqhqdhqqtwwjnnmvmwvmmwwgjgzjjvcjcvcjcnjcncmmphmmvmwmwpwbbtbffhnhshgssgvgvrrbwbtbddqmqfqvvfqvqdvvdbvdbdcdfdlflmffrwwgmmttrztrrfrqrpqrrzjrjpjdpjprrnhhbhcbbcwwqlwwcssbddfrfjrfjfrjfjvvdmdtdzzlvzlzhzmhmhphchnnfqnffvccfpfbfpfqpprrmttzrzzjzmjmzjmmfvmmrzrqqdllgjlglcchssgllsbllrbrlrjlrrhhfwwsqwsstpssznzcznzqzssvtvtrrqwqvvtssgfsfhssljjnwjnjddjdggclcrrfsfhsstgtdtctfttvvsbvvbtbttcgcssjlslhlpljpppwzwnwdnngmgjjbzznwwdllrrfppshhvdhhldhdbbdbjbdjjrnjjzhzfhhsqqbqgmsbvnjsptlrsszlqfmgprvscphmqztbgtlrqvcgdzcptcqjncrdtfqnghnbmwwmcjgtjlbvqqzslgbbntrdfnvfjvfgcgngndjcspgwmpnsrqzzvzljbzlzzrwflrqqqmhsvqwbmdftnhwwzgqrlhddbbtwvbphljmstcjzvpjqwcnhlvpqvqdgvntgqzqwrlwbwvngwtqgrhznlzcvbwqmwncccjctrdzrmzjsvrmcfpjjcczhbvdfwhqvczggfmrspvprvvthvtqnsphpcsdmbrtbdqljvssdrhwjsrrlzprstpgqcbpmnpdgzgjttwcfrgjnsghmszlclgvmlsjrqfvflbnhwwphtvrnrbhdvdglcvgpzfsjpwwhtlvvdzthsrldfzhnlrblzsjjnwclqsqzgdbflhvpwcrtfbfbjcjttbjpvfgvfcswnqqwshbmqlscdzzwshfqwsvwnwzltbnrmzzhzvtwpzqcgwshpvzgtcmwrtrwctnpzbznnwqphnrgwljtrcwlqmvlndwrdrctztnmswslqmbjcmtlrmcpjvzccqszrnflqnqzttbhqlrhbmqdpscqvfgtdbnwjdcljwcbgbgjfzgrgpwqzqgbnrtpntfthhdbqmswvhnmwmszpghgjjzrbnbbfjblpstdfslmmmqfdcrhblqjqfphnldrvvfpnfrcvprjnqbzbspfpjtgqhnjbhnrwzcjvdbshhqpgrmzqpmjfmqwqvvdbddbsldwzzsrhnhsjjnvljrbwcnjrnjpmrrvfthftgptgtlpbgqffthflgftwcrqcqwqwrmrcmfrcqgmrnqjbscdcgrqlhjzthvzdgjbvpswflqcgsnlmgmvcsttsgmnqdtvwdvrndvfdcvrcwmqlmlhtrvthsndsrmnsfmdmfnpfmfhzjqmtcjzcrnsjdztztvgdtlrmbdmmstbfgpmmzthcslpvgrpgfljfgqlqhldfwvvvdvbzjtdtppbtrnqwsqztjrsjhtfrgmvsdngvsdzjgpwrldqpzdpvhljzpjvttwltdwcrhcbrgrvdrmpwvdwjchqsjfprbgtjtzggvgrgmlvvwqrjfprbbgjjqrtdfnrdffwbswbvqtqtfsrhsgrjhftqldhmcnmsnfflmdrzqdjmbqqgqsttdmtrrvfsjnccnhcpcvqtrzdjzrpwswmjvvgsgwvnmdgqwlctrlhqnsmczbwsjhmtgvdcgsndzlstcwchcztqqbtdwfvlljdvdlzljslgnzpmqvzfcvqhdzvgchffqgfwrnmwqzwgbzblpmvddlvnhglrhdnwzqwztzgjczjpwcjwmpnrnrhncfjfggrbphrjztwtfqmfjlwfhnqfftfghbnvtwgtmdzzrdrtmfrwhrrbhzmcllsgqzwzzqtgdggvzptvtdcpzmtmsfcfbjtzlbdrwhdbtdhhrgggmddnzsvjwgcdcqfppqwphfvlhmgqsznlhmgpnjvcvrwwppnphchgsrhjwjcpjggsrcwrvnllfgrmjltfzwhmbqwpwwzmrtlqcprrqztcgnghcbvzrbfptjmhtdcfhhffdbrswqpnpppnpqwtflrrmqgjzctmmvvvwzllbsfdvpqjtmvpjcpmjztscsgbdznfgcmtjzdqzwqrsvstnnvddcstzqjtnbsnlptpmbmfqmhppgnjrffqrtchgptbmwlwbwbcqqfngpbwtwdmlmdstmqwcwjtbwbbbhghgptmvhfmvqfvpwqzwnbjdhpwlgjgvprdjbnlzhnllssbpvzfzspwsscfpqtpdvtzvqncfrfrgddsdglqvpblmpcczlqfdmwzmgvrljhqtcglcvfhbdwhbttqqrjbqwhsrhrbjwmtqwqddvdggdwfsmnpbpvvgsqnvvrqntwmbzdnqpmmqtbnlsbmslpfmqjtgvbddhwvlvjtlrhqdpfnjwtbhwjwdrpgctbbrdqvbbnvgqwngrhqfvwzmlqtmhfqphnmczlbdpnbmpvwrsjbcnjnvcfgnsvlhpzdgdzgvfbgwdcrswznrggnghzssdwqvvlwftqhbnwdvghhvjlqqmcnqmvbwhrrnsswlwmwbsmpcpdzzgmcmqnzpvjpzqbwcsgdhqtqhcpbtqftvscmntsbdcbrndvlfhprpblzbjcpqhfljtvnvtgvrcgqbsgl diff --git a/src/day06/part1.rs b/src/day06/part1.rs index 4074daf..1744504 100644 --- a/src/day06/part1.rs +++ b/src/day06/part1.rs @@ -1,7 +1,11 @@ use crate::utilities::*; -pub fn part1() -> usize { - unimplemented!() +pub fn part1(input: &str) -> usize { + input + .as_bytes() + .windows(4) + .position(|x| !find_dupes_stupid(x)) + .unwrap()+4 } #[cfg(test)] @@ -10,6 +14,10 @@ mod tests { #[test] fn test_part1() { - assert_eq!(part1(), 0); + assert_eq!(part1("mjqjpqmgbljsphdztnvjfqwrcgsmlb"), 7); + assert_eq!(part1("bvwbjplbgvbhsrlpgdmjqwftvncz"), 5); + assert_eq!(part1("nppdvjthqldpwncqszvftbrmjlhg"), 6); + assert_eq!(part1("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"), 10); + assert_eq!(part1("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"), 11); } } diff --git a/src/day06/part2.rs b/src/day06/part2.rs index 246b113..369672c 100644 --- a/src/day06/part2.rs +++ b/src/day06/part2.rs @@ -1,7 +1,11 @@ use crate::utilities::*; -pub fn part2() -> usize { - unimplemented!() +pub fn part2(input: &str) -> usize { + input + .as_bytes() + .windows(14) + .position(|x| !find_dupes_stupid(x)) + .unwrap()+14 } #[cfg(test)] @@ -10,6 +14,10 @@ mod tests { #[test] fn test_part2() { - assert_eq!(part2(), 0); + assert_eq!(part2("mjqjpqmgbljsphdztnvjfqwrcgsmlb"), 19); + assert_eq!(part2("bvwbjplbgvbhsrlpgdmjqwftvncz"), 23); + assert_eq!(part2("nppdvjthqldpwncqszvftbrmjlhg"), 23); + assert_eq!(part2("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"), 29); + assert_eq!(part2("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"), 26); } } diff --git a/src/day06/solve.rs b/src/day06/solve.rs index c613d23..652af02 100644 --- a/src/day06/solve.rs +++ b/src/day06/solve.rs @@ -4,11 +4,11 @@ mod utilities; fn main() { let _input = include_str!("./input.txt"); - let _structured_input = utilities::parse(_input); + // let _structured_input = utilities::parse(_input); println!("Part One"); - println!("Result: {}", part1::part1()); + println!("Result: {}", part1::part1(_input)); println!("Part Two"); - println!("Result: {}", part2::part2()); + println!("Result: {}", part2::part2(_input)); } diff --git a/src/day06/utilities.rs b/src/day06/utilities.rs index be3e53c..38a1cd0 100644 --- a/src/day06/utilities.rs +++ b/src/day06/utilities.rs @@ -1,5 +1,14 @@ -pub fn parse(input: &str) -> usize { +/* pub fn parse(input: &str) -> usize { unimplemented!() +} */ + +pub fn find_dupes_stupid(slice: &[T]) -> bool { + for i in 1..slice.len() { + if slice[i..].contains(&slice[i - 1]) { + return true; + } + } + false } #[cfg(test)] @@ -8,9 +17,7 @@ mod tests { #[test] fn test_parse() { - let input = -"test" -; + let input = "test"; assert_eq!(parse(input), 0); } } diff --git a/src/day07/input.txt b/src/day07/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/day07/part1.rs b/src/day07/part1.rs new file mode 100644 index 0000000..4074daf --- /dev/null +++ b/src/day07/part1.rs @@ -0,0 +1,15 @@ +use crate::utilities::*; + +pub fn part1() -> usize { + unimplemented!() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part1() { + assert_eq!(part1(), 0); + } +} diff --git a/src/day07/part2.rs b/src/day07/part2.rs new file mode 100644 index 0000000..246b113 --- /dev/null +++ b/src/day07/part2.rs @@ -0,0 +1,15 @@ +use crate::utilities::*; + +pub fn part2() -> usize { + unimplemented!() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part2() { + assert_eq!(part2(), 0); + } +} diff --git a/src/day07/solve.rs b/src/day07/solve.rs new file mode 100644 index 0000000..c613d23 --- /dev/null +++ b/src/day07/solve.rs @@ -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()); +} diff --git a/src/day07/utilities.rs b/src/day07/utilities.rs new file mode 100644 index 0000000..be3e53c --- /dev/null +++ b/src/day07/utilities.rs @@ -0,0 +1,16 @@ +pub fn parse(input: &str) -> usize { + unimplemented!() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse() { + let input = +"test" +; + assert_eq!(parse(input), 0); + } +}