Skip to content

Commit 93bc002

Browse files
committed
Code cleanup
1 parent 06e0f76 commit 93bc002

File tree

5 files changed

+7
-54
lines changed

5 files changed

+7
-54
lines changed

src/days/_1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn init() -> Result<_1, ()> {
1313
collection_2: vec![],
1414
};
1515

16-
match utils::http::request(1, None) {
16+
match utils::http::request(1) {
1717
Ok(input) => {
1818
for input_line in input.split("\n") {
1919
let inputs: Vec<&str> = input_line.split(" ").collect();

src/days/_2.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct _2 {
77
pub fn init() -> Result<_2, ()> {
88
let mut _2 = _2 { collection: vec![] };
99

10-
match utils::http::request(2, None) {
10+
match utils::http::request(2) {
1111
Ok(input) => {
1212
for input_line in input.split("\n") {
1313
if input_line.len() == 0 {
@@ -27,8 +27,6 @@ pub fn init() -> Result<_2, ()> {
2727

2828
_2.collection.push(input_line_collection);
2929
}
30-
// TODO: Fix edge case:
31-
// _2.collection.push(vec![18, 21, 19, 17, 16]);
3230
}
3331
Err(()) => {
3432
return Err(());
@@ -43,40 +41,6 @@ impl _2 {
4341

4442
for line_collection in self.collection.iter() {
4543
result += self.is_valid_line_collection(line_collection, None, 0);
46-
// let mut is_valid_line_collection = true;
47-
48-
// let mut p_previous_number: Option<&i32> = None;
49-
// let mut p_increase: Option<bool> = None;
50-
51-
// for number in line_collection.iter() {
52-
// match p_previous_number {
53-
// Some(previous_number) => {
54-
// let difference = previous_number - number;
55-
56-
// if !(0 < difference.abs() && difference.abs() < 4) {
57-
// is_valid_line_collection = false;
58-
// break;
59-
// }
60-
61-
// p_previous_number = Some(number);
62-
63-
// match p_increase {
64-
// Some(increase) => {
65-
// if increase != difference.is_positive() {
66-
// is_valid_line_collection = false;
67-
// break;
68-
// }
69-
// }
70-
// None => p_increase = Some(difference.is_positive()),
71-
// }
72-
// }
73-
// None => p_previous_number = Some(number),
74-
// }
75-
// }
76-
77-
// if is_valid_line_collection {
78-
// result += 1;
79-
// }
8044
}
8145

8246
result.to_string()
@@ -105,7 +69,7 @@ impl _2 {
10569

10670
let mut i_line_collection = line_collection.clone();
10771
if let Some(invalid_number_index) = p_invalid_number_index {
108-
if invalid_number_index as i8 - allowed_mut_count as i8 >= 0 {
72+
if !((invalid_number_index as i8 - allowed_mut_count as i8) < 0) {
10973
i_line_collection.remove(invalid_number_index - allowed_mut_count);
11074
}
11175
}

src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// TODO: Review day 1 and 2 code
2-
31
use std::process::ExitCode;
42

53
mod days;

src/utils/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{env, fs};
22

33
pub fn load_session_token() -> Result<(), u8> {
4-
println!("Loading all environment variables from the dotenv file");
4+
println!("Loading all environment variables from the dotenv file...");
55

66
let p_dotenv_vec = fs::read(".env");
77

src/utils/http.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
// TODO: Replace the Curl subprocess with a basic HTTP/2 request using std::io::net
2-
// TODO: Cache the response
32
// TODO: Prevent early fetching
4-
// TODO: Improve input parsing
3+
// TODO: Cache the response
54

65
use std::{env, process::Command};
76

8-
pub fn request(day: u8, part: Option<u8>) -> Result<String, ()> {
9-
match part {
10-
Some(part_number) => {
11-
println!(
12-
"Requesting the input of day {}, part {}",
13-
&day, &part_number
14-
)
15-
}
16-
None => println!("Requesting the input of day {}", &day),
17-
}
7+
pub fn request(day: u8) -> Result<String, ()> {
8+
println!("Requesting the input of day {}...", &day);
189

1910
let p_request = Command::new("/usr/bin/curl")
2011
.arg("-H")

0 commit comments

Comments
 (0)