more successes.
This commit is contained in:
@@ -39,4 +39,4 @@ fn main() {
|
||||
}
|
||||
println!("Ending on floor {}", current_floor);
|
||||
}
|
||||
// 232
|
||||
// 232
|
||||
|
||||
+15
-20
@@ -23,63 +23,60 @@ fn identify_wires(input: &str) -> Vec<String> {
|
||||
working
|
||||
}
|
||||
|
||||
fn parse_instruction(input: &str) -> Option<Actions> {
|
||||
fn parse_instruction(input: &str) -> Actions {
|
||||
let parts : Vec<_> = input.split_whitespace().collect();
|
||||
|
||||
match parts.len() {
|
||||
3 => {
|
||||
Some(Actions::Connection { a: parts[0].to_string(), z: parts[2].to_string() })
|
||||
Actions::Connection { a: parts[0].to_string(), z: parts[2].to_string() }
|
||||
},
|
||||
4 => {
|
||||
// NOT
|
||||
match parts[0] {
|
||||
"NOT" => {
|
||||
Some(Actions::NOT { a: parts[1].to_string(), z: parts[3].to_string()} ) },
|
||||
Actions::NOT { a: parts[1].to_string(), z: parts[3].to_string()} },
|
||||
_ => {
|
||||
println!("UNHANDLED 4 PART -> {input}");
|
||||
Some(Actions::Connection { a: "__".to_string(), z: "__".to_string() })
|
||||
unreachable!("UNHANDLED 4 PART -> {input}");
|
||||
}
|
||||
}
|
||||
}
|
||||
5 => {
|
||||
match parts[1] {
|
||||
"RSHIFT" => {
|
||||
Some(Actions::RSHIFT {
|
||||
Actions::RSHIFT {
|
||||
a: parts[0].to_string(),
|
||||
d: parts[2].parse::<u32>().unwrap(),
|
||||
z: parts[4].to_string(),
|
||||
})
|
||||
}
|
||||
},
|
||||
"LSHIFT" => {
|
||||
Some(Actions::LSHIFT {
|
||||
Actions::LSHIFT {
|
||||
a: parts[0].to_string(),
|
||||
d: parts[2].parse::<u32>().unwrap(),
|
||||
z: parts[4].to_string()
|
||||
})
|
||||
}
|
||||
},
|
||||
"AND" => {
|
||||
Some(Actions::AND {
|
||||
Actions::AND {
|
||||
a: parts[0].to_string(),
|
||||
b: parts[2].to_string(),
|
||||
z: parts[4].to_string(),
|
||||
})
|
||||
}
|
||||
},
|
||||
"OR" => {
|
||||
Some(Actions::OR {
|
||||
Actions::OR {
|
||||
a: parts[0].to_string(),
|
||||
b: parts[2].to_string(),
|
||||
z: parts[4].to_string(),
|
||||
})
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
println!("UNHANDLED 5 PART -> {input}");
|
||||
None
|
||||
unreachable!("UNHANDLED 5 PART -> {input}");
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
println!("Unhandled {} part -> {input}", parts.len());
|
||||
None
|
||||
unreachable!("Unhandled {} part -> {input}", parts.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,8 +89,6 @@ fn main() {
|
||||
|
||||
for line in lines {
|
||||
let parsed = parse_instruction(line);
|
||||
if parsed.is_some() {
|
||||
println!("PARSED [[{line}]] into [[{parsed:?}]]");
|
||||
}
|
||||
println!("PARSED [[{line}]] into [[{parsed:?}]]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ use core::read_data;
|
||||
enum Expr {
|
||||
Value(u16),
|
||||
Wire(String),
|
||||
Not(Box<Expr>),
|
||||
And(Box<Expr>, Box<Expr>),
|
||||
Or(Box<Expr>, Box<Expr>),
|
||||
LShift(Box<Expr>, u8),
|
||||
RShift(Box<Expr>, u8),
|
||||
Not(Box<Expr>),
|
||||
}
|
||||
|
||||
fn parse_expr(token: &str) -> Expr {
|
||||
|
||||
+36
-40
@@ -1,55 +1,51 @@
|
||||
use core::read_data;
|
||||
use std::fs;
|
||||
|
||||
fn parsed_string(input: &str) -> String {
|
||||
let mut output = String::new();
|
||||
let mut chars = input.chars().peekable();
|
||||
|
||||
while let Some(char) = chars.next() {
|
||||
match char {
|
||||
'\\' => {
|
||||
match chars.next() {
|
||||
Some('n') => output.push('\n'),
|
||||
Some('t') => output.push('\t'),
|
||||
Some('\\') => output.push('\\'),
|
||||
Some('"') => output.push('"'),
|
||||
Some('x') => {
|
||||
let hi = chars.next().unwrap();
|
||||
let lo = chars.next().unwrap();
|
||||
let value = u8::from_str_radix(&format!("{hi}{lo}"), 16).unwrap();
|
||||
output.push(value as char)
|
||||
}
|
||||
Some(other) => output.push(other),
|
||||
None => {}
|
||||
// Skip the surrounding quotes
|
||||
let mut chars = input[1..input.len() - 1].chars().peekable();
|
||||
|
||||
while let Some(ch) = chars.next() {
|
||||
match ch {
|
||||
'\\' => match chars.next() {
|
||||
Some('\\') => output.push('\\'),
|
||||
Some('"') => output.push('"'),
|
||||
Some('n') => output.push('\n'),
|
||||
Some('t') => output.push('\t'),
|
||||
Some('x') => {
|
||||
// Must be exactly two hex digits
|
||||
let hi = chars.next().expect("Incomplete \\x escape");
|
||||
let lo = chars.next().expect("Incomplete \\x escape");
|
||||
let hex = format!("{hi}{lo}");
|
||||
let value = u8::from_str_radix(&hex, 16)
|
||||
.expect("Invalid hex escape in input");
|
||||
output.push(value as char);
|
||||
}
|
||||
}
|
||||
'"' => {}
|
||||
_ => output.push(char)
|
||||
Some(other) => panic!("Invalid escape: \\{other}"),
|
||||
None => panic!("Dangling backslash"),
|
||||
},
|
||||
_ => output.push(ch),
|
||||
}
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
use core::read_data;
|
||||
fn main() {
|
||||
let mut char_count = 0;
|
||||
let mut mem_count = 0;
|
||||
// Read your puzzle input file
|
||||
let input = read_data("2015_08_data.txt");
|
||||
|
||||
let binding = read_data("2015_08_data.txt");
|
||||
let lines = binding.lines();
|
||||
let binding = vec![
|
||||
r#""""#,
|
||||
r#""abc""#,
|
||||
r#""aaa\"aaa""#,
|
||||
r#"\x27"#
|
||||
].join("\n");
|
||||
let lines = binding.lines();
|
||||
let mut raw_total = 0;
|
||||
let mut mem_total = 0;
|
||||
|
||||
for line in lines {
|
||||
let raw_size = line.len();
|
||||
let parsed = parsed_string(line).len();
|
||||
println!("||{line}|| -> raw: {raw_size} parsed: {parsed}");
|
||||
char_count += parsed;
|
||||
mem_count += raw_size;
|
||||
for line in input.lines() {
|
||||
let raw_len = line.len();
|
||||
let mem_len = parsed_string(line).len();
|
||||
raw_total += raw_len;
|
||||
mem_total += mem_len;
|
||||
}
|
||||
println!("{} - {} = {}", char_count, mem_count, 0);
|
||||
println!("{}", mem_count - char_count);
|
||||
|
||||
println!("Part 1: {} - {} = {}", raw_total, mem_total, raw_total - mem_total);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
fn next_password(input: &str) -> Vec<char> {
|
||||
// increment the last character.
|
||||
|
||||
let mut work: Vec<_> = input.clone().chars().collect();
|
||||
let wlen = input.len();
|
||||
print!("[[{work:?}]] ");
|
||||
if work[wlen - 1] == 'z' {
|
||||
|
||||
} else {
|
||||
work[wlen - 1] = (work[wlen - 1] as u8 + 1) as char;
|
||||
}
|
||||
println!(" became {work:?}");
|
||||
|
||||
work
|
||||
}
|
||||
|
||||
fn includes_straight(input: &str) -> bool {
|
||||
true
|
||||
}
|
||||
@@ -19,8 +35,10 @@ fn includes_pair(input: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn find_next_password(input: &str) -> String {}
|
||||
|
||||
fn find_next_password(input: &str) -> String {
|
||||
let next_password = next_password(input).join("");
|
||||
next_password
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let params = vec![
|
||||
@@ -31,4 +49,4 @@ fn main() {
|
||||
for (input, output) in params {
|
||||
assert_eq!(find_next_password(input), output.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user