heh
2016/15
bendn 8 months ago
parent d78abc1 · commit 3185414
-rw-r--r--Cargo.toml1
-rw-r--r--src/inp.txt7
-rw-r--r--src/main.rs46
-rw-r--r--src/util.rs79
4 files changed, 43 insertions, 90 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 7058ef1..29bdb93 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,6 +23,7 @@ regex = { version = "1.11.1", default-features = false, features = [
] }
# radsort = "0.1.1"
rustc-hash = { version = "2.1.0", features = ["nightly"] }
+swizzle = "0.1.0"
[profile.release]
lto = true
codegen-units = 1
diff --git a/src/inp.txt b/src/inp.txt
index b5fc5ff..1f25755 100644
--- a/src/inp.txt
+++ b/src/inp.txt
@@ -1 +1,6 @@
-ngcjuoqr \ No newline at end of file
+Disc #1 has 13 positions; at time=0, it is at position 1.
+Disc #2 has 19 positions; at time=0, it is at position 10.
+Disc #3 has 3 positions; at time=0, it is at position 2.
+Disc #4 has 7 positions; at time=0, it is at position 1.
+Disc #5 has 5 positions; at time=0, it is at position 3.
+Disc #6 has 17 positions; at time=0, it is at position 5.
diff --git a/src/main.rs b/src/main.rs
index 56782c5..8ec4de1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,11 +13,11 @@
)]
#![feature(
iterator_try_reduce,
+ step_trait,
cmp_minmax,
custom_inner_attributes,
extend_one,
slice_as_array,
- stdarch_x86_avx512,
impl_trait_in_bindings,
iter_partition_in_place,
iter_chain,
@@ -28,14 +28,12 @@
if_let_guard,
once_cell_get_mut,
iter_collect_into,
- let_chains,
anonymous_lifetime_in_impl_trait,
array_windows,
vec_into_raw_parts,
try_blocks,
portable_simd,
test,
- slice_as_chunks,
array_chunks,
slice_split_once,
import_trait_associated_functions,
@@ -44,8 +42,7 @@
extern crate test;
pub mod util;
-use atools::prelude::*;
-use collar::CollectArray;
+use atools::{CollectArray, prelude::*};
use lower::apply;
use md5::{Digest, Md5};
use memchr::memmem;
@@ -56,39 +53,24 @@ use std::{
mem::take,
simd::prelude::*,
};
+use swizzle::array;
pub use util::prelude::*;
#[unsafe(no_mangle)]
#[implicit_fn::implicit_fn]
pub unsafe fn p1(i: &'static str) -> impl Display {
- // let hash = |x: u32| util::md5s(format!("{i}{x}").as_bytes());
- let mut memo =
- HashMap::<u32, String>::with_capacity_and_hasher(92859, FxBuildHasher::default());
- macro_rules! hash {
- ($x:expr) => {{
- let x = $x;
- memo.entry(x)
- .or_insert_with(|| {
- successors(format!("{i}{x}").into(), |x| Some(util::md5s(x.as_bytes())))
- .nth(2017)
- .unwrap()
- })
- .as_bytes()
- }};
- }
- // dbg!(hash(0));
- (0u32..)
- .filter(|&x| {
- let Some(&c) = hash!(x)
- .array_windows::<3>()
- .find(|x| x.iter().all(|&y| y == x[0]))
- else {
- return false;
- };
-
- (x..=x + 1000).any(|x| memmem::find(hash!(x), &[c[0]; 5]).is_some())
+ let x = i
+ .行()
+ .map(|x| util::ints(x).carr::<4>().swizzle([1, 3]))
+ // p2
+ .chain([[11, 0]]);
+ (0..)
+ .find(|t| {
+ x.clone()
+ .ι1::<i64>()
+ .map(|([p, now], i)| (now + t + i) % p)
+ .all(_ == 0)
})
- .nth(74)
.unwrap()
}
fn main() {
diff --git a/src/util.rs b/src/util.rs
index 6bc8577..e2454dc 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -25,7 +25,7 @@ pub mod prelude {
MapWith, NumTupleIterTools, ParseIter, PartitionByKey, Printable, Skip, SplitU8, Str,
TakeLine, TupleIterTools2, TupleIterTools2R, TupleIterTools3, TupleUtils,
UnifiedTupleUtils, UnsoundUtilities, Widen, countmap, even, gcd, gt, infinite_successors,
- l, lcm, lt, nail, pa, r, rand, reading, reading::Ext, sort, twice, Ͷ, Α, Κ, Λ, Μ,
+ l, lcm, lt, nail, pa, r, rand, reading, reading::Ext, sort, twice, Ͷ, Α, Ι, Κ, Λ, Μ,
};
pub use Default::default;
pub use itertools::Itertools;
@@ -560,14 +560,14 @@ impl Dir {
}
impl std::ops::Add<(usize, usize)> for Dir {
- type Output = (usize, usize);
+ type Output = Option<(usize, usize)>;
fn add(self, (x, y): (usize, usize)) -> Self::Output {
- match self {
- Dir::N => (x, y.wrapping_sub(1)),
- Dir::E => (x.wrapping_add(1), y),
- Dir::S => (x, y.wrapping_add(1)),
- Dir::W => (x.wrapping_sub(1), y),
- }
+ Some(match self {
+ Dir::N => (x, y.checked_sub(1)?),
+ Dir::E => (x + 1, y),
+ Dir::S => (x, y + 1),
+ Dir::W => (x.checked_sub(1)?, y),
+ })
}
}
@@ -1142,14 +1142,8 @@ impl<T, U, V, I: Iterator<Item = (T, U, V)>> TupleIterTools3<T, U, V> for I {
pub trait GreekTools<T>: Iterator {
fn Δ(&mut self) -> T;
- fn ι<N>(&mut self) -> impl Iterator<Item = (T, N)>
- where
- Self: Ι<T, N>;
- fn ι1<N>(&mut self) -> impl Iterator<Item = (T, N)>
- where
- Self: Ι<T, N>;
- fn ν<const N: usize>(&mut self, into: &mut [T; N]) -> usize;
- fn θ(&mut self);
+ fn ν<const N: usize>(self, into: &mut [T; N]) -> usize;
+ fn θ(self);
}
pub trait ParseIter {
@@ -1167,30 +1161,15 @@ impl<'x, I: Iterator<Item = &'x [u8]>> ParseIter for I {
}
}
-pub trait Ι<T, N>: Iterator {
- fn ι(&mut self) -> impl Iterator<Item = (T, N)>;
- fn ι1(&mut self) -> impl Iterator<Item = (T, N)>;
-}
-
-macro_rules! ι {
- ($t:ty) => {
- impl<T, I: Iterator<Item = T>> Ι<T, $t> for I {
- fn ι(&mut self) -> impl Iterator<Item = (T, $t)> {
- self.zip(0..)
- }
-
- fn ι1(&mut self) -> impl Iterator<Item = (T, $t)> {
- self.zip(1..)
- }
- }
- };
+pub trait Ι<T>: Iterator<Item = T> + Sized {
+ fn ι<N: Default + std::iter::Step>(self) -> impl Iterator<Item = (T, N)> {
+ self.zip(N::default()..)
+ }
+ fn ι1<N: Default + std::iter::Step>(self) -> impl Iterator<Item = (T, N)> {
+ self.zip((N::default()..).skip(1))
+ }
}
-ι!(i8);
-ι!(u8);
-ι!(u16);
-ι!(u32);
-ι!(u64);
-ι!(usize);
+impl<T, I: Iterator<Item = T>> Ι<T> for I {}
pub fn nail<const N: usize, T: Copy>(x: &[T]) -> [T; N] {
unsafe { (x.as_ptr() as *const [T; N]).read() }
@@ -1421,7 +1400,7 @@ impl<T, I: Iterator<Item = T>> GreekTools<T> for I {
self.next().ψ()
}
- fn ν<const N: usize>(&mut self, into: &mut [T; N]) -> usize {
+ fn ν<const N: usize>(mut self, into: &mut [T; N]) -> usize {
let mut set = 0;
for e in into {
let Some(y) = self.next() else { break };
@@ -1431,21 +1410,7 @@ impl<T, I: Iterator<Item = T>> GreekTools<T> for I {
set
}
- fn ι<N>(&mut self) -> impl Iterator<Item = (T, N)>
- where
- Self: Ι<T, N>,
- {
- self.ι()
- }
-
- fn ι1<N>(&mut self) -> impl Iterator<Item = (T, N)>
- where
- Self: Ι<T, N>,
- {
- self.ι1()
- }
-
- fn θ(&mut self) {
+ fn θ(self) {
for _ in self {}
}
}
@@ -1592,7 +1557,7 @@ unsafe fn mmaped<'a>() -> (*const u8, i64) {
}
pub trait IntoLines {
- fn 行(&self) -> Lines<'_>;
+ fn 行<'a>(&'a self) -> Lines<'a>;
}
impl IntoLines for [u8] {
fn 行(&self) -> Lines<'_> {
@@ -1600,7 +1565,7 @@ impl IntoLines for [u8] {
}
}
-impl<T: AsRef<[u8]>> IntoLines for T {
+impl IntoLines for str {
fn 行(&self) -> Lines<'_> {
Lines {
bytes: self.as_ref(),