summaryrefslogtreecommitdiffstats
path: root/2015/rs/code/five/src/main.rs
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2023-11-20 17:12:15 -0500
committeralyx <alyx@aleteoryx.me>2023-11-20 17:12:15 -0500
commitccf1a5828fc26a82545c7accf1ce7916daa08a2d (patch)
tree2428c1374e8f9bcbfd00c8090606f4781d083401 /2015/rs/code/five/src/main.rs
parent4810e24657a5931ea79be3fc3ee3e108fe40282e (diff)
downloadadventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.tar.gz
adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.tar.bz2
adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.zip
Reorganize using workspaces
Diffstat (limited to '2015/rs/code/five/src/main.rs')
-rw-r--r--2015/rs/code/five/src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/2015/rs/code/five/src/main.rs b/2015/rs/code/five/src/main.rs
new file mode 100644
index 0000000..eeafd42
--- /dev/null
+++ b/2015/rs/code/five/src/main.rs
@@ -0,0 +1,52 @@
+static INPUT: &'static str = include_str!("input.txt");
+
+fn main() {
+ let valueified = INPUT.split('\n').filter(|s| !s.is_empty());
+
+ let nice_count = valueified.clone().filter(|s| {
+ let mut s2 = s.chars();
+ let mut last_char = s2.next().unwrap();
+
+ let mut double_flag = false;
+ let mut abcdpqxy_flag = false;
+ for c in s2 {
+ if c == last_char { double_flag = true; }
+ if [('a','b'),('c','d'),('p','q'),('x','y')].contains(&(last_char, c)) { abcdpqxy_flag = true; }
+ if double_flag && abcdpqxy_flag { break; }
+
+ last_char = c;
+ }
+
+ s.chars().filter(|c| "aeiou".contains(*c)).count() >= 3 && double_flag && !abcdpqxy_flag
+ }).count();
+ println!("Nice word count: {nice_count}");
+
+ let nice_count = valueified.filter(|s| {
+ let mut s = s.chars();
+ let mut llc = s.next().unwrap();
+ let mut lc = s.next().unwrap();
+
+ let mut dupeslist = Vec::with_capacity(32);
+ dupeslist.push((llc, lc));
+ let mut pushed = true;
+
+ let mut flag1 = false;
+ let mut flag2 = false;
+
+ for c in s {
+ if !flag1 && (lc != c || (lc == c && (llc != lc || !pushed))) && dupeslist.contains(&(lc, c)) { flag1 = true; }
+ if !flag1 && !dupeslist.contains(&(lc, c)) { dupeslist.push((lc, c)); pushed = true; } else { pushed = false; }
+
+ if c == llc { flag2 = true; }
+
+ if flag1 && flag2 { break; }
+
+ llc = lc;
+ lc = c;
+ }
+
+ flag1 && flag2
+ }).count();
+
+ println!("Nice word(v2) count: {nice_count}");
+}