Skip to content

Commit

Permalink
refactor and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MellKam committed Dec 3, 2022
1 parent 44415fe commit 5f1e5c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 3 additions & 5 deletions day_1/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mod quick_sort;

use quick_sort::quick_sort;
use std::fs;

fn get_total_calories(calorie_list: &String) -> Vec<i32> {
fn get_total_calories(calorie_list: &str) -> Vec<i32> {
let mut total_calories = Vec::<i32>::new();
let mut temp_sum: i32 = 0;

Expand All @@ -22,10 +21,9 @@ fn get_total_calories(calorie_list: &String) -> Vec<i32> {
}

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];
Expand Down
7 changes: 3 additions & 4 deletions day_2/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5f1e5c8

Please sign in to comment.