Skip to content

Commit

Permalink
fix: use katex code block
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Dec 14, 2024
1 parent 908fb44 commit b67cca6
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions docs/2024/puzzles/day13.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,54 @@ We need another approach. Let's look at the condition carefully...

Turns out we can express it using system of equations! For number of button presses `A` and `B`, our target `x` and `y` can be described as following equation:

```math
$$
\begin{cases}
A \cdot ax + B \cdot bx = x \\
A \cdot ay + B \cdot by = y
\end{cases}
```
$$

Which can be solved for `A` in terms of `B`:

```math
$$
A = \frac{x - B \cdot bx}{ax}, \quad A = \frac{y - B \cdot by}{ay}
```
$$

Then `A` can be equated in both expressions:

```math
$$
\frac{x - B \cdot bx}{ax} = \frac{y - B \cdot by}{ay}
```
$$

Now `ax` and `ay` can be cross-multiplied to eliminate denominators:

```math
$$
(x - B \cdot bx) \cdot ay = (y - B \cdot by) \cdot ax
```
$$

...Expand and rearrange:

```math
$$
x \cdot ay - B \cdot bx \cdot ay = y \cdot ax - B \cdot by \cdot ax
```
$$

Group terms involving `B`:

```math
$$
x \cdot ay - y \cdot ax = B \cdot (bx \cdot ay - by \cdot ax)
```
$$

Then solve for `B`:

```math
$$
B = \frac{x \cdot ay - y \cdot ax}{bx \cdot ay - by \cdot ax}
```
$$

Using `B`, `A` can also be solved:

```math
$$
A = \frac{x - B \cdot bx}{ax}
```
$$

There's two more important requirement for `A` and `B`:
1. `A` and `B` should both be an natural number.
Expand Down

0 comments on commit b67cca6

Please sign in to comment.