heh
2016/19
bendn 7 months ago
parent 821f21f · commit ea68e12
-rw-r--r--src/main.rs27
-rw-r--r--src/util.rs6
2 files changed, 22 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index 1b45818..8c74898 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -61,15 +61,24 @@ pub use util::prelude::*;
#[unsafe(no_mangle)]
#[implicit_fn::implicit_fn]
pub unsafe fn p1(i: &'static str) -> impl Display {
- infinite_successors(util::nail(i.as_bytes()), |x| {
- let x: [u8; 102] = [b'.'].couple(x).join(b'.');
- x.windowed::<3>()
- .map(|x| b".^"[matches!(x, b"^^." | b".^^" | b"^.." | b"..^") as usize])
- })
- .take(400000)
- .flatten()
- .filter(*_ == b'.')
- .count()
+ let n = 3012210;
+ let mut elves = vec![1; n];
+ for i in (0..elves.len()).cycle() {
+ if elves[i] == 0 {
+ continue;
+ }
+ if elves[i] == n {
+ return i + 1;
+ }
+ let left = (0..n)
+ .cycle()
+ .skip(i + 1)
+ .take(n)
+ .find(|x| elves[*x] != 0)
+ .unwrap();
+ elves[i] += take(&mut elves[left]);
+ }
+ panic!()
}
fn main() {
diff --git a/src/util.rs b/src/util.rs
index 48e4541..828b423 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -5,7 +5,9 @@ use regex::Regex;
use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;
use std::collections::VecDeque;
+use std::iter::Zip;
use std::iter::successors;
+use std::ops::RangeFrom;
use std::sync::LazyLock;
use std::{
cmp::Reverse,
@@ -1172,10 +1174,10 @@ impl<'x, I: Iterator<Item = &'x [u8]>> ParseIter for I {
}
pub trait Ι<T>: Iterator<Item = T> + Sized {
- fn ι<N: Default + std::iter::Step>(self) -> impl Iterator<Item = (T, N)> {
+ fn ι<N: Default + std::iter::Step>(self) -> Zip<Self, RangeFrom<N>> {
self.zip(N::default()..)
}
- fn ι1<N: Default + std::iter::Step>(self) -> impl Iterator<Item = (T, N)> {
+ fn ι1<N: Default + std::iter::Step>(self) -> Zip<Self, std::iter::Skip<RangeFrom<N>>> {
self.zip((N::default()..).skip(1))
}
}