heh
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 49f6081..7ce0244 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ redundant_semicolons )] #![feature( + int_roundings, type_alias_impl_trait, iter_from_coroutine, iterator_try_reduce, @@ -71,15 +72,29 @@ use crate::util::{MapF, UnionFind}; #[unsafe(no_mangle)] #[implicit_fn::implicit_fn] pub unsafe fn p1(x: &'static [u8; ISIZE]) -> impl Debug { - let mut set = HashSet::default(); - let mut n = 0; - for freq in util::ints::<i32>(x).collect::<Vec<_>>().into_iter().cycle() { - n += freq; - if !set.insert(n) { - return n; + let mut p = x.as_ptr(); + let end = p.add(ISIZE); + let mut n = 50; + let mut c = 0; + while p != end { + let dir = p.λ(); + let mut rest = 0; + while let x = p.λ() + && x != b'\n' + { + rest *= 10; + rest += (x - b'0') as i32; } + let f = 1 - 2 * (dir == b'L') as i32; + // n += rest * f; + // n = n.rem_euclid(100); + // c += (n == 0) as u64; + + let new = n + rest * f; + c += ((new * f).div_floor(100) - (n * f).div_floor(100)).abs(); + n = new; } - panic!() + c } const ISIZE: usize = include_bytes!("inp.txt").len(); |