-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathad1_1.rs
More file actions
executable file
·27 lines (27 loc) · 858 Bytes
/
ad1_1.rs
File metadata and controls
executable file
·27 lines (27 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fs;
fn main() {
let file_path = "C:\\Users\\iuliia.bubis\\Documents\\MobaXterm\\home\\advent_of_code\\task1.txt";
println!("Read the file {}", file_path);
let task = fs::read_to_string(file_path)
.expect("REad the file error?");
let lines: Vec<&str> = task.lines().collect();
// println!("In the file:\n{task}");
let mut current = 50;
let mut answer = 0;
for line in lines {
let direction = line.chars().nth(0);
let sign: i32;
if direction == Some('L'){
sign = -1;}
else{
sign = 1;
}
let turn: i32 = line[1..].trim().parse().unwrap();
current += sign * turn;
current = current % 100;
if current == 0 {
answer += 1;
}
}
println!("The answer is: {answer}");
}