Add puzzle text for day 6 and day 7
This commit is contained in:
@@ -1 +1,20 @@
|
||||
# Day 6 Puzzle Text.
|
||||
|
||||
<article class="day-desc"><h2>--- Day 6: Tuning Trouble ---</h2><p>The preparations are finally complete; you and the Elves leave camp on foot and begin to make your way toward the <em class="star">star</em> fruit grove.</p>
|
||||
<p>As you move through the dense undergrowth, one of the Elves gives you a handheld <em>device</em>. He says that it has many fancy features, but the most important one to set up right now is the <em>communication system</em>.</p>
|
||||
<p>However, because he's heard you have <a href="/2016/day/6">significant</a> <a href="/2016/day/25">experience</a> <a href="/2019/day/7">dealing</a> <a href="/2019/day/9">with</a> <a href="/2019/day/16">signal-based</a> <a href="/2021/day/25">systems</a>, he convinced the other Elves that it would be okay to give you their one malfunctioning device - surely you'll have no problem fixing it.</p>
|
||||
<p>As if inspired by comedic timing, the device emits a few <span title="The magic smoke, on the other hand, seems to be contained... FOR NOW!">colorful sparks</span>.</p>
|
||||
<p>To be able to communicate with the Elves, the device needs to <em>lock on to their signal</em>. The signal is a series of seemingly-random characters that the device receives one at a time.</p>
|
||||
<p>To fix the communication system, you need to add a subroutine to the device that detects a <em>start-of-packet marker</em> in the datastream. In the protocol being used by the Elves, the start of a packet is indicated by a sequence of <em>four characters that are all different</em>.</p>
|
||||
<p>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.</p>
|
||||
<p>For example, suppose you receive the following datastream buffer:</p>
|
||||
<pre><code>mjqjpqmgbljsphdztnvjfqwrcgsmlb</code></pre>
|
||||
<p>After the first three characters (<code>mjq</code>) have been received, there haven't been enough characters received yet to find the marker. The first time a marker could occur is after the fourth character is received, making the most recent four characters <code>mjqj</code>. Because <code>j</code> is repeated, this isn't a marker.</p>
|
||||
<p>The first time a marker appears is after the <em>seventh</em> character arrives. Once it does, the last four characters received are <code>jpqm</code>, which are all different. In this case, your subroutine should report the value <code><em>7</em></code>, because the first start-of-packet marker is complete after 7 characters have been processed.</p>
|
||||
<p>Here are a few more examples:</p>
|
||||
<ul>
|
||||
<li><code>bvwbjplbgvbhsrlpgdmjqwftvncz</code>: first marker after character <code><em>5</em></code></li>
|
||||
<li><code>nppdvjthqldpwncqszvftbrmjlhg</code>: first marker after character <code><em>6</em></code></li>
|
||||
<li><code>nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg</code>: first marker after character <code><em>10</em></code></li>
|
||||
<li><code>zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw</code>: first marker after character <code><em>11</em></code></li>
|
||||
</ul>
|
||||
<p><em>How many characters need to be processed before the first start-of-packet marker is detected?</em></p>
|
||||
|
||||
+1135
-1
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,9 @@
|
||||
import os
|
||||
from advent_of_code.get_puzzle_text import save_puzzle_text
|
||||
|
||||
year = 2022
|
||||
day = 7
|
||||
save_puzzle_text(year, day)
|
||||
|
||||
with open(r'advent_of_code\2022\day_7\input.txt', 'r') as file:
|
||||
input = file.read()
|
||||
|
||||
@@ -1 +1,76 @@
|
||||
# Day 7 Puzzle Text.
|
||||
|
||||
<article class="day-desc"><h2>--- Day 7: No Space Left On Device ---</h2><p>You can hear birds chirping and raindrops hitting leaves as the expedition proceeds. Occasionally, you can even hear much louder sounds in the distance; how big do the animals get out here, anyway?</p>
|
||||
<p>The device the Elves gave you has problems with more than just its communication system. You try to run a system update:</p>
|
||||
<pre><code>$ system-update --please --pretty-please-with-sugar-on-top
|
||||
<span title="E099 PROGRAMMER IS OVERLY POLITE">Error</span>: No space left on device
|
||||
</code></pre>
|
||||
<p>Perhaps you can delete some files to make space for the update?</p>
|
||||
<p>You browse around the filesystem to assess the situation and save the resulting terminal output (your puzzle input). For example:</p>
|
||||
<pre><code>$ cd /
|
||||
$ 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
|
||||
</code></pre>
|
||||
<p>The filesystem consists of a tree of files (plain data) and directories (which can contain other directories or files). The outermost directory is called <code>/</code>. You can navigate around the filesystem, moving into or out of directories and listing the contents of the directory you're currently in.</p>
|
||||
<p>Within the terminal output, lines that begin with <code>$</code> are <em>commands you executed</em>, very much like some modern computers:</p>
|
||||
<ul>
|
||||
<li><code>cd</code> means <em>change directory</em>. This changes which directory is the current directory, but the specific result depends on the argument:
|
||||
<ul>
|
||||
<li><code>cd x</code> moves <em>in</em> one level: it looks in the current directory for the directory named <code>x</code> and makes it the current directory.</li>
|
||||
<li><code>cd ..</code> moves <em>out</em> one level: it finds the directory that contains the current directory, then makes that directory the current directory.</li>
|
||||
<li><code>cd /</code> switches the current directory to the outermost directory, <code>/</code>.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><code>ls</code> means <em>list</em>. It prints out all of the files and directories immediately contained by the current directory:
|
||||
<ul>
|
||||
<li><code>123 abc</code> means that the current directory contains a file named <code>abc</code> with size <code>123</code>.</li>
|
||||
<li><code>dir xyz</code> means that the current directory contains a directory named <code>xyz</code>.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<p>Given the commands and output in the example above, you can determine that the filesystem looks visually like this:</p>
|
||||
<pre><code>- / (dir)
|
||||
- a (dir)
|
||||
- e (dir)
|
||||
- i (file, size=584)
|
||||
- f (file, size=29116)
|
||||
- g (file, size=2557)
|
||||
- h.lst (file, size=62596)
|
||||
- b.txt (file, size=14848514)
|
||||
- c.dat (file, size=8504156)
|
||||
- d (dir)
|
||||
- j (file, size=4060174)
|
||||
- d.log (file, size=8033020)
|
||||
- d.ext (file, size=5626152)
|
||||
- k (file, size=7214296)
|
||||
</code></pre>
|
||||
<p>Here, there are four directories: <code>/</code> (the outermost directory), <code>a</code> and <code>d</code> (which are in <code>/</code>), and <code>e</code> (which is in <code>a</code>). These directories also contain files of various sizes.</p>
|
||||
<p>Since the disk is full, your first step should probably be to find directories that are good candidates for deletion. To do this, you need to determine the <em>total size</em> of each directory. The total size of a directory is the sum of the sizes of the files it contains, directly or indirectly. (Directories themselves do not count as having any intrinsic size.)</p>
|
||||
<p>The total sizes of the directories above can be found as follows:</p>
|
||||
<ul>
|
||||
<li>The total size of directory <code>e</code> is <em>584</em> because it contains a single file <code>i</code> of size 584 and no other directories.</li>
|
||||
<li>The directory <code>a</code> has total size <em>94853</em> because it contains files <code>f</code> (size 29116), <code>g</code> (size 2557), and <code>h.lst</code> (size 62596), plus file <code>i</code> indirectly (<code>a</code> contains <code>e</code> which contains <code>i</code>).</li>
|
||||
<li>Directory <code>d</code> has total size <em>24933642</em>.</li>
|
||||
<li>As the outermost directory, <code>/</code> contains every file. Its total size is <em>48381165</em>, the sum of the size of every file.</li>
|
||||
</ul>
|
||||
<p>To begin, find all of the directories with a total size of <em>at most 100000</em>, then calculate the sum of their total sizes. In the example above, these directories are <code>a</code> and <code>e</code>; the sum of their total sizes is <code><em>95437</em></code> (94853 + 584). (As in this example, this process can count files more than once!)</p>
|
||||
<p>Find all of the directories with a total size of at most 100000. <em>What is the sum of the total sizes of those directories?</em></p>
|
||||
|
||||
Reference in New Issue
Block a user