cargo fmt
This commit is contained in:
parent
e0e68e5b6a
commit
94b3b3fd3b
4 changed files with 25 additions and 29 deletions
|
@ -1,8 +1,8 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let mut list1: Vec<i32> =
|
||||||
|
serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap();
|
||||||
let mut list1: Vec<i32> = serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap();
|
let mut list2: Vec<i32> =
|
||||||
let mut list2: Vec<i32> = serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap();
|
serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap();
|
||||||
|
|
||||||
list1.sort();
|
list1.sort();
|
||||||
list2.sort();
|
list2.sort();
|
||||||
|
@ -17,8 +17,7 @@ fn main() {
|
||||||
let int2 = list2[i];
|
let int2 = list2[i];
|
||||||
if int1 > int2 {
|
if int1 > int2 {
|
||||||
totaldiff += (int1 - int2) as i64;
|
totaldiff += (int1 - int2) as i64;
|
||||||
}
|
} else if int1 < int2 {
|
||||||
else if int1 < int2 {
|
|
||||||
totaldiff += (int2 - int1) as i64;
|
totaldiff += (int2 - int1) as i64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut list1: Vec<i32> = serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap();
|
let mut list1: Vec<i32> =
|
||||||
let mut list2: Vec<i32> = serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap();
|
serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap();
|
||||||
|
let mut list2: Vec<i32> =
|
||||||
|
serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap();
|
||||||
|
|
||||||
let mut simScoreTotal: i64 = 0;
|
let mut simScoreTotal: i64 = 0;
|
||||||
|
|
||||||
for i in &list1 {
|
for i in &list1 {
|
||||||
let mut totalsRight: i32 = 0;
|
let mut totalsRight: i32 = 0;
|
||||||
for j in &list2 {
|
for j in &list2 {
|
||||||
if i==j {
|
if i == j {
|
||||||
totalsRight += 1;
|
totalsRight += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
simScoreTotal += (totalsRight*i) as i64;
|
simScoreTotal += (totalsRight * i) as i64;
|
||||||
}
|
}
|
||||||
println!("{simScoreTotal}")
|
println!("{simScoreTotal}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,15 @@ use std::thread::current;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// read file input
|
// read file input
|
||||||
let lines: Vec<String> = read_to_string("input.txt").unwrap().lines().map(String::from).collect();
|
let lines: Vec<String> = read_to_string("input.txt")
|
||||||
|
.unwrap()
|
||||||
|
.lines()
|
||||||
|
.map(String::from)
|
||||||
|
.collect();
|
||||||
// current safe total count
|
// current safe total count
|
||||||
let mut safecount = 0;
|
let mut safecount = 0;
|
||||||
// for each line
|
// for each line
|
||||||
for i in lines {
|
for i in lines {
|
||||||
|
|
||||||
println!("{i}");
|
println!("{i}");
|
||||||
// for each line, split into a Vec<String> of the values
|
// for each line, split into a Vec<String> of the values
|
||||||
let mut frfrstr: Vec<String> = i.split_whitespace().map(|s| s.parse().unwrap()).collect();
|
let mut frfrstr: Vec<String> = i.split_whitespace().map(|s| s.parse().unwrap()).collect();
|
||||||
|
@ -28,19 +31,16 @@ fn main() {
|
||||||
let mut sort2 = sort1.clone();
|
let mut sort2 = sort1.clone();
|
||||||
sort2.reverse();
|
sort2.reverse();
|
||||||
if frfr == sort1 || frfr == sort2 {
|
if frfr == sort1 || frfr == sort2 {
|
||||||
|
|
||||||
let mut mode = 0;
|
let mut mode = 0;
|
||||||
let tempval0 = frfr[*&0];
|
let tempval0 = frfr[*&0];
|
||||||
let tempval1 = frfr[*&1];
|
let tempval1 = frfr[*&1];
|
||||||
if tempval0 < tempval1 {
|
if tempval0 < tempval1 {
|
||||||
println!("increasing mode");
|
println!("increasing mode");
|
||||||
mode = 1;
|
mode = 1;
|
||||||
}
|
} else if tempval0 > tempval1 {
|
||||||
else if tempval0 > tempval1 {
|
|
||||||
println!("decreasing mode");
|
println!("decreasing mode");
|
||||||
mode = -1;
|
mode = -1;
|
||||||
}
|
} else if tempval0 == tempval1 {
|
||||||
else if tempval0 == tempval1 {
|
|
||||||
println!("its equal and so its discarded");
|
println!("its equal and so its discarded");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -49,15 +49,14 @@ fn main() {
|
||||||
// starts true, becomes invalid
|
// starts true, becomes invalid
|
||||||
let mut currentcheckstate = true;
|
let mut currentcheckstate = true;
|
||||||
'fr1: for i2 in 1..frfr.len() {
|
'fr1: for i2 in 1..frfr.len() {
|
||||||
let realdiff = frfr[*&i2-1] - (frfr[*&i2]);
|
let realdiff = frfr[*&i2 - 1] - (frfr[*&i2]);
|
||||||
if mode == 1 {
|
if mode == 1 {
|
||||||
if realdiff > -1 || realdiff < -3 {
|
if realdiff > -1 || realdiff < -3 {
|
||||||
println!("realdiff {realdiff} plus");
|
println!("realdiff {realdiff} plus");
|
||||||
currentcheckstate = false;
|
currentcheckstate = false;
|
||||||
println!("abs diff averted");
|
println!("abs diff averted");
|
||||||
}
|
}
|
||||||
}
|
} else if mode == -1 {
|
||||||
else if mode == -1 {
|
|
||||||
if realdiff > 3 || realdiff < 1 {
|
if realdiff > 3 || realdiff < 1 {
|
||||||
println!("realdiff {realdiff} minus");
|
println!("realdiff {realdiff} minus");
|
||||||
currentcheckstate = false;
|
currentcheckstate = false;
|
||||||
|
@ -69,15 +68,11 @@ fn main() {
|
||||||
safemini = true;
|
safemini = true;
|
||||||
println!("allowed")
|
println!("allowed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if safemini {
|
if safemini {
|
||||||
safecount += 1
|
safecount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
println!("{safecount}")
|
println!("{safecount}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,15 @@ use std::thread::current;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// read file input
|
// read file input
|
||||||
let lines: Vec<String> = read_to_string("input.txt").unwrap().lines().map(String::from).collect();
|
let lines: Vec<String> = read_to_string("input.txt")
|
||||||
|
.unwrap()
|
||||||
|
.lines()
|
||||||
|
.map(String::from)
|
||||||
|
.collect();
|
||||||
// current safe total count
|
// current safe total count
|
||||||
let mut safecount = 0;
|
let mut safecount = 0;
|
||||||
// for each line
|
// for each line
|
||||||
for i in lines {
|
for i in lines {
|
||||||
|
|
||||||
println!("{i}");
|
println!("{i}");
|
||||||
// for each line, split into a Vec<String> of the values
|
// for each line, split into a Vec<String> of the values
|
||||||
let mut frfrstr: Vec<String> = i.split_whitespace().map(|s| s.parse().unwrap()).collect();
|
let mut frfrstr: Vec<String> = i.split_whitespace().map(|s| s.parse().unwrap()).collect();
|
||||||
|
@ -27,7 +30,6 @@ fn main() {
|
||||||
frfr.remove(i);
|
frfr.remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// sorted regular and reverse to check condition 1
|
// sorted regular and reverse to check condition 1
|
||||||
let mut sort1 = frfr.clone();
|
let mut sort1 = frfr.clone();
|
||||||
sort1.sort();
|
sort1.sort();
|
||||||
|
@ -77,8 +79,6 @@ fn main() {
|
||||||
if safemini {
|
if safemini {
|
||||||
safecount += 1
|
safecount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
println!("{safecount}")
|
println!("{safecount}")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue