heh
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/src/main.rs b/src/main.rs index bea374d..3498a82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ #![allow(confusable_idents, uncommon_codepoints, mixed_script_confusables)] #![feature( + iter_collect_into, + let_chains, + anonymous_lifetime_in_impl_trait, unchecked_math, array_windows, slice_take, @@ -11,52 +14,43 @@ )] extern crate test; mod util; - pub use util::prelude::*; +fn weigh(mat: Vec<[u8; 100]>) -> usize { + mat.iter() + .ι::<usize>() + .map(|(row, i)| util::count::<100>(&row, b'O') * (100 - i)) + .sum() +} + +#[no_mangle] pub fn run(i: &str) -> impl Display { - let mut sum = 0; - for lines in i.split("\n\n") { - let mut this = [&b""[..]; 17]; - let put = lines.行().ν(&mut this); - let this = &this[..put]; - 'huh: for (&[a, b], i) in this.array_windows::<2>().ι::<usize>() { - if a == b { - let mut α = i; - let mut β = i + 1; - while α > 0 && β < this.len() - 1 { - α -= 1; - β += 1; - if this[β] != this[α] { - continue 'huh; - } - } - sum += (i + 1) * 100; - } + let mut v = Vec::with_capacity(100); + let mut i = i.as_bytes(); + for _ in 0..100 { + v.push(unsafe { <&[u8; 100]>::try_from(i.get_unchecked(..100)).unwrap() }); + i = unsafe { i.get_unchecked(100..) }; + if i.len() != 0 { + i = unsafe { i.get_unchecked(1..) }; } - let t = &this; - 'yes: for ((a, b), i) in (0..this[0].len()) - .map(|x| (0..this.len()).map(move |y| t[y][x])) - .tuple_windows() - .ι::<usize>() - { - if a.zip(b).all(|(a, b)| a == b) { - let mut α = i; - let mut β = i + 1; - while α > 0 && β < this[0].len() - 1 { - α -= 1; - β += 1; - for i in 0..this.len() { - if this[i][β] != this[i][α] { - continue 'yes; - } - } - } - sum += i + 1; + } + weigh(pushhh(v)) +} + +fn pushhh(mat: Vec<&[u8; 100]>) -> Vec<[u8; 100]> { + let mut new = vec![[0; 100]; 100]; + for j in 0..100 { + let mut count = 0; + for i in 0..100 { + if *unsafe { mat.get_unchecked(i).get_unchecked(j) } == b'O' { + *unsafe { new.get_unchecked_mut(count).get_unchecked_mut(j) } = b'O'; + count += 1; + } else if mat[i][j] == b'#' { + count = i + 1; } } } - sum + new } fn main() { |