my solutions to advent of code
aoc advent-of-code

make this safe holy shit im stupid

aylac.top 977052bd 148b31fd

verified
Changed files
+13 -14
2015
18
rust
src
+13 -14
2015/18/rust/src/main.rs
··· 3 fn generations(times: u32, mut world: Vec<u8>, size: usize, stuck: bool) -> Vec<u8> { 4 #[inline] 5 fn pos(x: usize, y: usize, size: usize) -> usize { 6 - // this shit is unreadable man 7 - (1 + y) * (size + 2) + (1 + x) 8 } 9 10 #[inline] ··· 13 unsafe { *world.get_unchecked(pos(x, y, size)) } 14 } 15 16 - let sizem = size - 1; 17 18 let mut new_world = vec![0_u8; (size + 2).pow(2)]; 19 20 if stuck { 21 - world[pos(0, 0, size)] = 1; 22 - world[pos(sizem, 0, size)] = 1; 23 - world[pos(0, sizem, size)] = 1; 24 - world[pos(sizem, sizem, size)] = 1; 25 } 26 27 for _ in 0..times { 28 - for yo in 0..size { 29 let ym = yo - 1; 30 let yp = yo + 1; 31 - for xo in 0..size { 32 let xm = xo - 1; 33 let xp = xo + 1; 34 ··· 49 50 // i hate the duplication here :( 51 if stuck { 52 - world[pos(0, 0, size)] = 1; 53 - world[pos(sizem, 0, size)] = 1; 54 - world[pos(0, sizem, size)] = 1; 55 - world[pos(sizem, sizem, size)] = 1; 56 } 57 } 58 world ··· 61 fn main() { 62 let input = include_str!("../../input.txt").trim(); 63 let size = input.split_once("\n").expect("invalid input").0.len(); 64 - // reads the input but adds a line of buffer on the sides. unreadable 65 let buffer_line = ".".repeat(size); 66 let input: Vec<u8> = format!("{buffer_line}\n{input}\n{buffer_line}") 67 .split("\n")
··· 3 fn generations(times: u32, mut world: Vec<u8>, size: usize, stuck: bool) -> Vec<u8> { 4 #[inline] 5 fn pos(x: usize, y: usize, size: usize) -> usize { 6 + y * (size + 2) + x 7 } 8 9 #[inline] ··· 12 unsafe { *world.get_unchecked(pos(x, y, size)) } 13 } 14 15 + let sizep = size + 1; 16 17 let mut new_world = vec![0_u8; (size + 2).pow(2)]; 18 19 if stuck { 20 + world[pos(1, 1, size)] = 1; 21 + world[pos(size, 1, size)] = 1; 22 + world[pos(1, size, size)] = 1; 23 + world[pos(size, size, size)] = 1; 24 } 25 26 for _ in 0..times { 27 + for yo in 1..sizep { 28 let ym = yo - 1; 29 let yp = yo + 1; 30 + for xo in 1..sizep { 31 let xm = xo - 1; 32 let xp = xo + 1; 33 ··· 48 49 // i hate the duplication here :( 50 if stuck { 51 + world[pos(1, 1, size)] = 1; 52 + world[pos(size, 1, size)] = 1; 53 + world[pos(1, size, size)] = 1; 54 + world[pos(size, size, size)] = 1; 55 } 56 } 57 world ··· 60 fn main() { 61 let input = include_str!("../../input.txt").trim(); 62 let size = input.split_once("\n").expect("invalid input").0.len(); 63 + // reads the input but adds a line of buffer on the sides 64 let buffer_line = ".".repeat(size); 65 let input: Vec<u8> = format!("{buffer_line}\n{input}\n{buffer_line}") 66 .split("\n")