My solutions and approaches for the Advent of Code 2023 in C++
Related Topics: String, Two Pointers
Test input:
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
- Loop throughe all the lines
- For each line use a left pointer to find the first digit and a right pointer to find the last digit
- Create an array containing all the numbers as strings
- Loop throughe all the lines
- For the left pointer check if you can find any of the number string from (0, L), if not check if L is a number. Do the same for the right pointer just from the end of the string
Related Topics: String
Test input:
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
- Loop throughe all the lines
- Parse the line into sections for each turn of the game
- Check if the amounts of all the colors are valid
- Loop throughe all the lines
- Parse the line into sections for each turn of the game
- Check if the used colors in this turn are bigger then before and if so set the new max values
Problem description Related Topics: String
Test input:
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..
- Find all the special characters and save their positions
- Loop troughe all the found characters
- Look for numbers around the character
- When a number is found check how long it is by moving to the left until you reach its end
- Save the start position to a set of numbers
- Loop troughe the the saved numbers and sum them up
- Find all the gears (*)
- Loop troughe all the found gears
- Look for numbers around the character
- When a number is found check how long it is by moving to the left until you reach its end
- Save the start position to a set of numbers
- If the set size is equal to 2, multiply the numbers and add to the total sum
Problem description Related Topics: String, Set
Test input:
seeds: 79 14 55 13
seed-to-soil map:
50 98 2
52 50 48
soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15
fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4
water-to-light map:
88 18 7
18 25 70
light-to-temperature map:
45 77 23
81 45 19
68 64 13
temperature-to-humidity map:
0 69 1
1 0 69
humidity-to-location map:
60 56 37
56 93 4```