# Advent of Code 2022

## Day 4

It is a bit late, but here is my atempt for day 4.

### Part 1

## Spoiler: sollution

450837

## Day 5

... and day 5, this time with some visuals

### Part 1 & 2

## Spoiler: sollution

Using version CrateMover 9000

Stepper (0 renders all steps): 0

Stepper (0 renders all steps): 0

J

1

R

L

2

V

3

N

S

P

4

H

S

B

N

5

H

Q

C

G

D

H

G

J

V

W

R

J

G

S

L

D

H

R

D

N

L

6

C

J

H

F

F

M

B

G

B

R

M

N

Z

V

F

W

G

S

R

C

D

V

7

S

8

J

9

## Steps

Move 2 from 1 to 6.

Move 8 from 4 to 5.

Move 2 from 3 to 4.

Move 1 from 3 to 4.

Move 1 from 4 to 7.

Move 5 from 8 to 1.

Move 7 from 0 to 5.

Move 7 from 2 to 7.

Move 1 from 3 to 5.

Move 2 from 4 to 5.

Move 6 from 6 to 4.

Move 2 from 1 to 3.

Move 4 from 4 to 1.

Move 10 from 7 to 0.

Move 2 from 6 to 3.

Move 4 from 1 to 7.

Move 2 from 8 to 7.

Move 1 from 7 to 3.

Move 2 from 3 to 8.

Move 5 from 7 to 1.

Move 1 from 3 to 5.

Move 1 from 7 to 8.

Move 1 from 6 to 1.

Move 2 from 3 to 1.

Move 1 from 6 to 2.

Move 13 from 1 to 0.

Move 1 from 1 to 3.

Move 1 from 1 to 2.

Move 2 from 4 to 3.

Move 17 from 5 to 3.

Move 3 from 3 to 8.

Move 14 from 0 to 3.

Move 4 from 5 to 7.

Move 1 from 8 to 7.

Move 23 from 3 to 7.

Move 6 from 0 to 6.

Move 3 from 0 to 4.

Move 1 from 2 to 7.

Move 5 from 6 to 7.

Move 1 from 2 to 3.

Move 1 from 4 to 2.

Move 1 from 4 to 0.

Move 1 from 2 to 1.

Move 1 from 8 to 3.

Move 9 from 3 to 8.

Move 1 from 0 to 1.

Move 11 from 7 to 1.

Move 1 from 3 to 4.

Move 13 from 1 to 2.

Move 7 from 8 to 5.

Move 1 from 4 to 5.

Move 1 from 4 to 1.

Move 1 from 8 to 3.

Move 1 from 3 to 8.

Move 2 from 7 to 8.

Move 1 from 6 to 7.

Move 8 from 8 to 0.

Move 8 from 0 to 3.

Move 4 from 5 to 6.

Move 1 from 8 to 3.

Move 2 from 2 to 8.

Move 1 from 8 to 0.

Move 6 from 3 to 0.

Move 2 from 0 to 2.

Move 22 from 7 to 5.

Move 1 from 1 to 4.

Move 3 from 6 to 7.

Move 15 from 5 to 3.

Move 7 from 2 to 6.

Move 4 from 5 to 8.

Move 2 from 8 to 1.

Move 6 from 2 to 4.

Move 3 from 8 to 4.

Move 5 from 4 to 7.

Move 1 from 1 to 0.

Move 6 from 7 to 1.

Move 1 from 0 to 1.

Move 3 from 4 to 2.

Move 1 from 6 to 1.

Move 4 from 6 to 7.

Move 4 from 5 to 0.

Move 1 from 4 to 0.

Move 4 from 7 to 6.

Move 2 from 2 to 1.

Move 1 from 0 to 2.

Move 15 from 3 to 1.

Move 3 from 6 to 2.

Move 4 from 6 to 1.

Move 1 from 3 to 8.

Move 5 from 2 to 7.

Move 29 from 1 to 0.

Move 1 from 8 to 4.

Move 1 from 1 to 0.

Move 11 from 0 to 4.

Move 1 from 3 to 4.

Move 2 from 5 to 2.

Move 1 from 2 to 3.

Move 16 from 0 to 8.

Move 4 from 7 to 3.

Move 3 from 5 to 8.

Move 1 from 2 to 6.

Move 1 from 6 to 2.

Move 6 from 0 to 5.

Move 3 from 3 to 2.

Move 3 from 7 to 4.

Move 3 from 0 to 7.

Move 3 from 0 to 3.

Move 2 from 3 to 8.

Move 3 from 5 to 2.

Move 15 from 4 to 1.

Move 3 from 1 to 2.

Move 4 from 1 to 6.

Move 2 from 4 to 8.

Move 10 from 2 to 5.

Move 11 from 8 to 4.

Move 2 from 3 to 8.

Move 8 from 8 to 3.

Move 1 from 8 to 5.

Move 7 from 3 to 5.

Move 3 from 4 to 7.

Move 22 from 5 to 8.

Move 4 from 6 to 7.

Move 8 from 4 to 7.

Move 2 from 3 to 2.

Move 1 from 7 to 0.

Move 17 from 7 to 2.

Move 3 from 2 to 3.

Move 13 from 2 to 8.

Move 20 from 8 to 6.

Move 2 from 1 to 8.

Move 19 from 8 to 4.

Move 1 from 0 to 3.

Move 3 from 1 to 6.

Move 4 from 3 to 2.

Move 1 from 8 to 7.

Move 18 from 4 to 0.

Move 1 from 8 to 3.

Move 1 from 8 to 6.

Move 2 from 3 to 7.

Move 1 from 4 to 3.

Move 3 from 1 to 6.

Move 3 from 2 to 0.

Move 2 from 0 to 2.

Move 3 from 2 to 7.

Move 1 from 3 to 7.

Move 6 from 7 to 1.

Move 1 from 2 to 8.

Move 1 from 2 to 8.

Move 10 from 0 to 8.

Move 7 from 0 to 6.

Move 4 from 6 to 3.

Move 29 from 6 to 2.

Move 6 from 1 to 8.

Move 25 from 2 to 5.

Move 5 from 2 to 8.

Move 13 from 5 to 8.

Move 12 from 5 to 1.

Move 1 from 7 to 8.

Move 10 from 1 to 5.

Move 7 from 5 to 4.

Move 20 from 8 to 2.

Move 11 from 2 to 5.

Move 1 from 6 to 8.

Move 2 from 1 to 8.

Move 19 from 8 to 1.

Move 14 from 5 to 7.

Move 4 from 4 to 1.

Move 2 from 3 to 5.

Move 3 from 4 to 0.

Move 13 from 7 to 4.

Move 1 from 5 to 0.

Move 2 from 3 to 1.

Move 8 from 1 to 3.

Move 6 from 3 to 6.

Move 1 from 8 to 7.

Move 2 from 3 to 6.

Move 5 from 1 to 3.

Move 4 from 3 to 1.

Move 10 from 4 to 5.

Move 1 from 0 to 6.

Move 1 from 4 to 3.

Move 1 from 3 to 8.

Move 4 from 6 to 7.

Move 5 from 0 to 6.

Move 1 from 8 to 6.

Move 7 from 2 to 1.

Move 2 from 4 to 1.

Move 8 from 5 to 8.

Move 1 from 3 to 5.

Move 3 from 6 to 3.

Move 5 from 8 to 6.

Move 2 from 3 to 2.

Move 20 from 1 to 3.

Move 2 from 3 to 7.

Move 14 from 3 to 1.

Move 12 from 6 to 3.

Move 8 from 1 to 0.

Move 10 from 1 to 3.

Move 6 from 7 to 4.

Move 1 from 6 to 7.

Move 4 from 3 to 2.

Move 1 from 2 to 8.

Move 1 from 1 to 6.

Move 1 from 5 to 7.

Move 5 from 2 to 4.

Move 1 from 2 to 1.

Move 7 from 3 to 4.

Move 6 from 0 to 6.

Move 5 from 6 to 5.

Move 1 from 5 to 4.

Move 2 from 6 to 7.

Move 1 from 1 to 5.

Move 2 from 7 to 1.

Move 5 from 4 to 6.

Move 6 from 5 to 7.

Move 16 from 3 to 8.

Move 16 from 8 to 3.

Move 11 from 4 to 3.

Move 5 from 7 to 2.

Move 2 from 4 to 1.

Move 14 from 3 to 1.

Move 1 from 5 to 2.

Move 1 from 5 to 8.

Move 1 from 4 to 2.

Move 3 from 7 to 1.

Move 10 from 3 to 6.

Move 5 from 8 to 1.

Move 3 from 3 to 6.

Move 1 from 0 to 3.

Move 3 from 1 to 4.

Move 2 from 2 to 6.

Move 1 from 3 to 1.

Move 18 from 1 to 7.

Move 3 from 7 to 3.

Move 5 from 2 to 0.

Move 1 from 2 to 8.

Move 1 from 8 to 2.

Move 8 from 7 to 6.

Move 2 from 4 to 3.

Move 1 from 4 to 5.

Move 1 from 1 to 4.

Move 1 from 4 to 7.

Move 1 from 5 to 8.

Move 3 from 1 to 6.

Move 27 from 6 to 3.

Move 2 from 1 to 3.

Move 4 from 7 to 3.

Move 1 from 8 to 7.

Move 3 from 0 to 5.

Move 1 from 2 to 4.

Move 3 from 7 to 2.

Move 1 from 0 to 3.

Move 1 from 7 to 0.

Move 3 from 0 to 3.

Move 2 from 7 to 1.

Move 2 from 5 to 1.

Move 8 from 3 to 8.

Move 1 from 6 to 0.

Move 1 from 4 to 3.

Move 1 from 6 to 2.

Move 4 from 1 to 6.

Move 1 from 7 to 5.

Move 8 from 8 to 6.

Move 1 from 5 to 2.

Move 3 from 2 to 3.

Move 37 from 3 to 0.

Move 1 from 3 to 4.

Move 13 from 6 to 7.

Move 6 from 7 to 3.

Move 5 from 7 to 2.

Move 1 from 6 to 5.

Move 4 from 0 to 4.

Move 1 from 5 to 4.

Move 2 from 7 to 3.

Move 32 from 0 to 4.

Move 1 from 0 to 3.

Move 5 from 2 to 4.

Move 1 from 2 to 1.

Move 1 from 1 to 8.

Move 19 from 4 to 1.

Move 1 from 8 to 0.

Move 16 from 4 to 0.

Move 7 from 4 to 5.

Move 1 from 2 to 0.

Move 11 from 0 to 1.

Move 18 from 1 to 3.

Move 1 from 4 to 8.

Move 8 from 5 to 0.

Move 10 from 1 to 5.

Move 7 from 3 to 8.

Move 2 from 1 to 0.

Move 7 from 3 to 1.

Move 5 from 3 to 4.

Move 2 from 8 to 5.

Move 9 from 5 to 2.

Move 5 from 4 to 2.

Move 8 from 3 to 8.

Move 7 from 8 to 7.

Move 4 from 1 to 8.

Move 10 from 2 to 0.

Move 6 from 7 to 0.

Move 2 from 5 to 2.

Move 5 from 2 to 7.

Move 3 from 1 to 6.

Move 1 from 8 to 4.

Move 1 from 2 to 4.

Move 2 from 6 to 7.

Move 1 from 7 to 8.

Move 1 from 5 to 0.

Move 23 from 0 to 3.

Move 2 from 4 to 2.

Move 1 from 7 to 1.

Move 2 from 7 to 4.

Move 2 from 4 to 5.

Move 1 from 1 to 6.

Move 1 from 6 to 4.

Move 4 from 8 to 6.

Move 1 from 6 to 4.

Move 1 from 2 to 5.

Move 3 from 6 to 3.

Move 1 from 2 to 7.

Move 1 from 3 to 5.

Move 6 from 0 to 7.

Move 4 from 5 to 3.

Move 2 from 8 to 0.

Move 1 from 4 to 0.

Move 19 from 3 to 1.

Move 2 from 8 to 2.

Move 1 from 8 to 2.

Move 9 from 0 to 7.

Move 1 from 4 to 7.

Move 1 from 8 to 2.

Move 2 from 2 to 8.

Move 3 from 7 to 3.

Move 1 from 3 to 8.

Move 1 from 8 to 4.

Move 2 from 2 to 3.

Move 6 from 3 to 6.

Move 3 from 8 to 4.

Move 4 from 3 to 6.

Move 1 from 4 to 5.

Move 18 from 1 to 6.

Move 13 from 6 to 8.

Move 3 from 4 to 0.

Move 1 from 1 to 0.

Move 1 from 5 to 4.

Move 3 from 0 to 6.

Move 1 from 0 to 4.

Move 7 from 8 to 5.

Move 8 from 6 to 3.

Move 11 from 6 to 5.

Move 5 from 8 to 1.

Move 17 from 5 to 0.

Move 2 from 4 to 0.

Move 11 from 7 to 0.

Move 20 from 0 to 1.

Move 3 from 7 to 0.

Move 1 from 8 to 7.

Move 1 from 5 to 0.

Move 11 from 0 to 6.

Move 18 from 1 to 2.

Move 12 from 3 to 7.

Move 11 from 6 to 2.

Move 7 from 1 to 2.

Move 2 from 0 to 4.

Move 1 from 0 to 2.

Move 1 from 7 to 0.

Move 1 from 4 to 8.

Move 1 from 8 to 5.

Move 1 from 7 to 6.

Move 1 from 4 to 2.

Move 1 from 5 to 6.

Move 2 from 7 to 0.

Move 8 from 2 to 1.

Move 7 from 1 to 8.

Move 6 from 7 to 5.

Move 1 from 8 to 2.

Move 2 from 5 to 3.

Move 5 from 8 to 5.

Move 7 from 5 to 1.

Move 8 from 1 to 8.

Move 2 from 0 to 8.

Move 2 from 6 to 1.

Move 2 from 3 to 7.

Move 1 from 1 to 6.

Move 25 from 2 to 6.

Move 7 from 8 to 6.

Move 1 from 1 to 4.

Move 1 from 0 to 3.

Move 3 from 7 to 0.

Move 3 from 0 to 7.

Move 3 from 6 to 7.

Move 15 from 6 to 2.

Move 10 from 7 to 2.

Move 1 from 4 to 6.

Move 1 from 7 to 4.

Move 3 from 8 to 1.

Move 1 from 5 to 3.

Move 2 from 1 to 6.

Move 1 from 1 to 4.

Move 14 from 6 to 8.

Move 1 from 5 to 1.

Move 1 from 6 to 0.

Move 1 from 4 to 3.

Move 3 from 3 to 2.

Move 1 from 6 to 5.

Move 1 from 1 to 6.

Move 1 from 0 to 1.

Move 3 from 8 to 0.

Move 1 from 5 to 1.

Move 2 from 1 to 5.

Move 17 from 2 to 5.

Move 1 from 7 to 2.

Move 1 from 4 to 3.

Move 2 from 6 to 1.

Move 9 from 8 to 7.

Move 1 from 8 to 2.

Move 16 from 2 to 1.

Move 1 from 6 to 4.

Move 5 from 5 to 4.

Move 1 from 0 to 5.

Move 1 from 3 to 0.

Move 1 from 8 to 2.

Move 9 from 7 to 5.

Move 3 from 0 to 4.

Move 1 from 8 to 0.

Move 16 from 1 to 0.

Move 2 from 1 to 6.

Move 2 from 2 to 8.

Move 2 from 6 to 3.

Move 2 from 8 to 2.

Move 3 from 2 to 4.

Move 1 from 3 to 4.

Move 1 from 3 to 1.

Move 1 from 0 to 6.

Move 1 from 6 to 0.

Move 1 from 2 to 5.

Move 2 from 4 to 0.

Move 3 from 5 to 1.

Move 2 from 4 to 7.

Move 8 from 4 to 3.

Move 1 from 4 to 2.

Move 1 from 2 to 1.

Move 1 from 7 to 2.

Move 1 from 2 to 7.

Move 4 from 0 to 6.

Move 9 from 0 to 6.

Move 6 from 0 to 7.

Move 3 from 6 to 3.

Move 7 from 5 to 6.

Move 11 from 3 to 2.

Move 2 from 2 to 7.

Move 8 from 2 to 7.

Move 4 from 5 to 0.

Move 1 from 6 to 3.

Move 2 from 0 to 1.

Move 8 from 6 to 1.

Move 1 from 3 to 7.

Move 10 from 7 to 1.

Move 2 from 5 to 0.

Move 1 from 0 to 3.

Move 1 from 3 to 7.

Move 2 from 0 to 3.

Move 6 from 5 to 4.

Move 1 from 0 to 8.

Move 2 from 5 to 7.

Move 1 from 3 to 4.

Move 1 from 5 to 8.

Move 4 from 7 to 8.

Move 1 from 6 to 0.

Move 6 from 7 to 5.

Move 1 from 5 to 0.

Move 1 from 3 to 8.

Move 2 from 8 to 4.

Move 5 from 4 to 8.

Move 8 from 8 to 4.

Move 2 from 7 to 4.

Move 3 from 5 to 8.

Move 8 from 4 to 6.

Move 5 from 4 to 5.

Move 1 from 8 to 1.

Move 1 from 2 to 0.

Move 1 from 5 to 6.

Move 1 from 4 to 5.

Move 24 from 1 to 3.

Move 3 from 8 to 6.

Move 16 from 3 to 4.

Move 2 from 0 to 2.

Move 12 from 4 to 5.

Move 1 from 8 to 4.

Move 4 from 4 to 8.

Move 1 from 0 to 5.

Move 1 from 4 to 1.

Move 2 from 8 to 7.

Move 1 from 7 to 0.

Move 5 from 3 to 4.

Move 2 from 2 to 4.

Move 1 from 7 to 2.

Move 1 from 0 to 5.

Move 3 from 4 to 6.

Move 1 from 8 to 0.

Move 1 from 1 to 7.

The stacks are rendered above, you can toggle between the CrateMover versions. Since I already moved whole stacks in the first part this was very easy to implement. The stacks are a array of lists. Each stack is a list, a list can easily be split up with:

```
let grabFromStack = (stack: stack, amount: int) => {
let emptyStack: stack = list{}
switch Belt.List.splitAt(stack, amount) {
| Some(grabbed, rest) => (grabbed, rest)
| _ => (emptyStack, emptyStack)
}
}
```

Crates are grabbed in chunks, and reversed for the old version.

```
let sortGrabbedCrates = (stack: stack, version) =>
switch version {
| CM9000 => Belt.List.reverse(stack)
| CM9001 => stack
}
```