diff options
author | alyx <alyx@aleteoryx.me> | 2023-11-20 17:12:15 -0500 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2023-11-20 17:12:15 -0500 |
commit | ccf1a5828fc26a82545c7accf1ce7916daa08a2d (patch) | |
tree | 2428c1374e8f9bcbfd00c8090606f4781d083401 /2015/rs/src/six.rs | |
parent | 4810e24657a5931ea79be3fc3ee3e108fe40282e (diff) | |
download | adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.tar.gz adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.tar.bz2 adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.zip |
Reorganize using workspaces
Diffstat (limited to '2015/rs/src/six.rs')
-rw-r--r-- | 2015/rs/src/six.rs | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/2015/rs/src/six.rs b/2015/rs/src/six.rs deleted file mode 100644 index 0fe0d2d..0000000 --- a/2015/rs/src/six.rs +++ /dev/null @@ -1,57 +0,0 @@ -static INPUT: &'static str = include_str!("six.txt"); - -#[derive(Debug)] -enum LightCommand { - TurnOff, - TurnOn, - Toggle -} - -fn main() { - let valueified = INPUT.split('\n').filter(|s| !s.is_empty()).map(|s| { - let mut rsplit = s.rsplit(' '); - let mut cd = rsplit.next().unwrap().split(',').map(str::parse::<usize>).map(Result::unwrap); - let mut ab = rsplit.nth(1).unwrap().split(',').map(str::parse::<usize>).map(Result::unwrap); - let ab = (ab.next().unwrap(), ab.next().unwrap()); - let cd = (cd.next().unwrap(), cd.next().unwrap()); - match &s[0..7] { - "turn on" => (LightCommand::TurnOn, ab,cd), - "toggle " => (LightCommand::Toggle, ab,cd), - "turn of" => (LightCommand::TurnOff, ab,cd), - _ => unreachable!() - } - }); - - let mut lights = vec![false; 1_000_000]; - for (cmd, (x1, y1), (x2, y2)) in valueified.clone() { - use LightCommand::*; - for x in x1..=x2 { - for y in y1..=y2 { - match cmd { - TurnOff => { lights[x + y * 1000] = false; }, - TurnOn => { lights[x + y * 1000] = true; }, - Toggle => { lights[x + y * 1000] = !lights[x + y * 1000]; } - } - } - } - } - let light_count = lights.into_iter().filter(|a| *a).count(); - println!("Lit light count: {light_count}"); - - let mut lights = vec![0u64; 1_000_000]; - for (cmd, (x1, y1), (x2, y2)) in valueified { - use LightCommand::*; - for x in x1..=x2 { - for y in y1..=y2 { - match cmd { - TurnOff if lights[x + y * 1000] != 0 => { lights[x + y * 1000] -= 1; }, - TurnOn => { lights[x + y * 1000] += 1; }, - Toggle => { lights[x + y * 1000] += 2 }, - _ => () - } - } - } - } - let light_count = lights.into_iter().sum::<u64>(); - println!("Lit light count(Ancient Nordic Elvish): {light_count}"); -} |