Skip to content

Commit 0ea1984

Browse files
committed
Saves more stuff
1 parent 1d28969 commit 0ea1984

File tree

5 files changed

+236
-71
lines changed

5 files changed

+236
-71
lines changed

docs/2019/day/16.md

Lines changed: 105 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,105 @@
1-
```js
2-
const fillPattern = (function () {
3-
let cachedPatterns = {};
4-
return (n) => {
5-
if (cachedPatterns[n]) {
6-
return cachedPatterns[n];
7-
}
8-
9-
let pattern = [];
10-
for (let num of [0, 1, 0, -1]) {
11-
for (let i = 0; i < n; i++) {
12-
pattern.push(num);
13-
}
14-
}
15-
16-
// Offset the whole pattern left by one
17-
let first_digit = pattern.shift();
18-
pattern.push(first_digit);
19-
20-
cachedPatterns[n] = pattern;
21-
22-
return pattern;
23-
};
24-
})();
25-
26-
var table = function (input) {
27-
let pad = String(input.length).length;
28-
let space = '#'.padStart(pad);
29-
let header = `| ${space} | ${input.join(' | ')} |`;
30-
let line = header
31-
.split('')
32-
.map((c) => (c === '|' ? '|' : '-'))
33-
.join('');
34-
let grid = [];
35-
36-
let mid = Math.floor(input.length / 2);
37-
for (let y = 0; y < input.length; y++) {
38-
let row = [];
39-
let pattern = fillPattern(y + 1);
40-
for (let x = 0; x < input.length; x++) {
41-
let char = ' ';
42-
let i = x % pattern.length;
43-
let scalar = pattern[i];
44-
45-
if (y >= mid) {
46-
if (scalar === 1) {
47-
char = ` *${input[x]}*`;
48-
} else if (scalar === -1) {
49-
char = `*-${input[x]}*`;
50-
}
51-
} else {
52-
if (scalar === 1) {
53-
char = ` ${input[x]} `;
54-
} else if (scalar === -1) {
55-
char = ` -${input[x]} `;
56-
}
57-
}
58-
59-
row.push(char);
60-
}
61-
62-
grid.push(`| ${(y + 1).toString().padStart(pad)} | ${row.join(' | ')} |`);
63-
}
64-
65-
let output = [header, line, ...grid].join('\n');
66-
return output;
67-
};
68-
```
1+
---
2+
title: Day 16 - Flawed Frequency Transmission
3+
day: 16
4+
year: 2019
5+
---
6+
7+
This one had me stumped, but through some hints online, I was eventually able to realize the
8+
trick for this one.
9+
10+
<details><summary markdown='span'>Day 16, Part One and Part Two Descriptions
11+
</summary>
12+
13+
## --- Day 16: Flawed Frequency Transmission ---
14+
15+
You're 3/4ths of the way through the [gas giants](https://en.wikipedia.org/wiki/Gas_giant). Not only do roundtrip signals to Earth take five hours, but the signal quality is quite bad as well. You can clean up the signal with the Flawed Frequency Transmission algorithm, or _FFT_.
16+
17+
As input, FFT takes a list of numbers. In the signal you received (your puzzle input), each number is a single digit: data like `15243` represents the sequence `1`, `5`, `2`, `4`, `3`.
18+
19+
FFT operates in repeated _phases_. In each phase, a new list is constructed with the same length as the input list. This new list is also used as the input for the next phase.
20+
21+
Each element in the new list is built by multiplying every value in the input list by a value in a repeating _pattern_ and then adding up the results. So, if the input list were `9, 8, 7, 6, 5` and the pattern for a given element were `1, 2, 3`, the result would be `9*1 + 8*2 + 7*3 + 6*1 + 5*2` (with each input element on the left and each value in the repeating pattern on the right of each multiplication). Then, only the ones digit is kept: `38` becomes `8`, `-17` becomes `7`, and so on.
22+
23+
While each element in the output array uses all of the same input array elements, the actual repeating pattern to use depends on _which output element_ is being calculated. The base pattern is `0, 1, 0, -1`. Then, repeat each value in the pattern a number of times equal to the _position in the output list_ being considered. Repeat once for the first element, twice for the second element, three times for the third element, and so on. So, if the third element of the output list is being calculated, repeating the values would produce: `0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, -1`.
24+
25+
When applying the pattern, skip the very first value exactly once. (In other words, offset the whole pattern left by one.) So, for the second element of the output list, the actual pattern used would be: `0, 1, 1, 0, 0, -1, -1, 0, 0, 1, 1, 0, 0, -1, -1, ...`.
26+
27+
After using this process to calculate each element of the output list, the phase is complete, and the output list of this phase is used as the new input list for the next phase, if any.
28+
29+
Given the input signal `12345678`, below are four phases of FFT. Within each phase, each output digit is calculated on a single line with the result at the far right; each multiplication operation shows the input digit on the left and the pattern value on the right:
30+
31+
Input signal: 12345678
32+
33+
1*1 + 2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 0*1 + 4*0 + 3*0 + 8*0 = 4
58+
3*0 + 4*0 + 0*0 + 4*1 + 0*1 + 4*1 + 3*1 + 8*0 = 1
59+
3*0 + 4*0 + 0*0 + 4*0 + 0*1 + 4*1 + 3*1 + 8*1 = 5
60+
3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*1 + 3*1 + 8*1 = 5
61+
3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*0 + 3*1 + 8*1 = 1
62+
3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*0 + 3*0 + 8*1 = 8
63+
64+
After 3 phases: 03415518
65+
66+
0*1 + 3*0 + 4*-1 + 1*0 + 5*1 + 5*0 + 1*-1 + 8*0 = 0
67+
0*0 + 3*1 + 4*1 + 1*0 + 5*0 + 5*-1 + 1*-1 + 8*0 = 1
68+
0*0 + 3*0 + 4*1 + 1*1 + 5*1 + 5*0 + 1*0 + 8*0 = 0
69+
0*0 + 3*0 + 4*0 + 1*1 + 5*1 + 5*1 + 1*1 + 8*0 = 2
70+
0*0 + 3*0 + 4*0 + 1*0 + 5*1 + 5*1 + 1*1 + 8*1 = 9
71+
0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*1 + 1*1 + 8*1 = 4
72+
0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*0 + 1*1 + 8*1 = 9
73+
0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*0 + 1*0 + 8*1 = 8
74+
75+
After 4 phases: 01029498
76+
77+
78+
Here are the first eight digits of the final output list after 100 phases for some larger inputs:
79+
80+
* `80871224585914546619083218645595` becomes `24176176`.
81+
* `19617804207202209144916044189917` becomes `73745418`.
82+
* `69317163492948606335995924319873` becomes `52432133`.
83+
84+
After _100_ phases of FFT, _what are the first eight digits in the final output list?_
85+
86+
-----------------
87+
88+
## --- Part Two ---
89+
90+
Now that your FFT is working, you can decode the _real signal_.
91+
92+
The real signal is your puzzle input _repeated 10000 times_. Treat this new signal as a single input list. Patterns are still calculated as before, and 100 phases of FFT are still applied.
93+
94+
The _first seven digits_ of your initial input signal also represent the _message offset_. The message offset is the location of the eight-digit message in the final output list. Specifically, the message offset indicates _the number of digits to skip_ before reading the eight-digit message. For example, if the first seven digits of your initial input signal were `1234567`, the eight-digit message would be the eight digits after skipping 1,234,567 digits of the final output list. Or, if the message offset were `7` and your final output list were `98765432109876543210`, the eight-digit message would be `21098765`. (Of course, your real message offset will be a seven-digit number, not a one-digit number like `7`.)
95+
96+
Here is the eight-digit message in the final output list after 100 phases. The message offset given in each input has been highlighted. (Note that the inputs given below are repeated 10000 times to find the actual starting input lists.)
97+
98+
* <code><em>0303673</em>2577212944063491565474664</code> becomes `84462026`.
99+
* <code><em>0293510</em>9699940807407585447034323</code> becomes `78725270`.
100+
* <code><em>0308177</em>0884921959731165446850517</code> becomes `53553731`.
101+
102+
After repeating your input signal 10000 times and running 100 phases of FFT, _what is the eight-digit message embedded in the final output list?_
103+
104+
</details>
105+

docs/_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
theme: jekyll-theme-primer
22
google_analytics: "UA-103164724-3"
3+
4+
markdown: kramdown
5+
kramdown:
6+
parse_block_html: true

docs/_layouts/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
</head>
1111
<body>
1212
<header class="box-shadow py-3">
13-
<div class="container-lg px-3">
13+
<div class="container-md px-3">
1414
<a href="/{{ site.github.repository_name }}/" class="logo">Advent of Code</a>
1515
{% if page.title %}
1616
<h1 class="f3 ml-3 d-inline">{{ page.title }}</h1>
1717
{% endif %}
1818
</div>
1919
</header>
20-
<div class="container-lg px-3 my-3 markdown-body">
20+
<div class="container-md px-3 my-3 markdown-body">
2121

2222
{{ content }}
2323

docs/assets/css/_variables.scss

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Variables copied from
2+
// https://github.com/pages-themes/primer/blob/516c116/_sass/primer-support/lib/variables/color-system.scss
3+
// for easier reference
4+
5+
//
6+
//
7+
// -------- Grays --------
8+
$gray-000: #fafbfc !default;
9+
$gray-100: #f6f8fa !default;
10+
$gray-200: #e1e4e8 !default;
11+
$gray-300: #d1d5da !default;
12+
$gray-400: #959da5 !default;
13+
$gray-500: #6a737d !default;
14+
$gray-600: #586069 !default;
15+
$gray-700: #444d56 !default;
16+
$gray-800: #2f363d !default;
17+
$gray-900: #24292e !default; // body font color
18+
19+
// -------- Blue --------
20+
$blue-000: #f1f8ff !default;
21+
$blue-100: #dbedff !default;
22+
$blue-200: #c8e1ff !default;
23+
$blue-300: #79b8ff !default;
24+
$blue-400: #2188ff !default;
25+
$blue-500: #0366d6 !default; // Default: Passes AA with #fff
26+
$blue-600: #005cc5 !default;
27+
$blue-700: #044289 !default;
28+
$blue-800: #032f62 !default;
29+
$blue-900: #05264c !default; // Passes with 1/2/300 blues
30+
31+
// -------- Green --------
32+
$green-000: #f0fff4 !default;
33+
$green-100: #dcffe4 !default;
34+
$green-200: #bef5cb !default;
35+
$green-300: #85e89d !default;
36+
$green-400: #34d058 !default;
37+
$green-500: #28a745 !default; // Default. passes AA Large
38+
$green-600: #22863a !default; // Text green, passes AA on #fff
39+
$green-700: #176f2c !default;
40+
$green-800: #165c26 !default;
41+
$green-900: #144620 !default;
42+
43+
// -------- Yellow --------
44+
$yellow-000: #fffdef !default;
45+
$yellow-100: #fffbdd !default;
46+
$yellow-200: #fff5b1 !default;
47+
$yellow-300: #ffea7f !default;
48+
$yellow-400: #ffdf5d !default;
49+
$yellow-500: #ffd33d !default;
50+
$yellow-600: #f9c513 !default;
51+
$yellow-700: #dbab09 !default;
52+
$yellow-800: #b08800 !default;
53+
$yellow-900: #735c0f !default;
54+
55+
// -------- Orange --------
56+
$orange-000: #fff8f2 !default;
57+
$orange-100: #ffebda !default;
58+
$orange-200: #ffd1ac !default;
59+
$orange-300: #ffab70 !default;
60+
$orange-400: #fb8532 !default;
61+
$orange-500: #f66a0a !default; // Default. passes AA Large with #fff
62+
$orange-600: #e36209 !default;
63+
$orange-700: #d15704 !default;
64+
$orange-800: #c24e00 !default;
65+
$orange-900: #a04100 !default;
66+
67+
// -------- Red --------
68+
$red-000: #ffeef0 !default;
69+
$red-100: #ffdce0 !default;
70+
$red-200: #fdaeb7 !default;
71+
$red-300: #f97583 !default;
72+
$red-400: #ea4a5a !default;
73+
$red-500: #d73a49 !default; // Default. passes AA
74+
$red-600: #cb2431 !default;
75+
$red-700: #b31d28 !default;
76+
$red-800: #9e1c23 !default;
77+
$red-900: #86181d !default;
78+
79+
// -------- Purple --------
80+
$purple-000: #f5f0ff !default;
81+
$purple-100: #e6dcfd !default;
82+
$purple-200: #d1bcf9 !default;
83+
$purple-300: #b392f0 !default;
84+
$purple-400: #8a63d2 !default;
85+
$purple-500: #6f42c1 !default; // passes AA with #fff
86+
$purple-600: #5a32a3 !default;
87+
$purple-700: #4c2889 !default;
88+
$purple-800: #3a1d6e !default;
89+
$purple-900: #29134e !default;
90+
91+
// -------- Fades --------
92+
// Black based on same hue as $gray-900
93+
$black: #1b1f23 !default;
94+
$white: #fff !default;
95+
96+
$black-fade-15: rgba($black, 0.15) !default;
97+
$black-fade-30: rgba($black, 0.3) !default;
98+
$black-fade-50: rgba($black, 0.5) !default;
99+
$black-fade-70: rgba($black, 0.7) !default;
100+
$black-fade-85: rgba($black, 0.85) !default;
101+
102+
$white-fade-15: rgba($white, 0.15) !default;
103+
$white-fade-30: rgba($white, 0.3) !default;
104+
$white-fade-50: rgba($white, 0.5) !default;
105+
$white-fade-70: rgba($white, 0.7) !default;
106+
$white-fade-85: rgba($white, 0.85) !default;
107+
108+
// -------- Color defaults --------
109+
$red: $red-500 !default;
110+
$purple: $purple-500 !default;
111+
$blue: $blue-500 !default;
112+
$green: $green-500 !default;
113+
$yellow: $yellow-500 !default;
114+
$orange: $orange-500 !default;
115+
116+
$gray-dark: $gray-900 !default;
117+
$gray-light: $gray-400 !default;
118+
$gray: $gray-500 !default;

docs/assets/css/style.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
details {
77
font-family: monospace;
88
font-size: 0.8rem;
9-
color: #444;
9+
color: $gray-700;
1010

1111
padding: 1rem;
1212
margin: 0 -1rem;
@@ -27,6 +27,12 @@ details {
2727
.markdown-body & + p {
2828
margin-top: 16px;
2929
}
30+
31+
em {
32+
color: $black;
33+
font-style: normal;
34+
text-shadow: 0 0 2px rgba($black, 50%);
35+
}
3036
}
3137

3238
.logo {

0 commit comments

Comments
 (0)