Added template and 2016

This commit is contained in:
FrederikBaerentsen 2024-11-02 18:13:20 +01:00
parent f57441f092
commit 7b23e4ab4b
7 changed files with 431 additions and 0 deletions

63
2015/01/1.md Normal file
View File

@ -0,0 +1,63 @@
## \-\-- Day 1: Not Quite Lisp \-\--
Santa was hoping for a white Christmas, but his weather machine\'s
\"snow\" function is powered by stars, and he\'s fresh out! To save
Christmas, he needs you to collect *fifty stars* by December 25th.
Collect stars by helping Santa solve puzzles. Two puzzles will be made
available on each day in the Advent calendar; the second puzzle is
unlocked when you complete the first. Each puzzle grants *one star*.
[Good
luck!]{title="Also, some puzzles contain Easter eggs like this one. Yes, I know it's not traditional to do Advent calendars for Easter."}
Here\'s an easy puzzle to warm you up.
Santa is trying to deliver presents in a large apartment building, but
he can\'t find the right floor - the directions he got are a little
confusing. He starts on the ground floor (floor `0`) and then follows
the instructions one character at a time.
An opening parenthesis, `(`, means he should go up one floor, and a
closing parenthesis, `)`, means he should go down one floor.
The apartment building is very tall, and the basement is very deep; he
will never find the top or bottom floors.
For example:
- `(())` and `()()` both result in floor `0`.
- `(((` and `(()(()(` both result in floor `3`.
- `))(((((` also results in floor `3`.
- `())` and `))(` both result in floor `-1` (the first basement
level).
- `)))` and `)())())` both result in floor `-3`.
To *what floor* do the instructions take Santa?
Your puzzle answer was `232`.
## \-\-- Part Two \-\-- {#part2}
Now, given the same instructions, find the *position* of the first
character that causes him to enter the basement (floor `-1`). The first
character in the instructions has position `1`, the second character has
position `2`, and so on.
For example:
- `)` causes him to enter the basement at character position `1`.
- `()())` causes him to enter the basement at character position `5`.
What is the *position* of the character that causes Santa to first enter
the basement?
Your puzzle answer was `1783`.
Both parts of this puzzle are complete! They provide two gold stars:
\*\*
At this point, you should [return to your Advent calendar](/2015) and
try another puzzle.
If you still want to see it, you can [get your puzzle
input](1/input).

View File

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 1 - Advent of Code 2015</title>
<link rel="stylesheet" type="text/css" href="/static/style.css?31"/>
<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?1" title="High Contrast"/>
<link rel="shortcut icon" href="/favicon.png"/>
<script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
</head><!--
Oh, hello! Funny seeing you here.
I appreciate your enthusiasm, but you aren't going to find much down here.
There certainly aren't clues to any of the puzzles. The best surprises don't
even appear in the source until you unlock them for real.
Please be careful with automated requests; I'm not a massive company, and I can
only take so much traffic. Please be considerate so that everyone gets to play.
If you're curious about how Advent of Code works, it's running on some custom
Perl code. Other than a few integrations (auth, analytics, social media), I
built the whole thing myself, including the design, animations, prose, and all
of the puzzles.
The puzzles are most of the work; preparing a new calendar and a new set of
puzzles each year takes all of my free time for 4-5 months. A lot of effort
went into building this thing - I hope you're enjoying playing it as much as I
enjoyed making it for you!
If you'd like to hang out, I'm @ericwastl@hachyderm.io on Mastodon and
@ericwastl on Twitter.
- Eric Wastl
-->
<body>
<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2015/about">[About]</a></li><li><a href="/2015/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2015/settings">[Settings]</a></li><li><a href="/2015/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Frederik Baerentsen <span class="star-count">11*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=</span><a href="/2015">2015</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2015">[Calendar]</a></li><li><a href="/2015/support">[AoC++]</a></li><li><a href="/2015/sponsors">[Sponsors]</a></li><li><a href="/2015/leaderboard">[Leaderboard]</a></li><li><a href="/2015/stats">[Stats]</a></li></ul></nav></div></header>
<div id="sidebar">
</div><!--/sidebar-->
<main>
<article><p>You don't seem to be solving the right level. Did you already complete it? <a href="/2015/day/1">[Return to Day 1]</a></p></article>
</main>
<!-- ga -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-69522494-1', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
<!-- /ga -->
</body>
</html>

17
2015/01/part1.py Normal file
View File

@ -0,0 +1,17 @@
#!/bin/python3
import sys
from pprint import pprint
input_f = sys.argv[1]
result = 0
with open(input_f) as file:
for line in file:
for idx,i in enumerate(line):
if i == '(':
result += 1
if i == ')':
result -= 1
print(result)

70
2015/07/7.md Normal file
View File

@ -0,0 +1,70 @@
## \-\-- Day 7: Some Assembly Required \-\--
This year, Santa brought little Bobby Tables a set of wires and [bitwise
logic gates](https://en.wikipedia.org/wiki/Bitwise_operation)!
Unfortunately, little Bobby is a little under the recommended age range,
and he needs help [assembling the
circuit]{title="You had one of these as a kid, right?"}.
Each wire has an identifier (some lowercase letters) and can carry a
[16-bit](https://en.wikipedia.org/wiki/16-bit) signal (a number from `0`
to `65535`). A signal is provided to each wire by a gate, another wire,
or some specific value. Each wire can only get a signal from one source,
but can provide its signal to multiple destinations. A gate provides no
signal until all of its inputs have a signal.
The included instructions booklet describes how to connect the parts
together: `x AND y -> z` means to connect wires `x` and `y` to an AND
gate, and then connect its output to wire `z`.
For example:
- `123 -> x` means that the signal `123` is provided to wire `x`.
- `x AND y -> z` means that the [bitwise
AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of wire
`x` and wire `y` is provided to wire `z`.
- `p LSHIFT 2 -> q` means that the value from wire `p` is
[left-shifted](https://en.wikipedia.org/wiki/Logical_shift) by `2`
and then provided to wire `q`.
- `NOT e -> f` means that the [bitwise
complement](https://en.wikipedia.org/wiki/Bitwise_operation#NOT) of
the value from wire `e` is provided to wire `f`.
Other possible gates include `OR` ([bitwise
OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and `RSHIFT`
([right-shift](https://en.wikipedia.org/wiki/Logical_shift)). If, for
some reason, you\'d like to *emulate* the circuit instead, almost all
programming languages (for example,
[C](https://en.wikipedia.org/wiki/Bitwise_operations_in_C),
[JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators),
or [Python](https://wiki.python.org/moin/BitwiseOperators)) provide
operators for these gates.
For example, here is a simple circuit:
123 -> x
456 -> y
x AND y -> d
x OR y -> e
x LSHIFT 2 -> f
y RSHIFT 2 -> g
NOT x -> h
NOT y -> i
After it is run, these are the signals on the wires:
d: 72
e: 507
f: 492
g: 114
h: 65412
i: 65079
x: 123
y: 456
In little Bobby\'s kit\'s instructions booklet (provided as your puzzle
input), what signal is ultimately provided to *wire `a`*?
To begin, [get your puzzle input](7/input).
Answer:

62
2016/01/1.md Normal file
View File

@ -0,0 +1,62 @@
## \-\-- Day 1: No Time for a Taxicab \-\--
Santa\'s sleigh uses a [very high-precision
clock]{title="An atomic clock is too inaccurate; he might end up in a wall!"}
to guide its movements, and the clock\'s oscillator is regulated by
stars. Unfortunately, the stars have been stolen\... by the Easter
Bunny. To save Christmas, Santa needs you to retrieve all *fifty stars*
by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on
each day in the Advent calendar; the second puzzle is unlocked when you
complete the first. Each puzzle grants *one star*. Good luck!
You\'re airdropped near *Easter Bunny Headquarters* in a city somewhere.
\"Near\", unfortunately, is as close as you can get - the instructions
on the Easter Bunny Recruiting Document the Elves intercepted start
here, and nobody had time to work them out further.
The Document indicates that you should start at the given coordinates
(where you just landed) and face North. Then, follow the provided
sequence: either turn left (`L`) or right (`R`) 90 degrees, then walk
forward the given number of blocks, ending at a new intersection.
There\'s no time to follow such ridiculous instructions on foot, though,
so you take a moment and work out the destination. Given that you can
only walk on the [street grid of the
city](https://en.wikipedia.org/wiki/Taxicab_geometry), how far is the
shortest path to the destination?
For example:
- Following `R2, L3` leaves you `2` blocks East and `3` blocks North,
or `5` blocks away.
- `R2, R2, R2` leaves you `2` blocks due South of your starting
position, which is `2` blocks away.
- `R5, L5, R5, R3` leaves you `12` blocks away.
*How many blocks away* is Easter Bunny HQ?
Your puzzle answer was `236`.
## \-\-- Part Two \-\-- {#part2}
Then, you notice the instructions continue on the back of the Recruiting
Document. Easter Bunny HQ is actually at the first location you visit
twice.
For example, if your instructions are `R8, R4, R4, R8`, the first
location you visit twice is `4` blocks away, due East.
How many blocks away is the *first location you visit twice*?
Your puzzle answer was `182`.
Both parts of this puzzle are complete! They provide two gold stars:
\*\*
At this point, you should [return to your Advent calendar](/2016) and
try another puzzle.
If you still want to see it, you can [get your puzzle
input](1/input).

84
2016/01/solution.py Normal file
View File

@ -0,0 +1,84 @@
#!/bin/python3
import sys
from pprint import pprint
# Read instructions from file
with open("input", "r") as file:
instructions = file.read().strip().split(", ")
#########################################
# #
# Part 1 #
# #
#########################################
# Define directions and movements in terms of (x, y) vectors
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # North, East, South, West
# Starting position and direction
x, y = 0, 0
current_direction = 0 # Start facing North (index 0 in directions)
# Process each instruction
for instruction in instructions:
turn, steps = instruction[0], int(instruction[1:])
# Update direction based on the turn
if turn == 'R':
current_direction = (current_direction + 1) % 4 # Turn right
elif turn == 'L':
current_direction = (current_direction - 1) % 4 # Turn left
# Move in the current direction
dx, dy = directions[current_direction]
x += dx * steps
y += dy * steps
# Calculate Manhattan distance from the origin
distance = abs(x) + abs(y)
print(distance)
#########################################
# #
# Part 2 #
# #
#########################################
# Define directions and movements in terms of (x, y) vectors
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # North, East, South, West
# Starting position and direction
x, y = 0, 0
current_direction = 0 # Start facing North (index 0 in directions)
visited = set() # To track visited positions
visited.add((x, y)) # Starting point is visited
# Read instructions from file
with open("input", "r") as file:
instructions = file.read().strip().split(", ")
# Process each instruction
for instruction in instructions:
turn, steps = instruction[0], int(instruction[1:])
# Update direction based on the turn
if turn == 'R':
current_direction = (current_direction + 1) % 4 # Turn right
elif turn == 'L':
current_direction = (current_direction - 1) % 4 # Turn left
# Move step by step in the current direction
dx, dy = directions[current_direction]
for _ in range(steps):
x += dx
y += dy
if (x, y) in visited:
# Found the first location visited twice
distance = abs(x) + abs(y)
print(distance)
exit()
visited.add((x, y))

24
solution.py Normal file
View File

@ -0,0 +1,24 @@
#!/bin/python3
import sys
from pprint import pprint
input_f = "input" #sys.argv[1]
with open(input_f) as file:
for line in file:
#########################################
# #
# Part 1 #
# #
#########################################
#########################################
# #
# Part 2 #
# #
#########################################