mirror of
https://github.com/iritmaximus/aoc.git
synced 2026-10-12 19:13:38 +03:00
incomplete answer
This commit is contained in:
+25
-8
@@ -1,9 +1,12 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
const FILE_PATH: &str = "./src/input.txt";
|
const FILE_PATH: &str = "./src/input.txt";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
first();
|
first();
|
||||||
|
println!();
|
||||||
second();
|
second();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,21 +48,35 @@ fn second() {
|
|||||||
|
|
||||||
let mut result = 0;
|
let mut result = 0;
|
||||||
let mut starting_value: i32 = 50;
|
let mut starting_value: i32 = 50;
|
||||||
|
let mut previous_zero: bool = false;
|
||||||
for line in contents.lines() {
|
for line in contents.lines() {
|
||||||
let direction: char = line.chars().nth(0).unwrap();
|
let direction: char = line.chars().nth(0).unwrap();
|
||||||
let value: i32 = line.chars().skip(1).collect::<String>().parse().unwrap();
|
let value: i32 = line.chars().skip(1).collect::<String>().parse().unwrap();
|
||||||
|
|
||||||
starting_value += if direction == 'R' { value } else if direction == 'L' { -value } else { 0 };
|
starting_value += if direction == 'R' { value } else if direction == 'L' { -value } else { 0 };
|
||||||
while starting_value > 99 {
|
|
||||||
starting_value -= 100
|
|
||||||
}
|
|
||||||
while starting_value < 0 {
|
|
||||||
starting_value += 100
|
|
||||||
}
|
|
||||||
if starting_value == 0 {
|
if starting_value == 0 {
|
||||||
result += 1;
|
result += 1;
|
||||||
|
previous_zero = true;
|
||||||
|
print!("**");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
} else {
|
||||||
|
// println!("Starting calculations with {starting_value}");
|
||||||
|
while starting_value > 99 {
|
||||||
|
result += 1;
|
||||||
|
starting_value -= 100;
|
||||||
|
print!("*");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
}
|
||||||
|
while starting_value < 0 {
|
||||||
|
result += 1;
|
||||||
|
starting_value += 100;
|
||||||
|
print!("*");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
}
|
||||||
|
if previous_zero { result -= 1; }
|
||||||
|
previous_zero = false;
|
||||||
}
|
}
|
||||||
println!("Line: {line} ({starting_value}, {result})");
|
println!("Line: {line} (v: {starting_value}, r: {result})");
|
||||||
|
|
||||||
}
|
}
|
||||||
println!("Result: {result}");
|
println!("Result: {result}");
|
||||||
|
|||||||
Reference in New Issue
Block a user