Compare commits

...

2 Commits

Author SHA1 Message Date
Nat 06e8e5d293 chore: remove dead & unused code 2024-12-05 21:32:11 -08:00
Nat 0626085cbe chore: delete op_utils 2024-12-05 21:27:20 -08:00
3 changed files with 3 additions and 43 deletions

View File

@ -4,7 +4,6 @@ use std::fs::File;
use std::io::Read;
use std::collections::{VecDeque, HashMap, BTreeSet};
mod op_utils;
mod math;
mod stack;
mod state;
@ -67,7 +66,7 @@ fn parse_rom(path: &String) -> io::Result<(state::Land, Vec<state::Rule>, HashMa
let x_pos = rom_words.pop_front().unwrap();
let y_pos = rom_words.pop_front().unwrap();
land.sow(x_pos, y_pos, value);
land.map.insert((x_pos % land.width, y_pos % land.height), value);
}
println!("World\n=====");
@ -193,9 +192,9 @@ fn main() -> io::Result<()> {
for tree_index in trees_to_compost_by_index.iter() {
let tree_id = scheduled_trees.swap_remove(*tree_index as usize);
let (parent_id, tree_id, recovered_stack_size) = {
let (parent_id, recovered_stack_size) = {
let tree = trees.remove(&tree_id).unwrap();
(tree.parent_id, tree.id, tree.stack_size)
(tree.parent_id, tree.stack_size)
};
let parent = trees.get_mut(&parent_id).unwrap();
parent.stack_size += recovered_stack_size;

View File

@ -1,24 +0,0 @@
/**
* Runs the given macro on a combination of two stacks depending on the value
* of the stack code. The highest-order bit represents the source stack and the
* lowest represents the destination.
*
* Unlike `match_ternary_stack_code`, `match_binary_stack_code` takes a third,
* immediate argument, for a literal number that may be used in the operation
*/
#[macro_export]
macro_rules! match_binary_stack_code {
($macro: ident, $stack_code:expr, $root:expr, $trunk:expr) => {
match_binary_stack_code!($macro, $stack_code, $root, $trunk, 0);
};
($macro: ident, $stack_code:expr, $root:expr, $trunk:expr, $immediate:expr) => {
match $stack_code {
0b00 => $macro!($root, $root, $immediate),
0b01 => $macro!($root, $trunk, $immediate),
0b10 => $macro!($trunk, $root, $immediate),
0b11 => $macro!($trunk, $trunk, $immediate),
_ => panic!("Invalid stack code: {}", $stack_code)
}
};
}

View File

@ -11,11 +11,6 @@ pub struct Land {
}
impl Land {
#[deprecated(since="0.0.0", note="please use `derelativize` instead")]
pub fn wrap_absolute_coordinates(&self, x: u16, y: u16) -> (u16, u16) {
(x % self.width, y % self.height)
}
pub fn derelativize(&self, position: (u16, u16), relative_x: i16, relative_y: i16) -> (u16, u16) {
// Note: we don't need to worry about integer overflows directly
// because land itself cannot exceed integer limits in size and
@ -39,16 +34,6 @@ impl Land {
return (absolute_x, absolute_y);
}
pub fn sow(&mut self, x: u16, y: u16, value: u16) {
// We use modulo arithmetic here to account for values that wrap around
// the world.
self.map.insert((x % self.width, y % self.height), value);
}
pub fn reap(&mut self, x: u16, y: u16) -> u16 {
self.map.remove(&(x % self.width, y % self.height)).unwrap_or(0u16)
}
}
pub type Rule = VecDeque<u16>;