From 5f1e5c8d3d5eadc45ad54fc441920a6068637232 Mon Sep 17 00:00:00 2001 From: MelKam Date: Sat, 3 Dec 2022 22:18:13 +0000 Subject: [PATCH] refactor and fix --- day_1/rust/src/main.rs | 8 +++----- day_2/rust/src/main.rs | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/day_1/rust/src/main.rs b/day_1/rust/src/main.rs index a172ef8..1f62201 100644 --- a/day_1/rust/src/main.rs +++ b/day_1/rust/src/main.rs @@ -1,9 +1,8 @@ mod quick_sort; use quick_sort::quick_sort; -use std::fs; -fn get_total_calories(calorie_list: &String) -> Vec { +fn get_total_calories(calorie_list: &str) -> Vec { let mut total_calories = Vec::::new(); let mut temp_sum: i32 = 0; @@ -22,10 +21,9 @@ fn get_total_calories(calorie_list: &String) -> Vec { } fn main() { - let data = - fs::read_to_string("./day_1/input.txt").expect("Error while trying to read input file"); + let data = include_str!("../../input.txt"); - let total_calories = get_total_calories(&data); + let total_calories = get_total_calories(data); let length = total_calories.len(); let max = total_calories[length - 1]; diff --git a/day_2/rust/src/main.rs b/day_2/rust/src/main.rs index 7e46450..eb324a1 100644 --- a/day_2/rust/src/main.rs +++ b/day_2/rust/src/main.rs @@ -79,14 +79,13 @@ fn get_move_by_game_result(opponent_move: MoveType, expected_game_result: GameRe return opponent_move; }; - let inverted_result = - (expected_game_result as i32 - opponent_move as i32).rem_euclid(MOVE_COUNTS) * -1; + let num = expected_game_result as i32 - opponent_move as i32; - if inverted_result == 0 { + if num == 0 { return MoveType::from(MOVE_COUNTS); } - return MoveType::from(inverted_result.rem_euclid(MOVE_COUNTS)); + return MoveType::from((num.rem_euclid(MOVE_COUNTS) * -1).rem_euclid(MOVE_COUNTS)); } fn main() {