mirror of
https://github.com/iritmaximus/aoc.git
synced 2026-10-12 19:13:38 +03:00
removed old files
This commit is contained in:
Generated
-16
@@ -1,16 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "array-append"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "725731b5abb5b99ed3237a756dd6c6723911f973d998c0e756671f92df20bfec"
|
||||
|
||||
[[package]]
|
||||
name = "day1"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"array-append",
|
||||
]
|
||||
@@ -1,9 +0,0 @@
|
||||
[package]
|
||||
name = "day1"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
array-append = "0.1.0"
|
||||
-2252
File diff suppressed because it is too large
Load Diff
@@ -1,72 +0,0 @@
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
|
||||
const PATH: &str = "./input.txt";
|
||||
|
||||
fn main() {
|
||||
// 1. read file
|
||||
// 2. loop line by line
|
||||
// 3. count all values
|
||||
// 4. if \n, check sum
|
||||
|
||||
let mut highest_sum: i32 = 0;
|
||||
let mut new_sum: i32 = 0;
|
||||
|
||||
let mut highest_sums: Vec<i32> = Vec::new();
|
||||
|
||||
let lines = read_lines(PATH);
|
||||
for result in lines {
|
||||
let line = result.unwrap();
|
||||
|
||||
if line == "" {
|
||||
highest_sum = check_highest_sum(&new_sum, &highest_sum);
|
||||
new_sum = 0;
|
||||
} else {
|
||||
new_sum += line.parse::<i32>().unwrap();
|
||||
check_3_highest(&new_sum, &mut highest_sums);
|
||||
}
|
||||
}
|
||||
|
||||
println!("1. RESULT: {}", highest_sum);
|
||||
println!("2. RESULT {:?}", calc_final_result(highest_sums));
|
||||
}
|
||||
|
||||
fn check_highest_sum(new_sum: &i32, highest_sum: &i32) -> i32 {
|
||||
if *new_sum > *highest_sum {
|
||||
*new_sum
|
||||
} else {
|
||||
*highest_sum
|
||||
}
|
||||
}
|
||||
|
||||
fn check_3_highest(new_sum: &i32, highest_sums: &mut Vec<i32>) {
|
||||
if highest_sums.len() < 3 {
|
||||
highest_sums.push(*new_sum);
|
||||
return;
|
||||
}
|
||||
|
||||
highest_sums.sort();
|
||||
highest_sums.reverse();
|
||||
|
||||
println!(
|
||||
"{} > {} = {}",
|
||||
*new_sum,
|
||||
*highest_sums.last().unwrap(),
|
||||
*new_sum > highest_sums[0]
|
||||
);
|
||||
|
||||
if *new_sum > *highest_sums.last().unwrap() {
|
||||
highest_sums.pop();
|
||||
highest_sums.push(*new_sum);
|
||||
}
|
||||
println!("{:?}", highest_sums);
|
||||
}
|
||||
|
||||
fn calc_final_result(sum: Vec<i32>) -> i32 {
|
||||
sum.iter().sum()
|
||||
}
|
||||
|
||||
fn read_lines(filename: &str) -> io::Lines<BufReader<File>> {
|
||||
let file = File::open(filename).unwrap();
|
||||
return io::BufReader::new(file).lines();
|
||||
}
|
||||
Generated
-7
@@ -1,7 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day2"
|
||||
version = "0.1.0"
|
||||
@@ -1,8 +0,0 @@
|
||||
[package]
|
||||
name = "day2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
-2500
File diff suppressed because it is too large
Load Diff
-110
@@ -1,110 +0,0 @@
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
|
||||
|
||||
fn parse_rpc_str(rpc_string: &str) -> Result<i32, &str> {
|
||||
match rpc_string {
|
||||
"A" | "X" => return Ok(1), // Rock
|
||||
"B" | "Y" => return Ok(2), // Paper
|
||||
"C" | "Z" => return Ok(3), // Scissors
|
||||
_ => Err("Incorrect value :D"), // error lol
|
||||
}
|
||||
}
|
||||
|
||||
fn game_result(p1: &str, p2: &str) -> i32 {
|
||||
let p1_score = parse_rpc_str(p1).unwrap();
|
||||
let p2_score = parse_rpc_str(p2).unwrap();
|
||||
|
||||
// RPC
|
||||
// Rock 1
|
||||
// Paper 2
|
||||
// Scissors 3
|
||||
|
||||
|
||||
// lol the problem wasn't even the calculations
|
||||
match p1_score {
|
||||
1 => {
|
||||
if p2_score == 1 {
|
||||
return 3 + p1_score;
|
||||
}
|
||||
if p2_score == 2 {
|
||||
return 0 + p1_score;
|
||||
}
|
||||
if p2_score == 3 {
|
||||
return 6 + p1_score;
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
if p2_score == 1 {
|
||||
return 6 + p1_score;
|
||||
}
|
||||
if p2_score == 2 {
|
||||
return 3 + p1_score;
|
||||
}
|
||||
if p2_score == 3 {
|
||||
return 0 + p1_score;
|
||||
}
|
||||
},
|
||||
3 => {
|
||||
if p2_score == 1 {
|
||||
return 0 + p1_score;
|
||||
}
|
||||
if p2_score == 2 {
|
||||
return 6 + p1_score;
|
||||
}
|
||||
if p2_score == 3 {
|
||||
return 3 + p1_score;
|
||||
}
|
||||
},
|
||||
_ => return 8000,
|
||||
}
|
||||
|
||||
println!("No result from here: {}, {}", p1_score, p2_score);
|
||||
return 8000;
|
||||
}
|
||||
fn part2_game_result(p1: &str, p2: &str) -> i32 {
|
||||
let p1_score = parse_rpc_str(p1).unwrap();
|
||||
let p2_score = parse_rpc_str(p2).unwrap();
|
||||
|
||||
match p1_score {
|
||||
1 => return 0 + if p2_score == 1 {3} else {p2_score - 1},
|
||||
2 => return 3 + p2_score,
|
||||
3 => return 6 + if p2_score == 3 {1} else {p2_score + 1},
|
||||
_ => return 8000,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let mut result: i32 = 0;
|
||||
let mut p2_result: i32 = 0;
|
||||
let lines = read_lines("input.txt".to_string());
|
||||
for line in lines {
|
||||
let chars_str = line.as_ref().unwrap();
|
||||
let chars: Vec<&str> = chars_str.split(" ").collect();
|
||||
|
||||
if chars.len() != 2 {
|
||||
println!("Fake result?: {}", result);
|
||||
return;
|
||||
}
|
||||
|
||||
// lol the players were the other way around
|
||||
result += game_result(chars[1], chars[0]);
|
||||
p2_result += part2_game_result(chars[1], chars[0])
|
||||
}
|
||||
println!("{}", result);
|
||||
println!("{}", p2_result);
|
||||
|
||||
let mut test_result: i32 = 0;
|
||||
test_result += game_result("A", "Y");
|
||||
test_result += game_result("B", "X");
|
||||
test_result += game_result("C", "Z");
|
||||
test_result += game_result("C", "C");
|
||||
|
||||
println!("{}", test_result);
|
||||
}
|
||||
|
||||
fn read_lines(filename: String) -> io::Lines<BufReader<File>> {
|
||||
let file = File::open(filename).unwrap();
|
||||
return io::BufReader::new(file).lines();
|
||||
}
|
||||
Reference in New Issue
Block a user