Compare commits

..

No commits in common. "5fe3d1caa86e76e31217360d176067ba60f2224e" and "2c88cb8fe8a02d726f2e5a447d072d2e7a0c8827" have entirely different histories.

12 changed files with 211 additions and 452 deletions

View file

@ -1,17 +1,15 @@
# See https://pre-commit.com for more information # See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks # See https://pre-commit.com/hooks.html for more hooks
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 rev: v4.5.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
- id: check-yaml - id: check-yaml
- id: check-added-large-files - id: check-added-large-files
- repo: https://git.xenia.me.uk/utils/pre-commit-rust - repo: https://github.com/doublify/pre-commit-rust
rev: v1.2 rev: v1.0
hooks: hooks:
- id: fmt - id: fmt
- id: cargo-check - id: cargo-check
- id: cargo-clippy
- id: cargo-test

View file

@ -1,24 +0,0 @@
--- Day 1: Trebuchet?! ---
Something is wrong with global snow production, and you've been selected to take a look. The Elves have even given you a map; on it, they've used stars to mark the top fifty locations that are likely to be having problems.
You've been doing this long enough to know that to restore snow operations, you need to check all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
You try to ask why they can't just use a weather machine ("not powerful enough") and where they're even sending you ("the sky") and why your map looks mostly blank ("you sure ask a lot of questions") and hang on did you just say the sky ("of course, where do you think snow comes from") when you realize that the Elves are already loading you into a trebuchet ("please hold still, we need to strap you in").
As they're making the final adjustments, they discover that their calibration document (your puzzle input) has been amended by a very young Elf who was apparently just excited to show off her art skills. Consequently, the Elves are having trouble reading the values on the document.
The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
For example:
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.
Consider your entire calibration document. What is the sum of all of the calibration values?

View file

@ -1,17 +0,0 @@
--- Part Two ---
Your calculation isn't quite right. It looks like some of the digits are actually spelled out with letters: one, two, three, four, five, six, seven, eight, and nine also count as valid "digits".
Equipped with this new information, you now need to find the real first and last digit on each line. For example:
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
In this example, the calibration values are 29, 83, 13, 24, 42, 14, and 76. Adding these together produces 281.
What is the sum of all of the calibration values?

View file

@ -1,27 +0,0 @@
--- Day 2: Cube Conundrum ---
You're launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island floating in the sky. You gently land in a fluffy pile of leaves. It's quite cold, but you don't see much snow. An Elf runs over to greet you.
The Elf explains that you've arrived at Snow Island and apologizes for the lack of snow. He'll be happy to explain the situation, but it's a bit of a walk, so you have some time. They don't get many visitors up here; would you like to play a game in the meantime?
As you walk, the Elf shows you a small bag and some cubes which are either red, green, or blue. Each time you play this game, he will hide a secret number of cubes of each color in the bag, and your goal is to figure out information about the number of cubes.
To get information, once a bag has been loaded with cubes, the Elf will reach into the bag, grab a handful of random cubes, show them to you, and then put them back in the bag. He'll do this a few times per game.
You play several games and record the information from each game (your puzzle input). Each game is listed with its ID number (like the 11 in Game 11: ...) followed by a semicolon-separated list of subsets of cubes that were revealed from the bag (like 3 red, 5 green, 4 blue).
For example, the record of a few games might look like this:
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
In game 1, three sets of cubes are revealed from the bag (and then put back again). The first set is 3 blue cubes and 4 red cubes; the second set is 1 red cube, 2 green cubes, and 6 blue cubes; the third set is only 2 green cubes.
The Elf would first like to know which games would have been possible if the bag contained only 12 red cubes, 13 green cubes, and 14 blue cubes?
In the example above, games 1, 2, and 5 would have been possible if the bag had been loaded with that configuration. However, game 3 would have been impossible because at one point the Elf showed you 20 red cubes at once; similarly, game 4 would also have been impossible because the Elf showed you 15 blue cubes at once. If you add up the IDs of the games that would have been possible, you get 8.
Determine which games would have been possible if the bag had been loaded with only 12 red cubes, 13 green cubes, and 14 blue cubes. What is the sum of the IDs of those games?

View file

@ -1,7 +1,6 @@
mod part1; mod part1;
mod part2;
fn main() { fn main() {
println!("Part1: {}", part1::main(include_str!("input.txt"))); println!("Part1: {}", part1::main(include_str!("input.txt")));
println!("Part2: {}", part2::main(include_str!("input.txt"))); println!("Part2: TODO");
} }

View file

@ -1,156 +0,0 @@
use regex::{Match, Regex};
pub struct Games {
games: Vec<Game>,
}
impl Games {
fn new(input: &str, bag: Contents) -> Self {
Self {
games: input
.lines()
.map(|m| Game::new(m.to_owned(), bag.clone()))
.collect(),
}
}
fn valid_games(&self) -> Vec<i32> {
self.games
.iter()
.filter(|m| m.valid())
.map(|m| m.id)
.collect()
}
fn valid_sum(&self) -> i32 {
self.valid_games().iter().sum()
}
}
#[derive(Debug, Clone)]
pub struct Game {
bag: Contents,
id: i32,
draws: Vec<Contents>,
}
impl Game {
fn new(line: String, bag: Contents) -> Self {
Self {
bag: bag.clone(),
id: line
.split(':')
.next()
.unwrap()
.split(' ')
.last()
.expect("Must have game ID")
.parse::<i32>()
.expect("Game ID must be integer value"),
draws: Game::get_draws(line.split(':').last().unwrap()),
}
}
fn get_draws(line: &str) -> Vec<Contents> {
line.split(':')
.next()
.unwrap()
.split(';')
.map(|m| -> Contents { Contents::new(m) })
.collect()
}
fn valid(&self) -> bool {
self.draws.iter().all(|m| self.bag.valid(m))
}
}
#[derive(Debug, Clone)]
pub struct Contents {
blue: i32,
green: i32,
red: i32,
}
impl Contents {
fn new(line: &str) -> Self {
Self {
red: Self::get_red(line),
blue: Self::get_blue(line),
green: Self::get_green(line),
}
}
fn valid(self: &Contents, hand: &Contents) -> bool {
self.red.ge(&hand.red) & self.blue.ge(&hand.blue) & self.green.ge(&hand.green)
}
fn get_value(slice: &str) -> i32 {
Regex::new(r"(\d)+")
.unwrap()
.find(slice)
.unwrap()
.as_str()
.parse()
.unwrap()
}
fn get_slice<'a>(line: &'a str, rstring: &'a str) -> Option<Match<'a>> {
Regex::new(rstring).unwrap().find(line)
}
fn get_red(line: &str) -> i32 {
let rstring = r"((\d)+ red)";
match Self::get_slice(line, rstring) {
Some(slice) => Self::get_value(slice.as_str()),
None => 0,
}
}
fn get_blue(line: &str) -> i32 {
let rstring = r"((\d)+ blue)";
match Self::get_slice(line, rstring) {
Some(slice) => Self::get_value(slice.as_str()),
None => 0,
}
}
fn get_green(line: &str) -> i32 {
let rstring = r"((\d)+ green)";
match Self::get_slice(line, rstring) {
Some(slice) => Self::get_value(slice.as_str()),
None => 0,
}
}
}
pub fn main(input: &str) -> i32 {
let bag = Contents {
red: 12,
green: 13,
blue: 14,
};
let games = Games::new(input, bag);
games.valid_sum()
}
#[cfg(test)]
mod tests {
use super::*;
const BAG: Contents = Contents {
red: 12,
green: 13,
blue: 14,
};
const INPUT: &str = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
#[test]
fn example() {
assert_eq!(main(INPUT), 8)
}
#[test]
fn by_line() {
assert_eq!(Games::new(INPUT, BAG).valid_games(), vec![1, 2, 5])
}
#[test]
fn solution() {
assert_eq!(main(include_str!("input.txt")), 2476)
}
}

View file

@ -1,78 +1,128 @@
use regex::Regex; use regex::{Match, Regex};
type Games = Vec<Game>; pub fn main(input: &str) -> i32 {
let bag = Contents {
#[derive(Debug)]
pub struct Bag {
pub red: usize,
pub green: usize,
pub blue: usize,
}
#[derive(Debug)]
pub struct Game {
pub id: usize,
pub rounds: Vec<Round>,
}
impl Game {
pub fn new(input: &str) -> Self {
let (id, games) = input
.split_once(':')
.expect("All input lines follow this format");
Self {
id: id.split(' ').last().unwrap().parse().unwrap(),
rounds: games.split(';').map(Round::new).collect(),
}
}
pub fn is_valid(&self, bag: &Bag) -> bool {
self.rounds.iter().all(|m| m.is_valid(bag))
}
}
#[derive(Debug)]
pub struct Round {
pub red: usize,
pub green: usize,
pub blue: usize,
}
impl Round {
pub fn new(input: &str) -> Self {
fn get_colour(rstring: &str, input: &str) -> usize {
match Regex::new(rstring).unwrap().find(input) {
Some(val) => val.as_str().split(' ').next().unwrap().parse().unwrap(),
None => 0,
}
}
Self {
red: get_colour(r"\d+ (red)", input),
green: get_colour(r"\d+ (green)", input),
blue: get_colour(r"\d+ (blue)", input),
}
}
pub fn is_valid(&self, bag: &Bag) -> bool {
self.red <= bag.red && self.green <= bag.green && self.blue <= bag.blue
}
}
pub fn games(input: &str) -> Games {
input.lines().map(Game::new).collect()
}
pub fn main(input: &str) -> usize {
let bag = Bag {
red: 12, red: 12,
green: 13, green: 13,
blue: 14, blue: 14,
}; };
games(input) let games = Games::new(input, bag);
.iter() games.valid_sum()
.filter_map(|m| if m.is_valid(&bag) { Some(m.id) } else { None }) }
.sum()
struct Games {
games: Vec<Game>,
}
impl Games {
fn new(input: &str, bag: Contents) -> Self {
Self {
games: input
.lines()
.map(|m| Game::new(m.to_owned(), bag.clone()))
.collect(),
}
}
fn valid_games(self) -> Vec<i32> {
self.games
.iter()
.filter(|m| m.valid())
.map(|m| m.id)
.collect()
}
fn valid_sum(self) -> i32 {
self.valid_games().iter().sum()
}
}
#[derive(Debug, Clone)]
struct Game {
bag: Contents,
id: i32,
draws: Vec<Contents>,
}
impl Game {
fn new(line: String, bag: Contents) -> Self {
Self {
bag: bag.clone(),
id: line
.split(':')
.next()
.unwrap()
.split(' ')
.last()
.expect("Must have game ID")
.parse::<i32>()
.expect("Game ID must be integer value"),
draws: Game::get_draws(line.split(':').last().unwrap()),
}
}
fn get_draws(line: &str) -> Vec<Contents> {
line.split(':')
.next()
.unwrap()
.split(';')
.map(|m| -> Contents { Contents::new(m) })
.collect()
}
fn valid(&self) -> bool {
self.draws.iter().all(|m| self.bag.valid(m))
}
}
#[derive(Debug, Clone)]
struct Contents {
blue: i32,
green: i32,
red: i32,
}
impl Contents {
fn new(line: &str) -> Self {
Self {
red: Self::get_red(line),
blue: Self::get_blue(line),
green: Self::get_green(line),
}
}
fn valid(self: &Contents, hand: &Contents) -> bool {
self.red.gt(&hand.red) & self.blue.gt(&hand.blue) & self.green.gt(&hand.green)
}
fn get_value(slice: &str) -> i32 {
Regex::new(r"(\d)+")
.unwrap()
.find(slice)
.unwrap()
.as_str()
.parse()
.unwrap()
}
fn get_slice<'a>(line: &'a str, rstring: &'a str) -> Option<Match<'a>> {
Regex::new(rstring).unwrap().find(line)
}
fn get_red(line: &str) -> i32 {
let rstring = r"((\d)+ red)";
match Self::get_slice(line, rstring) {
Some(slice) => Self::get_value(slice.as_str()),
None => 0,
}
}
fn get_blue(line: &str) -> i32 {
let rstring = r"((\d)+ blue)";
match Self::get_slice(line, rstring) {
Some(slice) => Self::get_value(slice.as_str()),
None => 0,
}
}
fn get_green(line: &str) -> i32 {
let rstring = r"((\d)+ green)";
match Self::get_slice(line, rstring) {
Some(slice) => Self::get_value(slice.as_str()),
None => 0,
}
}
} }
#[cfg(test)] #[cfg(test)]
@ -88,9 +138,4 @@ Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"; Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
assert_eq!(main(input), 8); assert_eq!(main(input), 8);
} }
#[test]
fn solution() {
assert_eq!(main(include_str!("input.txt")), 2476)
}
} }

61
day2/src/part1_new.rs Normal file
View file

@ -0,0 +1,61 @@
use std::fs;
use regex::Regex;
pub(crate) fn main() {
let input = String::from("inputs/2023/day2_1.txt");
println!(
"{:?}",
Game::from(fs::read_to_string(input).unwrap().lines().next())
)
}
#[derive(Debug)]
struct Game {
id: u32,
draws: Vec<Draw>,
}
impl TryFrom<&str> for Game {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
let re = Regex::new(r"^Game [\d]+: ([\d]+ (red|blue|green){1}(;)?)+$").unwrap();
println!("{:?}", re.captures(value).unwrap());
Ok(Self {
id: 1,
draws: vec![Draw {
red: 1,
green: 1,
blue: 1,
}],
})
}
}
#[derive(Debug)]
struct Draw {
red: i32,
green: i32,
blue: i32,
}
impl TryFrom<&str> for Draw {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
todo!()
}
}
impl Draw {
fn is_valid(&self, bag: &Bag) -> bool {
self.red < bag.red && self.green < bag.green && self.blue < bag.blue
}
}
struct Bag {
red: i32,
green: i32,
blue: i32,
}

View file

@ -1,53 +0,0 @@
use crate::part1::{games, Bag, Game};
impl Game {
pub fn min_bag(&self) -> Bag {
Bag {
red: self.rounds.iter().map(|m| m.red).max().unwrap(),
green: self.rounds.iter().map(|m| m.green).max().unwrap(),
blue: self.rounds.iter().map(|m| m.blue).max().unwrap(),
}
}
pub fn product(&self) -> usize {
let bag = self.min_bag();
bag.red * bag.green * bag.blue
}
}
pub fn products(input: &str) -> Vec<usize> {
games(input)
.iter()
.map(Game::product)
.collect::<Vec<usize>>()
}
pub fn main(input: &str) -> usize {
products(input).iter().sum()
}
#[cfg(test)]
mod tests {
use super::*;
const INPUT: &str = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
#[test]
fn example() {
assert_eq!(main(INPUT), 2286);
}
#[test]
fn by_line() {
assert_eq!(products(INPUT), vec![48, 12, 1560, 630, 36])
}
#[test]
fn solution() {
assert_eq!(main(include_str!("input.txt")), 54911)
}
}

View file

@ -1,30 +0,0 @@
--- Day 3: Gear Ratios ---
You and the Elf eventually reach a gondola lift station; he says the gondola lift will take you up to the water source, but this is as far as he can bring you. You go inside.
It doesn't take long to find the gondolas, but there seems to be a problem: they're not moving.
"Aaah!"
You turn around to see a slightly-greasy Elf with a wrench and a look of surprise. "Sorry, I wasn't expecting anyone! The gondola lift isn't working right now; it'll still be a while before I can fix it." You offer to help.
The engineer explains that an engine part seems to be missing from the engine, but nobody can figure out which one. If you can add up all the part numbers in the engine schematic, it should be easy to work out which part is missing.
The engine schematic (your puzzle input) consists of a visual representation of the engine. There are lots of numbers and symbols you don't really understand, but apparently any number adjacent to a symbol, even diagonally, is a "part number" and should be included in your sum. (Periods (.) do not count as a symbol.)
Here is an example engine schematic:
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..
In this schematic, two numbers are not part numbers because they are not adjacent to a symbol: 114 (top right) and 58 (middle right). Every other number is adjacent to a symbol and so is a part number; their sum is 4361.
Of course, the actual engine schematic is much larger. What is the sum of all of the part numbers in the engine schematic?

View file

@ -2,7 +2,7 @@ use regex::{Match, Regex};
use std::{fmt::Display, num::ParseIntError}; use std::{fmt::Display, num::ParseIntError};
#[derive(Debug)] #[derive(Debug)]
pub struct Symbol { struct Symbol {
value: char, value: char,
row: usize, row: usize,
col: usize, col: usize,
@ -15,7 +15,7 @@ impl Display for Symbol {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Number { struct Number {
value: u32, value: u32,
row: usize, row: usize,
start: usize, start: usize,
@ -36,7 +36,7 @@ impl Display for Number {
} }
impl Number { impl Number {
pub fn is_valid(&self, symbols: &[Symbol]) -> bool { fn valid(&self, symbols: &[Symbol]) -> bool {
let adjacent: Vec<usize> = symbols let adjacent: Vec<usize> = symbols
.iter() .iter()
.filter_map(|m| { .filter_map(|m| {
@ -68,7 +68,7 @@ impl TryFrom<Match<'_>> for Number {
} }
} }
pub fn get_symbols(input: &str) -> Vec<Symbol> { fn get_symbols(input: &str) -> Vec<Symbol> {
let mut items: Vec<Symbol> = Vec::new(); let mut items: Vec<Symbol> = Vec::new();
for (row, line) in input.lines().enumerate() { for (row, line) in input.lines().enumerate() {
for (col, value) in line.chars().enumerate() { for (col, value) in line.chars().enumerate() {
@ -80,38 +80,40 @@ pub fn get_symbols(input: &str) -> Vec<Symbol> {
items items
} }
pub fn get_numbers(input: &str, predicate: Option<&dyn Fn(&Number) -> bool>) -> Vec<Number> { fn get_numbers(input: &str) -> Vec<Number> {
let rstring = r"(\d)+"; let rstring = r"(\d)+";
let mut items: Vec<Number> = Vec::new(); let mut items: Vec<Number> = Vec::new();
for (row, line) in input.lines().enumerate() { for (row, line) in input.lines().enumerate() {
for item in Regex::new(rstring).unwrap().find_iter(line) { for item in Regex::new(rstring).unwrap().find_iter(line) {
let mut number = Number::try_from(item).unwrap(); let mut number = Number::try_from(item).unwrap();
number.row = row; number.row = row;
if predicate.unwrap_or(&|_| true)(&number) { items.push(number);
items.push(number);
};
} }
} }
items items
} }
pub fn get_valid_numbers(input: &str, symbols: &[Symbol]) -> Vec<u32> {
get_numbers(input, Some(&|number| number.is_valid(symbols)))
.iter()
.map(|m| m.value)
.collect()
}
pub fn main(input: &str) -> u32 { pub fn main(input: &str) -> u32 {
let symbols = get_symbols(input); let symbols = get_symbols(input);
get_valid_numbers(input, &symbols).iter().sum() get_numbers(input)
.iter()
.filter_map(|m| {
if m.valid(&symbols) {
Some(m.value)
} else {
None
}
})
.sum()
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
const INPUT: &str = "467..114.. #[test]
fn example() {
let input = "467..114..
...*...... ...*......
..35..633. ..35..633.
......#... ......#...
@ -121,9 +123,6 @@ mod tests {
......755. ......755.
...$.*.... ...$.*....
.664.598.."; .664.598..";
assert_eq!(main(input), 4361);
#[test]
fn example() {
assert_eq!(main(INPUT), 4361);
} }
} }

View file

@ -1,36 +0,0 @@
--- Day 4: Scratchcards ---
The gondola takes you up. Strangely, though, the ground doesn't seem to be coming with you; you're not climbing a mountain. As the circle of Snow Island recedes below you, an entire new landmass suddenly appears above you! The gondola carries you to the surface of the new island and lurches into the station.
As you exit the gondola, the first thing you notice is that the air here is much warmer than it was on Snow Island. It's also quite humid. Is this where the water source is?
The next thing you notice is an Elf sitting on the floor across the station in what seems to be a pile of colorful square cards.
"Oh! Hello!" The Elf excitedly runs over to you. "How may I be of service?" You ask about water sources.
"I'm not sure; I just operate the gondola lift. That does sound like something we'd have, though - this is Island Island, after all! I bet the gardener would know. He's on a different island, though - er, the small kind surrounded by water, not the floating kind. We really need to come up with a better naming scheme. Tell you what: if you can help me with something quick, I'll let you borrow my boat and you can go visit the gardener. I got all these scratchcards as a gift, but I can't figure out what I've won."
The Elf leads you over to the pile of colorful cards. There, you discover dozens of scratchcards, all with their opaque covering already scratched off. Picking one up, it looks like each card has two lists of numbers separated by a vertical bar (|): a list of winning numbers and then a list of numbers you have. You organize the information into a table (your puzzle input).
As far as the Elf has been able to figure out, you have to figure out which of the numbers you have appear in the list of winning numbers. The first match makes the card worth one point and each match after the first doubles the point value of that card.
For example:
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
In the above example, card 1 has five winning numbers (41, 48, 83, 86, and 17) and eight numbers you have (83, 86, 6, 31, 17, 9, 48, and 53). Of the numbers you have, four of them (48, 83, 17, and 86) are winning numbers! That means card 1 is worth 8 points (1 for the first match, then doubled three times for each of the three matches after the first).
Card 2 has two winning numbers (32 and 61), so it is worth 2 points.
Card 3 has two winning numbers (1 and 21), so it is worth 2 points.
Card 4 has one winning number (84), so it is worth 1 point.
Card 5 has no winning numbers, so it is worth no points.
Card 6 has no winning numbers, so it is worth no points.
So, in this example, the Elf's pile of scratchcards is worth 13 points.
Take a seat in the large pile of colorful cards. How many points are they worth in total?