heh
2015/20
bendn 12 months ago
parent 6eacb4b · commit 0ae5a70
-rw-r--r--src/main.rs39
-rw-r--r--src/util.rs8
2 files changed, 13 insertions, 34 deletions
diff --git a/src/main.rs b/src/main.rs
index 81e651c..be0164c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -43,38 +43,17 @@ pub use util::prelude::*;
#[no_mangle]
pub fn p1(x: &'static str) -> impl Display {
- let mut i: impl Iterator<Item = &'static [u8]> = x.as_bytes().行();
-
- let mapping = i
- .by_ref()
- .take_while(|x| !x.is_empty())
- .map(|x| x.μ(' ').mr(|x| x.μ1(' ')))
- .collect::<Vec<_>>();
-
- let x = i.Δ();
- let n = mapping
- .iter()
- .flat_map(move |replacement| {
- memmem::find_iter(x, replacement.0).map(|n| {
- let mut x = x.to_vec();
- x.splice(n..n + replacement.0.len(), replacement.1.iter().copied());
- x
- })
- })
- .collect::<HashSet<_>>()
- .len();
- dbg!(n);
- let mut x = x.to_vec();
- let mut steps = 0;
- while x != b"e" {
- for replacement in &mapping {
- if let Some(n) = memmem::find(&x, replacement.1) {
- steps += 1;
- x.splice(n..n + replacement.1.len(), replacement.0.iter().copied());
- }
+ let mut x = vec![0; 1 << 20];
+ let target = 34000000;
+ for elf in 1..1 << 20 {
+ for house in (elf..1 << 20).step_by(elf)
+ //.take(50)
+ {
+ x[house] += elf * 10; // 11
}
}
- steps
+
+ x.into_iter().ι::<u32>().fl(move |e| e > target).Δ().1
}
fn main() {
diff --git a/src/util.rs b/src/util.rs
index 5ae5c1e..b94d249 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1031,16 +1031,16 @@ impl<T: Copy, U: Copy, V: Copy, I: Iterator<Item = (T, U, V)>> FilterBy3<T, U, V
}
}
pub trait FilterBy<T, U>: Iterator {
- fn fl(self, f: impl Fn(T) -> bool) -> impl Iterator<Item = (T, U)>;
- fn fr(self, f: impl Fn(U) -> bool) -> impl Iterator<Item = (T, U)>;
+ fn fl(self, f: impl FnMut(T) -> bool) -> impl Iterator<Item = (T, U)>;
+ fn fr(self, f: impl FnMut(U) -> bool) -> impl Iterator<Item = (T, U)>;
}
impl<T: Copy, U: Copy, I: Iterator<Item = (T, U)>> FilterBy<T, U> for I {
- fn fl(self, f: impl Fn(T) -> bool) -> impl Iterator<Item = (T, U)> {
+ fn fl(self, mut f: impl FnMut(T) -> bool) -> impl Iterator<Item = (T, U)> {
self.filter(move |(x, _)| f(*x))
}
- fn fr(self, f: impl Fn(U) -> bool) -> impl Iterator<Item = (T, U)> {
+ fn fr(self, mut f: impl FnMut(U) -> bool) -> impl Iterator<Item = (T, U)> {
self.filter(move |(_, x)| f(*x))
}
}