updated the code based on thenew rustfmt.toml
Dieser Commit ist enthalten in:
Ursprung
5129d46b35
Commit
6a7843b0da
7 geänderte Dateien mit 101 neuen und 26 gelöschten Zeilen
11
.editorconfig
Normale Datei
11
.editorconfig
Normale Datei
|
@ -0,0 +1,11 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = truew
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
|
@ -42,7 +42,11 @@ impl Round {
|
||||||
ok
|
ok
|
||||||
}
|
}
|
||||||
fn power(&self) -> u64 {
|
fn power(&self) -> u64 {
|
||||||
let mut sack = Sack { reds: 0, greens: 0, blues: 0 };
|
let mut sack = Sack {
|
||||||
|
reds: 0,
|
||||||
|
greens: 0,
|
||||||
|
blues: 0,
|
||||||
|
};
|
||||||
for take in self.takes.clone() {
|
for take in self.takes.clone() {
|
||||||
if take.red > sack.reds {
|
if take.red > sack.reds {
|
||||||
sack.reds = take.red
|
sack.reds = take.red
|
||||||
|
@ -66,7 +70,11 @@ impl From<&str> for Round {
|
||||||
takes: Vec::<Take>::new(),
|
takes: Vec::<Take>::new(),
|
||||||
};
|
};
|
||||||
for taking in value.get(doublecolon + 1..).unwrap().split(";") {
|
for taking in value.get(doublecolon + 1..).unwrap().split(";") {
|
||||||
let mut take = Take { red: 0, green: 0, blue: 0 };
|
let mut take = Take {
|
||||||
|
red: 0,
|
||||||
|
green: 0,
|
||||||
|
blue: 0,
|
||||||
|
};
|
||||||
for color in taking.split(',').map(str::trim) {
|
for color in taking.split(',').map(str::trim) {
|
||||||
let mut i = color.splitn(2, char::is_whitespace);
|
let mut i = color.splitn(2, char::is_whitespace);
|
||||||
let amount = parsenumber(i.next().unwrap());
|
let amount = parsenumber(i.next().unwrap());
|
||||||
|
@ -88,7 +96,11 @@ fn main() {
|
||||||
for game in DATA.split('\n') {
|
for game in DATA.split('\n') {
|
||||||
gamerounds.push(game.into());
|
gamerounds.push(game.into());
|
||||||
}
|
}
|
||||||
let sack = Sack { reds: 12, greens: 13, blues: 14 };
|
let sack = Sack {
|
||||||
|
reds: 12,
|
||||||
|
greens: 13,
|
||||||
|
blues: 14,
|
||||||
|
};
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
for round in gamerounds.clone() {
|
for round in gamerounds.clone() {
|
||||||
if round.possible(sack) {
|
if round.possible(sack) {
|
||||||
|
|
|
@ -49,7 +49,10 @@ fn get_x(list: Vec<TextPos>) -> usize {
|
||||||
fn follow_text(data: &Table, start_point: Kartesian<usize>, direction: KartesianDirection, current_pos: Kartesian<usize>, chars: Vec<char>, list: &mut Vec<TextPos>) {
|
fn follow_text(data: &Table, start_point: Kartesian<usize>, direction: KartesianDirection, current_pos: Kartesian<usize>, chars: Vec<char>, list: &mut Vec<TextPos>) {
|
||||||
let mut iter = chars.iter().cloned();
|
let mut iter = chars.iter().cloned();
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
None => list.push(TextPos { start: start_point, end: current_pos }),
|
None => list.push(TextPos {
|
||||||
|
start: start_point,
|
||||||
|
end: current_pos,
|
||||||
|
}),
|
||||||
Some(c) => match current_pos.move_dir_max(direction.vector_abs(), direction, Kartesian::maximum(data)) {
|
Some(c) => match current_pos.move_dir_max(direction.vector_abs(), direction, Kartesian::maximum(data)) {
|
||||||
None => return,
|
None => return,
|
||||||
Some(new) => {
|
Some(new) => {
|
||||||
|
|
|
@ -18,13 +18,23 @@ struct DirectionalKartesian<T: Integer> {
|
||||||
}
|
}
|
||||||
impl<T: Integer> From<(Kartesian<T>, KartesianDirection)> for DirectionalKartesian<T> {
|
impl<T: Integer> From<(Kartesian<T>, KartesianDirection)> for DirectionalKartesian<T> {
|
||||||
fn from(value: (Kartesian<T>, KartesianDirection)) -> Self {
|
fn from(value: (Kartesian<T>, KartesianDirection)) -> Self {
|
||||||
DirectionalKartesian { x: value.0.x, y: value.0.y, dir: value.1 }
|
DirectionalKartesian {
|
||||||
|
x: value.0.x,
|
||||||
|
y: value.0.y,
|
||||||
|
dir: value.1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Integer + Copy> Into<(Kartesian<T>, KartesianDirection)> for &DirectionalKartesian<T> {
|
impl<T: Integer + Copy> Into<(Kartesian<T>, KartesianDirection)> for &DirectionalKartesian<T> {
|
||||||
fn into(self) -> (Kartesian<T>, KartesianDirection) {
|
fn into(self) -> (Kartesian<T>, KartesianDirection) {
|
||||||
(Kartesian { x: self.x, y: self.y }, self.dir)
|
(
|
||||||
|
Kartesian {
|
||||||
|
x: self.x,
|
||||||
|
y: self.y,
|
||||||
|
},
|
||||||
|
self.dir,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,13 @@ impl StoneCounter {
|
||||||
fn new(start_values: Vec<u64>, rounds: usize) -> StoneCounter {
|
fn new(start_values: Vec<u64>, rounds: usize) -> StoneCounter {
|
||||||
let mut cache = Vec::with_capacity(start_values.len());
|
let mut cache = Vec::with_capacity(start_values.len());
|
||||||
for v in start_values.iter() {
|
for v in start_values.iter() {
|
||||||
cache.push(Stone { number: *v, left: rounds });
|
cache.push(Stone {
|
||||||
|
number: *v,
|
||||||
|
left: rounds,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
StoneCounter {
|
StoneCounter {
|
||||||
cache: cache,
|
cache,
|
||||||
map: HashMap::with_capacity(10_000),
|
map: HashMap::with_capacity(10_000),
|
||||||
stones: 0,
|
stones: 0,
|
||||||
start: rounds,
|
start: rounds,
|
||||||
|
@ -72,7 +75,10 @@ impl StoneCounter {
|
||||||
stone.left -= skip.skipped_steps;
|
stone.left -= skip.skipped_steps;
|
||||||
}
|
}
|
||||||
stone.number = skip.newnumber_a;
|
stone.number = skip.newnumber_a;
|
||||||
self.cache.push(Stone { number: skip.newnumber_b, left: stone.left });
|
self.cache.push(Stone {
|
||||||
|
number: skip.newnumber_b,
|
||||||
|
left: stone.left,
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
ExtendedOption::Unset => {},
|
ExtendedOption::Unset => {},
|
||||||
|
|
|
@ -108,18 +108,54 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_safety() {
|
fn test_safety() {
|
||||||
let positions = vec![
|
let positions = vec![
|
||||||
Kartesian { x: 5, y: 3 },
|
Kartesian {
|
||||||
Kartesian { x: 4, y: 5 },
|
x: 5,
|
||||||
Kartesian { x: 0, y: 9 },
|
y: 3,
|
||||||
Kartesian { x: 5, y: 4 },
|
},
|
||||||
Kartesian { x: 6, y: 1 },
|
Kartesian {
|
||||||
Kartesian { x: 3, y: 1 },
|
x: 4,
|
||||||
Kartesian { x: 0, y: 6 },
|
y: 5,
|
||||||
Kartesian { x: 3, y: 2 },
|
},
|
||||||
Kartesian { x: 2, y: 0 },
|
Kartesian {
|
||||||
Kartesian { x: 0, y: 6 },
|
x: 0,
|
||||||
Kartesian { x: 5, y: 4 },
|
y: 9,
|
||||||
Kartesian { x: 6, y: 6 },
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 5,
|
||||||
|
y: 4,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 6,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 3,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 0,
|
||||||
|
y: 6,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 3,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 2,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 0,
|
||||||
|
y: 6,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 5,
|
||||||
|
y: 4,
|
||||||
|
},
|
||||||
|
Kartesian {
|
||||||
|
x: 6,
|
||||||
|
y: 6,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
assert_eq!(calc_safety(positions, Kartesian::new(7, 11)), (1, 3, 4, 1));
|
assert_eq!(calc_safety(positions, Kartesian::new(7, 11)), (1, 3, 4, 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,11 +87,8 @@ fn main() {
|
||||||
let map = Map::from(convert_to_array::<_, _, '\n'>(DATA, line_to_char));
|
let map = Map::from(convert_to_array::<_, _, '\n'>(DATA, line_to_char));
|
||||||
//println!("Startmap: \n{}", map);
|
//println!("Startmap: \n{}", map);
|
||||||
let deer = find_character(&map, 'S');
|
let deer = find_character(&map, 'S');
|
||||||
let best = search_end(&map, deer, KartesianDirection::Right);
|
let best = search_end(&map, deer, KartesianDirection::East);
|
||||||
println!(
|
println!("Best Score is: {}", best)
|
||||||
"Best Score is: {}",
|
|
||||||
best
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren