TNWJK3WAU2ZIYSY4MWMXWUMCDVVVJKDLJD35QN6VZOTHU5UGUDOQC
IWN7EOTTMWUU5PNPMXDVZFKIVOUFFE47ELSC2YRBLCQHUZBV3EJQC
HUHAFQLN6Q6U7CPR2SPPEPLE5LMCR53UA2GJ7LUVSHFXQPCGIYAQC
#[derive(Clone,Copy)]
#[derive(Clone, Copy)]
Down
Down,
Distance(std::num::ParseIntError)
Distance(std::num::ParseIntError),
_ => Err(InstructionParseError::Direction)
_ => Err(InstructionParseError::Direction),
let distance: i64 = words.next().unwrap_or_else(|| "") .parse()?; Ok(Self { direction, distance })
let distance: i64 = words.next().unwrap_or_else(|| "")
.parse()?;
Ok(Self { direction, distance })
let distance: i64 = words.next().unwrap_or("").parse()?; Ok(Self { direction, distance, })
let distance: i64 = words.next().unwrap_or("").parse()?;
Ok(Self {
direction,
distance,
})
fn trace_1<I: Iterator<Item=Instruction>>(source: I) -> (i64,i64) {
fn trace_1<I: Iterator<Item = Instruction>>(source: I) -> (i64, i64) {
Direction::Forward => { x += i.distance; } Direction::Up => { y -= i.distance; } Direction::Down => { y += i.distance; }
Direction::Forward => { x += i.distance; }
Direction::Up => { y -= i.distance; }
Direction::Down => { y += i.distance; }
Direction::Forward => {
x += i.distance;
}
Direction::Up => {
y -= i.distance;
Direction::Down => {
y += i.distance;
}; (x,y)
};
(x,y)
} (x, y)
(x, y)
fn trace_2<I: Iterator<Item=Instruction>>(source: I) -> (i64,i64) {
fn trace_2<I: Iterator<Item = Instruction>>(source: I) -> (i64, i64) {
Direction::Up => { aim -= i.distance; } Direction::Down => { aim += i.distance; }
Direction::Up => { aim -= i.distance; }
Direction::Down => { aim += i.distance; }
aim -= i.distance;
aim += i.distance;
let file = std::io::BufReader::new(std::fs::File::open(<String as AsRef<std::path::Path>>::as_ref(&args[1])).unwrap());
let file = std::io::BufReader::new( std::fs::File::open(<String as AsRef<std::path::Path>>::as_ref(&args[1])).unwrap(), );
let file = std::io::BufReader::new(
std::fs::File::open(<String as AsRef<std::path::Path>>::as_ref(&args[1])).unwrap(),
);
.flat_map(|line| line.ok().and_then(|line| str::parse::<Instruction>(line.as_ref()).ok()))
.flat_map(|line| { line.ok() .and_then(|line| str::parse::<Instruction>(line.as_ref()).ok()) })
.flat_map(|line| {
line.ok()
.and_then(|line| str::parse::<Instruction>(line.as_ref()).ok())
let (x1, y1) = trace_1(instructions.iter().map(|x| *x));
let (x1, y1) = trace_1(instructions.iter().copied());
let (x2, y2) = trace_2(instructions.iter().map(|x| *x)); println!("");
let (x2, y2) = trace_2(instructions.iter().map(|x| *x));
println!("");
let (x2, y2) = trace_2(instructions.iter().copied()); println!();
let (x2, y2) = trace_2(instructions.iter().copied());
println!();
inner: inner,
inner,
inner: inner, size: size,
size: size,
inner, size,
size,
let result = self.window.iter().map(|x| *x).collect();
let result = self.window.iter().copied().collect();
[[bin]]name = "day3"path = "day3.rs"
[[bin]]
name = "day3"
path = "day3.rs"