heh
prune the tree
bendn 2023-12-12
parent 93214e9 · commit c2a349e
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs31
2 files changed, 21 insertions, 11 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 5455192..14af4b6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-amap = "0.1.2"
itertools = "0.12.0"
memchr = "2.6.4"
[profile.release]
diff --git a/src/main.rs b/src/main.rs
index c2985be..96a8e2c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,7 +11,7 @@
)]
extern crate test;
mod util;
-use std::ops::ControlFlow;
+use std::{io::Write, ops::ControlFlow};
pub use util::prelude::*;
@@ -26,7 +26,7 @@ pub fn run(i: &str) -> impl Display {
s: Vec<u8>,
n: usize,
max: usize,
- p: &mut impl FnMut(&[u8]) -> ControlFlow<(), bool>,
+ p: &mut impl FnMut(&[u8]) -> ControlFlow<(), ()>,
) -> Vec<Vec<u8>> {
if n == max {
return vec![s];
@@ -38,8 +38,7 @@ pub fn run(i: &str) -> impl Display {
for thing in kill_me(s, n + 1, max, p) {
match p(&thing) {
ControlFlow::Break(()) => break,
- ControlFlow::Continue(true) => combinations.push(thing),
- _ => {}
+ ControlFlow::Continue(()) => combinations.push(thing),
}
}
}
@@ -51,24 +50,36 @@ pub fn run(i: &str) -> impl Display {
return ControlFlow::Break(());
}
}
- let mut huh = vec![];
+ let mut checked = 0;
let mut len = 0;
- for &x in x {
- match x {
+ for &b in x {
+ match b {
b'#' => len += 1,
b'.' if len != 0 => {
- huh.push(len);
+ match c.get(checked) {
+ Some(&x) if x == len => {}
+ _ => return ControlFlow::Break(()),
+ };
+ checked += 1;
len = 0;
}
_ => {}
}
}
if len != 0 {
- huh.push(len);
+ match c.get(checked) {
+ Some(&x) if x == len => {}
+ _ => return ControlFlow::Break(()),
+ }
+ checked += 1;
+ }
+ if checked != c.len() {
+ return ControlFlow::Break(());
}
- ControlFlow::Continue(&*huh == &*c)
+ ControlFlow::Continue(())
})
.len();
+ std::io::stdout().flush().unwrap();
why
})
.sum::<usize>()