Small changes.
This commit is contained in:
@@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
fn follow_instructions(input: &str) -> (Option<(i32, i32)>, Option<(i32, i32)>) {
|
fn follow_instructions(input: &str) -> (Option<(i32, i32)>, Option<(i32, i32)>) {
|
||||||
let instructions = input
|
let instructions = input
|
||||||
.split(",")
|
.split(',')
|
||||||
.map(|x| x.trim())
|
.map(|x| x.trim())
|
||||||
.map(|x| x.split_at(1))
|
.map(|x| x.split_at(1))
|
||||||
.map(|(x, y)| (x, y.parse::<i32>().unwrap()));
|
.map(|(x, y)| (x, y.parse::<i32>().unwrap()));
|
||||||
@@ -36,7 +36,7 @@ fn follow_instructions(input: &str) -> (Option<(i32, i32)>, Option<(i32, i32)>)
|
|||||||
delta = match direction {
|
delta = match direction {
|
||||||
"R" => (delta.1, delta.0 * -1),
|
"R" => (delta.1, delta.0 * -1),
|
||||||
"L" => (delta.1 * -1, delta.0),
|
"L" => (delta.1 * -1, delta.0),
|
||||||
_ => delta,
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for _ in 0..steps {
|
for _ in 0..steps {
|
||||||
|
|||||||
@@ -22,28 +22,27 @@ fn main() {
|
|||||||
|
|
||||||
let count_v = input
|
let count_v = input
|
||||||
.chunks(3)
|
.chunks(3)
|
||||||
.flat_map(|x| {
|
.flat_map(|rows| {
|
||||||
x[0]
|
rows[0].iter()
|
||||||
.iter()
|
.zip(&rows[1])
|
||||||
.zip(&x[1])
|
.zip(&rows[2])
|
||||||
.zip(&x[2])
|
|
||||||
.map(|((x, y), z)| [x, y, z])
|
.map(|((x, y), z)| [x, y, z])
|
||||||
})
|
})
|
||||||
.filter(|x| is_triangle(*x[0], *x[1], *x[2]))
|
.filter(|x| is_triangle(*x[0], *x[1], *x[2]))
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
println!("count={}", count_h);
|
println!("count_h={}", count_h);
|
||||||
println!("count={}", count_v);
|
println!("count_v={}", count_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_triangle(a: i32, b: i32, c: i32) -> bool {
|
pub fn is_triangle(a: i32, b: i32, c: i32) -> bool {
|
||||||
a + b > c && b + c > a && c + a > b
|
a + b > c && b + c > a && c + a > b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::is_triangle;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn example_01() {
|
fn example_01() {
|
||||||
|
|||||||
Reference in New Issue
Block a user