blob: 447862abf62a524cbd62ece206e6d4a7d89b5347 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
use std::fs::File;
use std::io::{BufRead,BufReader};
fn main() {
let f = File::open("day10").unwrap();
let v: Vec<(i32,i32,i32,i32)> = BufReader::new(&f).lines()
.map(|l| {
let l = l.unwrap();
(l[10..16].trim().parse().unwrap(),
l[18..24].trim().parse().unwrap(),
l[36..38].trim().parse().unwrap(),
l[40..42].trim().parse().unwrap())
}).collect();
let p2 = (0..20000).min_by_key(|i| {
let a = v.iter().map(|l| l.0 + i*l.2).max().unwrap();
let b = v.iter().map(|l| l.0 + i*l.2).min().unwrap();
(a - b)
}).unwrap();
let mut m = [[' '; 30]; 80];
for l in v {
m[(l.0 + p2*l.2 - 100) as usize][(l.1 + p2*l.3 - 180) as usize] = '#';
}
for x in 0..30 {
for y in 0..80 {
print!("{}", m[y][x]);
}
println!("");
}
println!("{}", p2);
}
|