refactoring

This commit is contained in:
2022-09-25 10:46:09 +02:00
parent f5e98e2851
commit 357c5d42cc

View File

@@ -2,11 +2,11 @@ use itertools::Itertools;
use num_integer::Integer; use num_integer::Integer;
use std::iter; use std::iter;
const INPUT: &str = "59750530221324194853012320069589312027523989854830232144164799228029162830477472078089790749906142587998642764059439173975199276254972017316624772614925079238407309384923979338502430726930592959991878698412537971672558832588540600963437409230550897544434635267172603132396722812334366528344715912756154006039512272491073906389218927420387151599044435060075148142946789007756800733869891008058075303490106699737554949348715600795187032293436328810969288892220127730287766004467730818489269295982526297430971411865028098708555709525646237713045259603175397623654950719275982134690893685598734136409536436003548128411943963263336042840301380655801969822";
#[allow(dead_code)] #[allow(dead_code)]
pub fn run() { pub fn run() {
let input = "03036732577212944063491565474664"; let input = to_digits(INPUT);
// let input = "59750530221324194853012320069589312027523989854830232144164799228029162830477472078089790749906142587998642764059439173975199276254972017316624772614925079238407309384923979338502430726930592959991878698412537971672558832588540600963437409230550897544434635267172603132396722812334366528344715912756154006039512272491073906389218927420387151599044435060075148142946789007756800733869891008058075303490106699737554949348715600795187032293436328810969288892220127730287766004467730818489269295982526297430971411865028098708555709525646237713045259603175397623654950719275982134690893685598734136409536436003548128411943963263336042840301380655801969822";
let input = to_digits(input);
task1(input.clone()); task1(input.clone());
task2(input.clone()); task2(input.clone());
} }
@@ -90,18 +90,38 @@ mod test {
use super::*; use super::*;
#[test] #[test]
fn test_part_1() { fn test_part_1_examples() {
assert_eq!(task1(to_digits("80871224585914546619083218645595")), "24176176"); assert_eq!(
assert_eq!(task1(to_digits("19617804207202209144916044189917")), "73745418"); task1(to_digits("80871224585914546619083218645595")),
assert_eq!(task1(to_digits("69317163492948606335995924319873")), "52432133"); "24176176"
);
assert_eq!(
task1(to_digits("19617804207202209144916044189917")),
"73745418"
);
assert_eq!(
task1(to_digits("69317163492948606335995924319873")),
"52432133"
);
}
#[test]
fn test_part_1_solution() {
assert_eq!(task1(to_digits(INPUT)), "84487724");
} }
#[test] #[test]
fn test_part_2() { fn test_part_2() {
assert_eq!(
assert_eq!(task2(to_digits("02935109699940807407585447034323")), "78725270"); task2(to_digits("02935109699940807407585447034323")),
assert_eq!(task2(to_digits("03036732577212944063491565474664")), "84462026"); "78725270"
assert_eq!(task2(to_digits("03081770884921959731165446850517")), "53553731"); );
assert_eq!(
task2(to_digits("03036732577212944063491565474664")),
"84462026"
);
assert_eq!(
task2(to_digits("03081770884921959731165446850517")),
"53553731"
);
} }
} }