Currently working on Datasette and associated projects. Read my blog or follow @[email protected]
on Mastodon.
simonw / advent-of-code-2022-in-rust Goto Github PK
View Code? Open in Web Editor NEWCopilot-assisted Advent of Code 2022 to learn Rust
Copilot-assisted Advent of Code 2022 to learn Rust
Currently working on Datasette and associated projects. Read my blog or follow @[email protected]
on Mastodon.
To fix the communication system, you need to add a subroutine to the device that detects a start-of-packet marker in the datastream. In the protocol being used by the Elves, the start of a packet is indicated by a sequence of four characters that are all different.
The device will send your subroutine a datastream buffer (your puzzle input); your subroutine needs to identify the first position where the four most recently received characters were all different. Specifically, it needs to report the number of characters from the beginning of the buffer to the end of the first such four-character marker.
Example: bvwbjplbgvbhsrlpgdmjqwftvncz
- first marker after character 5
https://adventofcode.com/2022/day/5
Wow this one is a whole lot more interesting! Need to parse this:
[V] [C] [M]
[V] [J] [N] [H] [V]
[R] [F] [N] [W] [Z] [N]
[H] [R] [D] [Q] [M] [L] [B]
[B] [C] [H] [V] [R] [C] [G] [R]
[G] [G] [F] [S] [D] [H] [B] [R] [S]
[D] [N] [S] [D] [H] [G] [J] [J] [G]
[W] [J] [L] [J] [S] [P] [F] [S] [L]
1 2 3 4 5 6 7 8 9
move 2 from 2 to 7
move 8 from 5 to 6
move 2 from 4 to 5
move 1 from 4 to 5
"Move 2 from 2 to 7" means take the top item from stack to - here F - and move it to stack 7, then do that again so N gets moved to. Afterwards stack 7 will have N at the top and F directly below it.
https://adventofcode.com/2022/day/2
Puzzle input: https://adventofcode.com/2022/day/2/input
e.g.
B Y
A Z
A Z
C Z
B Y
The first column is what your opponent is going to play: A for Rock, B for Paper, and C for Scissors [...]
The second column, you reason, must be what you should play in response: X for Rock, Y for Paper, and Z for Scissors
The score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors) plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won).
https://adventofcode.com/2022/day/4
Example:
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8
Diagram:
....567.. 5-7
......789 7-9
.2345678. 2-8
..34567.. 3-7
.....6... 6-6
...456... 4-6
.23456... 2-6
...45678. 4-8
In how many pairs does one group entirely overlap the other?
https://adventofcode.com/2022/day/13
This one looks like a good opportunity to learn how to write unit tests in Rust.
https://adventofcode.com/2022/day/3
The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same number of items in each of its two compartments, so the first half of the characters represent items in the first compartment, while the second half of the characters represent items in the second compartment.
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
Need to look for common types - items in both the front and back half.
- Lowercase item types a through z have priorities 1 through 26.
- Uppercase item types A through Z have priorities 27 through 52.
Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item types?
Would be great to have GitHub Actions run tests against all of my code on every commit.
Not sure how to do this in Rust though. Might need be to use Cargo?
https://adventofcode.com/2022/day/8
First, determine whether there is enough tree cover here to keep a tree house hidden. To do this, you need to count the number of trees that are visible from outside the grid when looking directly along a row or column.
30373
25512
65332
33549
35390
Each number is the height of a tree.
A tree is visible if all of the other trees between it and an edge of the grid are shorter than it. Only consider trees in the same row or column; that is, only look up, down, left, or right from any given tree.
Trees on the edges are always visible.
how many trees are visible from outside the grid?
https://adventofcode.com/2022/day/9
Wow this one is a bit complicated. I'm modelling a rope with a head and tail. The head moves around - the tail follows.
Moves example:
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2
H
is rope head, T
is rope tail, s
is the starting position:
== Initial State ==
......
......
......
......
H..... (H covers T, s)
== R 4 ==
......
......
......
......
TH.... (T covers s)
......
......
......
......
sTH...
......
......
......
......
s.TH..
......
......
......
......
s..TH.
== U 4 ==
......
......
......
....H.
s..T..
......
......
....H.
....T.
s.....
......
....H.
....T.
......
s.....
....H.
....T.
......
......
s.....
== L 3 ==
...H..
....T.
......
......
s.....
..HT..
......
......
......
s.....
.HT...
......
......
......
s.....
etc.
How many positions does the tail of the rope visit at least once?
For the example the answer is 13.
https://adventofcode.com/2022/day/7
Puzzle input looks like this:
$ ls
dir a
14848514 b.txt
8504156 c.dat
dir d
$ cd a
$ ls
dir e
29116 f
2557 g
62596 h.lst
$ cd e
$ ls
584 i
$ cd ..
$ cd ..
$ cd d
$ ls
4060174 j
8033020 d.log
5626152 d.ext
7214296 k
determine the total size of each directory. The total size of a directory is the sum of the sizes of the files it contains, directly or indirectly
[...]
Find all of the directories with a total size of at most 100000. What is the sum of the total sizes of those directories?
Answer for above example is 95437
https://adventofcode.com/2022/day/10
Partial example:
addx 15
addx -11
addx 6
addx -3
addx 5
addx -1
addx -8
addx 13
addx 4
noop
addx -1
addx 5
addx -1
The CPU has a single register, X, which starts with the value 1. It supports only two instructions:
addx V
takes two cycles to complete. After two cycles, the X register is increased by the value V. (V can be negative.)
noop
takes one cycle to complete. It has no other effect.[...]
Find the signal strength during the 20th, 60th, 100th, 140th, 180th, and 220th cycles. What is the sum of these six signal strengths?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.