I don't like learning Rust, continue in c++ for now -- advent_of_code
This commit is contained in:
@@ -3,6 +3,8 @@ use std::path::Path;
|
||||
use std::fs::File;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use text_io::scan;
|
||||
|
||||
|
||||
// -- PART 1 --
|
||||
|
||||
@@ -12,6 +14,7 @@ use std::collections::HashMap;
|
||||
// Goal is to find the bingo card that has bingo first and calculate some metrics of it
|
||||
// Metrics are the last called number multiplied by sum of all numbers that were not needed for bingo
|
||||
|
||||
#[derive(Debug,PartialEq)]
|
||||
struct Card {
|
||||
numbers : HashMap<u64, (usize, usize)>,
|
||||
opens : [[bool; 5]; 5],
|
||||
@@ -78,8 +81,8 @@ fn main(){
|
||||
Ok(file) => file,
|
||||
};
|
||||
|
||||
let lines = io::BufReader::new(file).lines();
|
||||
let mut numbers = Vec::<u8>::new();
|
||||
let mut lines = io::BufReader::new(file).lines();
|
||||
let mut numbers = Vec::<u32>::new();
|
||||
let mut bingo_cards = Vec::<Card>::new();
|
||||
|
||||
// let mut c = Card::new();
|
||||
@@ -95,4 +98,36 @@ fn main(){
|
||||
// assert_eq!(c.call(4), None);
|
||||
// assert_eq!(c.call(5), Some(0));
|
||||
|
||||
let first_line = lines.nth(0).unwrap().unwrap();
|
||||
let mut acc: u32 = 0;
|
||||
for c in first_line.chars() {
|
||||
if c != ',' && c != '\n' {
|
||||
acc *= 10;
|
||||
acc += c.to_digit(10).unwrap();
|
||||
} else{
|
||||
numbers.push(acc);
|
||||
acc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
let mut n_start = 2;
|
||||
let mut bingo_start_line = lines.nth(n_start);
|
||||
|
||||
while !bingo_start_line.is_none() {
|
||||
let card = Card::new();
|
||||
|
||||
for i in 0..5 {
|
||||
let cur_line = lines.nth(n_start + i).unwrap().unwrap();
|
||||
let a: i32;
|
||||
let b: i32;
|
||||
let c: i32;
|
||||
let d: i32;
|
||||
let e: i32;
|
||||
scan!(cur_line.bytes() => "{} {} {} {} {}", a, b, c, d, e);
|
||||
println!("{} {} {} {} {}", a, b, c, d, e);
|
||||
}
|
||||
|
||||
n_start += 6;
|
||||
bingo_start_line = lines.nth(n_start);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user