This commit is contained in:
Tim Nope
2022-12-11 18:06:33 +01:00
commit 6b6fc8d486
1361 changed files with 19939 additions and 0 deletions

7
d02/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "d02"
version = "0.1.0"

8
d02/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "d02"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

2500
d02/input.txt Normal file

File diff suppressed because it is too large Load Diff

70
d02/src/a1.rs Normal file
View File

@ -0,0 +1,70 @@
fn eval_score(enemy_move :&str, ally_move :&str) -> i32 {
let diff = ally_move.chars().nth(0).unwrap() as i32 - (enemy_move.chars().nth(0).unwrap() as i32 + ('W' as i32 - 'A' as i32));
let bonus = ally_move.chars().nth(0).unwrap() as i32 - 'W' as i32;
let tmp = match diff {
1 => 3,
2 | -1 => 6,
_ => 0
} + bonus;
tmp
}
pub fn run(inp :Vec<String>) {
let mut score = 0;
inp.iter().for_each(|elem| {
let moves = elem.split(' ').collect::<Vec<&str>>();
let a = eval_score(moves[0], moves[1]);
score += a;
});
println!("a1: {}", score);
}
/*
win: 2, -1
Draw: 1
Lose: 3, 0
88 - 87 = 1 -> Draw
89 - 87 = 2 -> Win
90 - 87 = 3 -> Lose
X - (A + (W - A)) = 0 -> draw
A - Y + W = -1 -> Win
A - Z + W = -2 -> Lose
88 - 88 = 0 -> Lose
89 - 88 = 1 -> Draw
90 - 88 = 2 -> Win
B - X + W = 1 -> Lose
B - Y + W = 0 -> draw
B - Z + W = -1 -> Win
88 - 89 = -1 -> Win
89 - 89 = 0 -> Lose
90 - 89 = 1 -> Draw
C - X + W = 2 -> Win
Y - (C + (W - A)) = 1 -> Lose
C - Z + W = 0 -> draw
A: Stein
B: Papier
C: Schere
X: Stein (1)
Y: Papier (2)
Z: Schere (3)
win: 6
tie: 3
loose: 0
*/

74
d02/src/a2.rs Normal file
View File

@ -0,0 +1,74 @@
fn eval_score(enemy_move :&str, ally_move :&str) -> i32 {
let ally_char = ally_move.chars().nth(0).unwrap();
let enemy_char = enemy_move.chars().nth(0).unwrap();
let diff = ally_char as i32 - (enemy_char as i32 + ('W' as i32 - 'A' as i32));
let move_score = match enemy_char {
'A' => {if diff == 1 {diff + 2} else {(diff + 2) % 3}}
'B' => {diff + 1}
'C' => {if diff == 1 {diff} else {diff + 3}}
_ => {0}
};
let win_score = match ally_char {
'X' => 0,
'Y' => 3,
'Z' => 6,
_ => 0
};
move_score + win_score
}
pub fn run(inp :Vec<String>) {
let mut score = 0;
inp.iter().for_each(|elem| {
let moves = elem.split(' ').collect::<Vec<&str>>();
let a = eval_score(moves[0], moves[1]);
score += a;
});
println!("a2: {}", score);
}
/*
Stein: 0, 1, 2
Schere: 0, 1, 2
Papier: -1, 1, 3
X - (A + (W-A)) = 1 -> Schere (3)
Y - (A + (W-A)) = 2 -> Stein (1)
Z - (A + (W-A)) = 3 -> Papier (2)
X - (B + (W-A)) = 0 -> Stein (1)
Y - (B + (W-A)) = 1 -> Papier (2)
Z - (B + (W-A)) = 2 -> Schere (3)
X - (C + (W-A)) = -1 -> Papier (2)
Y - (C + (W-A)) = 0 -> Schere (3)
Z - (C + (W-A)) = 1 -> Stein (1)
A: Stein
B: Papier
C: Schere
X: loose
Y: draw
Z: win
scere: 1
stein: 2
paier: 3
win: 6
tie: 3
loose: 0
*/

41
d02/src/main.rs Normal file
View 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);
}

View 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":""},"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":""},"8623966523033996810":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""}},"successes":{}}

3
d02/target/CACHEDIR.TAG Normal file
View 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/

View File

View File

@ -0,0 +1 @@
da14129948edda72

View File

@ -0,0 +1 @@
{"rustc":2347157018072859861,"features":"[]","target":18394517894148844104,"profile":7309141686862299243,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d02-63a7fbbe15ec47a4\\dep-bin-d02"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View File

@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@ -0,0 +1 @@
af0866ac3d27889c

View File

@ -0,0 +1 @@
{"rustc":2347157018072859861,"features":"[]","target":18394517894148844104,"profile":1021633075455700787,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d02-843723054dca7a09\\dep-test-bin-d02"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View File

@ -0,0 +1 @@
f6c0fec9cdeb5e02

View File

@ -0,0 +1 @@
{"rustc":2347157018072859861,"features":"[]","target":18394517894148844104,"profile":9251013656241001069,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d02-c8b2c2235a5e3702\\dep-bin-d02"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View File

@ -0,0 +1 @@
This file has an mtime of when this was started.

1
d02/target/debug/d02.d Normal file
View File

@ -0,0 +1 @@
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\d02.exe: C:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\src\a1.rs C:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\src\a2.rs C:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\src\main.rs

BIN
d02/target/debug/d02.exe Normal file

Binary file not shown.

BIN
d02/target/debug/d02.pdb Normal file

Binary file not shown.

View File

@ -0,0 +1,7 @@
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\deps\d02-63a7fbbe15ec47a4.rmeta: src\main.rs src\a1.rs src\a2.rs
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\deps\d02-63a7fbbe15ec47a4.d: src\main.rs src\a1.rs src\a2.rs
src\main.rs:
src\a1.rs:
src\a2.rs:

View File

@ -0,0 +1,7 @@
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\deps\d02-843723054dca7a09.rmeta: src\main.rs src\a1.rs src\a2.rs
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\deps\d02-843723054dca7a09.d: src\main.rs src\a1.rs src\a2.rs
src\main.rs:
src\a1.rs:
src\a2.rs:

View File

@ -0,0 +1,7 @@
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\deps\d02.exe: src\main.rs src\a1.rs src\a2.rs
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d02\target\debug\deps\d02.d: src\main.rs src\a1.rs src\a2.rs
src\main.rs:
src\a1.rs:
src\a2.rs:

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More