init
This commit is contained in:
7
d10/Cargo.lock
generated
Normal file
7
d10/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "d05"
|
||||
version = "0.1.0"
|
8
d10/Cargo.toml
Normal file
8
d10/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "d05"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
140
d10/input.txt
Normal file
140
d10/input.txt
Normal file
@ -0,0 +1,140 @@
|
||||
addx 2
|
||||
addx 3
|
||||
addx 1
|
||||
noop
|
||||
addx 4
|
||||
addx 1
|
||||
noop
|
||||
addx 28
|
||||
addx -24
|
||||
noop
|
||||
addx 5
|
||||
addx 17
|
||||
addx -16
|
||||
noop
|
||||
addx 6
|
||||
noop
|
||||
addx -7
|
||||
addx 11
|
||||
addx 4
|
||||
noop
|
||||
addx 1
|
||||
addx -36
|
||||
addx -2
|
||||
noop
|
||||
noop
|
||||
addx 10
|
||||
noop
|
||||
noop
|
||||
addx -2
|
||||
addx 2
|
||||
addx 25
|
||||
addx -18
|
||||
addx 23
|
||||
addx -22
|
||||
addx 2
|
||||
addx 5
|
||||
addx -10
|
||||
addx -15
|
||||
addx 28
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -16
|
||||
addx 17
|
||||
addx -36
|
||||
noop
|
||||
noop
|
||||
addx 39
|
||||
addx -32
|
||||
addx -5
|
||||
addx 7
|
||||
addx 1
|
||||
addx 5
|
||||
addx -13
|
||||
addx 1
|
||||
addx 17
|
||||
addx 1
|
||||
noop
|
||||
addx 7
|
||||
noop
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -37
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 6
|
||||
addx 11
|
||||
addx -7
|
||||
addx 29
|
||||
addx -22
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
addx 7
|
||||
addx -28
|
||||
addx 24
|
||||
addx 3
|
||||
addx 2
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx -38
|
||||
noop
|
||||
addx 7
|
||||
addx -2
|
||||
addx 1
|
||||
addx 6
|
||||
addx -10
|
||||
addx 38
|
||||
addx -25
|
||||
addx 5
|
||||
addx 2
|
||||
addx -10
|
||||
addx 11
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
addx 5
|
||||
addx -39
|
||||
addx 1
|
||||
addx 1
|
||||
addx 3
|
||||
addx 2
|
||||
addx 4
|
||||
addx 29
|
||||
addx -23
|
||||
noop
|
||||
addx -1
|
||||
addx 5
|
||||
noop
|
||||
addx 11
|
||||
addx -10
|
||||
addx 5
|
||||
addx -1
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
addx 3
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
80
d10/src/a1.rs
Normal file
80
d10/src/a1.rs
Normal file
@ -0,0 +1,80 @@
|
||||
|
||||
enum COMMAND {
|
||||
ADD,
|
||||
NOP
|
||||
}
|
||||
|
||||
struct CMD {
|
||||
cmd :COMMAND,
|
||||
op :i32
|
||||
}
|
||||
|
||||
fn parse_inp(inp :&Vec<String>) -> Vec<CMD> {
|
||||
|
||||
let mut res = vec![];
|
||||
|
||||
for s in inp {
|
||||
let split = s.split(' ').collect::<Vec<&str>>();
|
||||
match split[0] {
|
||||
"addx" => {
|
||||
res.push(CMD {cmd: COMMAND::ADD, op: split[1].parse::<i32>().unwrap()});
|
||||
}
|
||||
|
||||
"noop" => {
|
||||
res.push(CMD {cmd: COMMAND::NOP, op: 0});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
fn check_cycle(sum :&mut i32, x_reg :&i32, cycle :&i32) {
|
||||
|
||||
|
||||
if (*cycle + 20) % 40 == 0 {
|
||||
*sum += *x_reg * *cycle;
|
||||
println!("{}, {}, {}, {}", cycle, x_reg, cycle * x_reg, sum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn run(inp :Vec<String>) {
|
||||
|
||||
let mut cycle = 0;
|
||||
|
||||
let mut sum = 0;
|
||||
|
||||
let mut x_reg = 1;
|
||||
|
||||
let parsed_inp :Vec<CMD> = parse_inp(&inp);
|
||||
|
||||
for cmd in parsed_inp {
|
||||
|
||||
match cmd.cmd {
|
||||
COMMAND::ADD => {
|
||||
cycle += 1;
|
||||
|
||||
check_cycle(&mut sum, &x_reg, &cycle);
|
||||
|
||||
cycle += 1;
|
||||
|
||||
check_cycle(&mut sum, &x_reg, &cycle);
|
||||
|
||||
x_reg += cmd.op;
|
||||
}
|
||||
|
||||
COMMAND::NOP => {
|
||||
cycle += 1;
|
||||
|
||||
check_cycle(&mut sum, &x_reg, &cycle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
println!("a1: {}", sum);
|
||||
|
||||
}
|
96
d10/src/a2.rs
Normal file
96
d10/src/a2.rs
Normal file
@ -0,0 +1,96 @@
|
||||
|
||||
enum COMMAND {
|
||||
ADD,
|
||||
NOP
|
||||
}
|
||||
|
||||
struct CMD {
|
||||
cmd :COMMAND,
|
||||
op :i32
|
||||
}
|
||||
|
||||
fn parse_inp(inp :&Vec<String>) -> Vec<CMD> {
|
||||
|
||||
let mut res = vec![];
|
||||
|
||||
for s in inp {
|
||||
let split = s.split(' ').collect::<Vec<&str>>();
|
||||
match split[0] {
|
||||
"addx" => {
|
||||
res.push(CMD {cmd: COMMAND::ADD, op: split[1].parse::<i32>().unwrap()});
|
||||
}
|
||||
|
||||
"noop" => {
|
||||
res.push(CMD {cmd: COMMAND::NOP, op: 0});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
fn check_cycle(width :&usize, height :&usize, screen :&mut Vec<char>, x_reg :&i32, cycle :&i32) {
|
||||
|
||||
if (cycle-1) as usize >= width * height {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((x_reg-1)..=(x_reg+1)).contains(&((cycle-1) % (*width as i32))) {
|
||||
screen[(cycle-1) as usize] = '#';
|
||||
println!("{}, {}", cycle-1, x_reg, );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
pub fn run(inp :Vec<String>) {
|
||||
|
||||
const SCREEN_WIDTH :usize = 40;
|
||||
const SCREEN_HEIGHT :usize = 6;
|
||||
|
||||
let mut screen :Vec<char> = vec!['.'; SCREEN_HEIGHT * SCREEN_WIDTH];
|
||||
|
||||
let mut cycle = 0;
|
||||
|
||||
let mut x_reg = 1;
|
||||
|
||||
let parsed_inp :Vec<CMD> = parse_inp(&inp);
|
||||
|
||||
for cmd in parsed_inp {
|
||||
|
||||
match cmd.cmd {
|
||||
COMMAND::ADD => {
|
||||
cycle += 1;
|
||||
|
||||
check_cycle(&SCREEN_WIDTH, &SCREEN_HEIGHT, &mut screen, &x_reg, &cycle);
|
||||
|
||||
cycle += 1;
|
||||
|
||||
check_cycle(&SCREEN_WIDTH, &SCREEN_HEIGHT, &mut screen, &x_reg, &cycle);
|
||||
|
||||
x_reg += cmd.op;
|
||||
}
|
||||
|
||||
COMMAND::NOP => {
|
||||
cycle += 1;
|
||||
check_cycle(&SCREEN_WIDTH, &SCREEN_HEIGHT, &mut screen, &x_reg, &cycle);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
println!("a2:");
|
||||
|
||||
for i in 0..screen.len() {
|
||||
if i % SCREEN_WIDTH == 0 {
|
||||
println!("");
|
||||
}
|
||||
print!("{}", screen[i]);
|
||||
}
|
||||
|
||||
}
|
41
d10/src/main.rs
Normal file
41
d10/src/main.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use std::io::BufRead;
|
||||
|
||||
mod a1;
|
||||
mod a2;
|
||||
|
||||
fn read_file(path :&str) -> Vec<String> {
|
||||
|
||||
let file = std::fs::File::open(path);
|
||||
|
||||
return match file {
|
||||
|
||||
Ok(handle) => {
|
||||
|
||||
let reader = std::io::BufReader::new(handle);
|
||||
|
||||
let mut vec : Vec<String> = vec![];
|
||||
|
||||
reader.lines().for_each(|elem| {
|
||||
vec.push(elem.unwrap());
|
||||
});
|
||||
|
||||
vec
|
||||
|
||||
}
|
||||
|
||||
Err(_) => vec![]
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let inp :Vec<String> = read_file("input.txt");
|
||||
|
||||
a1::run(inp.clone());
|
||||
|
||||
a2::run(inp);
|
||||
|
||||
}
|
1
d10/target/.rustc_info.json
Normal file
1
d10/target/.rustc_info.json
Normal file
@ -0,0 +1 @@
|
||||
{"rustc_fingerprint":15594459422025777716,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.65.0 (897e37553 2022-11-02)\nbinary: rustc\ncommit-hash: 897e37553bba8b42751c67658967889d11ecd120\ncommit-date: 2022-11-02\nhost: x86_64-pc-windows-msvc\nrelease: 1.65.0\nLLVM version: 15.0.0\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"8623966523033996810":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"8204103499295538959":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\tfuec\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\tfuec\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
3
d10/target/CACHEDIR.TAG
Normal file
3
d10/target/CACHEDIR.TAG
Normal file
@ -0,0 +1,3 @@
|
||||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
# This file is a cache directory tag created by cargo.
|
||||
# For information about cache directory tags see https://bford.info/cachedir/
|
0
d10/target/debug/.cargo-lock
Normal file
0
d10/target/debug/.cargo-lock
Normal file
@ -0,0 +1 @@
|
||||
a62220af2acc103e
|
@ -0,0 +1 @@
|
||||
{"rustc":2347157018072859861,"features":"[]","target":16997346216964277088,"profile":7309141686862299243,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d05-54bad1502471c435\\dep-bin-d05"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
BIN
d10/target/debug/.fingerprint/d05-54bad1502471c435/dep-bin-d05
Normal file
BIN
d10/target/debug/.fingerprint/d05-54bad1502471c435/dep-bin-d05
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
e737b342d3e62e08
|
@ -0,0 +1 @@
|
||||
{"rustc":2347157018072859861,"features":"[]","target":16997346216964277088,"profile":9251013656241001069,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d05-60235cbe9d69ff8a\\dep-bin-d05"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
BIN
d10/target/debug/.fingerprint/d05-60235cbe9d69ff8a/dep-bin-d05
Normal file
BIN
d10/target/debug/.fingerprint/d05-60235cbe9d69ff8a/dep-bin-d05
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
f0fa31a79957e157
|
@ -0,0 +1 @@
|
||||
{"rustc":2347157018072859861,"features":"[]","target":16997346216964277088,"profile":1021633075455700787,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d05-cd6375c08847f9de\\dep-test-bin-d05"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
1
d10/target/debug/d05.d
Normal file
1
d10/target/debug/d05.d
Normal file
@ -0,0 +1 @@
|
||||
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\d05.exe: C:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\src\a1.rs C:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\src\a2.rs C:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\src\main.rs
|
BIN
d10/target/debug/d05.exe
Normal file
BIN
d10/target/debug/d05.exe
Normal file
Binary file not shown.
BIN
d10/target/debug/d05.pdb
Normal file
BIN
d10/target/debug/d05.pdb
Normal file
Binary file not shown.
7
d10/target/debug/deps/d05-54bad1502471c435.d
Normal file
7
d10/target/debug/deps/d05-54bad1502471c435.d
Normal file
@ -0,0 +1,7 @@
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\deps\d05-54bad1502471c435.rmeta: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\deps\d05-54bad1502471c435.d: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
src\main.rs:
|
||||
src\a1.rs:
|
||||
src\a2.rs:
|
7
d10/target/debug/deps/d05-cd6375c08847f9de.d
Normal file
7
d10/target/debug/deps/d05-cd6375c08847f9de.d
Normal file
@ -0,0 +1,7 @@
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\deps\d05-cd6375c08847f9de.rmeta: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\deps\d05-cd6375c08847f9de.d: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
src\main.rs:
|
||||
src\a1.rs:
|
||||
src\a2.rs:
|
7
d10/target/debug/deps/d05.d
Normal file
7
d10/target/debug/deps/d05.d
Normal file
@ -0,0 +1,7 @@
|
||||
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\deps\d05.exe: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d10\target\debug\deps\d05.d: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
src\main.rs:
|
||||
src\a1.rs:
|
||||
src\a2.rs:
|
BIN
d10/target/debug/deps/d05.exe
Normal file
BIN
d10/target/debug/deps/d05.exe
Normal file
Binary file not shown.
BIN
d10/target/debug/deps/d05.pdb
Normal file
BIN
d10/target/debug/deps/d05.pdb
Normal file
Binary file not shown.
0
d10/target/debug/deps/libd05-54bad1502471c435.rmeta
Normal file
0
d10/target/debug/deps/libd05-54bad1502471c435.rmeta
Normal file
0
d10/target/debug/deps/libd05-cd6375c08847f9de.rmeta
Normal file
0
d10/target/debug/deps/libd05-cd6375c08847f9de.rmeta
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user