mirror of
https://github.com/LeMoonStar/AoC24.git
synced 2025-07-07 16:05:31 +02:00
⚡️ Day 3: Significant performance improvement
This commit is contained in:
parent
37cf778b8c
commit
703c429bcf
1 changed files with 4 additions and 4 deletions
|
@ -11,7 +11,7 @@ pub struct Command {
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn run(&self) -> u64 {
|
pub fn run(&self) -> u64 {
|
||||||
if !self.command.ends_with("mul") || self.parameters.len() < 2 {
|
if self.command != "mul" || self.parameters.len() < 2 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
self.parameters[0] * self.parameters[1]
|
self.parameters[0] * self.parameters[1]
|
||||||
|
@ -32,9 +32,9 @@ impl Program {
|
||||||
self.0
|
self.0
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
if v.command.ends_with("don't") {
|
if v.command == "don't" {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
} else if v.command.ends_with("do") {
|
} else if v.command == "do" {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
} else if enabled {
|
} else if enabled {
|
||||||
return v.run();
|
return v.run();
|
||||||
|
@ -47,7 +47,7 @@ impl Program {
|
||||||
|
|
||||||
impl From<&str> for Program {
|
impl From<&str> for Program {
|
||||||
fn from(value: &str) -> Self {
|
fn from(value: &str) -> Self {
|
||||||
let pattern: Regex = Regex::new(r"([a-z_']+)\(((?:\d+,?)*)\)").unwrap();
|
let pattern: Regex = Regex::new(r"(do|don't|mul)\(((?:\d+,?)*)\)").unwrap();
|
||||||
|
|
||||||
let mut commands = vec![];
|
let mut commands = vec![];
|
||||||
for (_, [command, parameters]) in pattern.captures_iter(value).map(|c| c.extract()) {
|
for (_, [command, parameters]) in pattern.captures_iter(value).map(|c| c.extract()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue