use std::io;
use std::io::BufRead;

const DEBUG: bool = true;

struct Card {
    card_number: u32,
    match_count: u32,
    copies: u32,
}

fn main() {
    let mut lines_processed = 0;
    let mut cards: Vec<Card> = Vec::new();


    let mut line = String::new();
    while io::stdin().lock().read_line(&mut line).unwrap() > 0 {
        println!("input {}", line.trim());
        let card_strings = line.trim().split_once(':').unwrap();
        //dbg!(card_strings);
        let card_number = card_strings.0[5..].trim().parse::<u32>().unwrap();
        let card_data_string = card_strings.1.trim().split_once('|').unwrap();

        let winning_numbers: Vec<u32> = card_data_string.0
                                            .split_whitespace()
                                            .map(|s| s.parse().unwrap())
                                            .collect();
        let my_numbers: Vec<u32> = card_data_string.1
                                                   .split_whitespace()
                                                   .map(|s| s.parse().unwrap())
                                                   .collect();

        //dbg!(my_numbers.iter().filter(|x| winning_numbers.contains(x)).cloned().collect::<Vec<u32>>());                                                   
        let match_count: u32 = my_numbers.iter().filter(|x| winning_numbers.contains(x)).count().try_into().unwrap();

        println!("------------ card_number: {}, match_count: {}\n", card_number, match_count);

        cards.push(Card {
            card_number: card_number,
            match_count: match_count,
            copies: 1,
        });

        for card in cards.iter() {
            println!("CARD card: {}, match count: {}", card.card_number, card.match_count);
        }


        //dbg!(winning_numbers, my_numbers, match_count);
        //.map(|x| x.parse).unwrap())
        //.collect()

        // dbg!( card_data_string.0
        //                       .trim()
        //                       .split_whitespace()
        //                       //.split(' ').map(|s| s.trim())
        //                       .filter(|s| !s.is_empty())
        //                       .map(|s| s.parse().unwrap())
        //                       .collect()
        //                       //.map(|x| x.parse).unwrap())
        //                       //.collect()
        //                      );
        //let winning_numbers: Vec<u32> = card_data_string.0.trim().split_whitespace().iter().flat_map(|s| s.parse().ok()).collect();
        let my_numbers = card_data_string.1.trim();

        dbg!(card_number);
        //dbg!(winning_numbers, my_numbers);
        lines_processed += 1;
        line.clear()
    }

    println!("\n Ingested {} Lines", lines_processed);
    println!("===================================");

    // Insert processing code

    println!("\n Processed XXX");
    println!("===================================");

    println!("Answer: \nXXXX");
}
