Compare commits
2 Commits
58980edfb0
...
bd0ccdd942
| Author | SHA1 | Date | |
|---|---|---|---|
| bd0ccdd942 | |||
| 9bd7a0cd85 |
@@ -1,15 +1,3 @@
|
||||
|
||||
Advent of Code
|
||||
|
||||
[About][Events][Shop][Settings][Log Out]
|
||||
|
||||
Bruno Raoult 2*
|
||||
{:year 2021}
|
||||
|
||||
[Calendar][AoC++][Sponsors][Leaderboard][Stats]
|
||||
|
||||
Our sponsors help make Advent of Code possible:
|
||||
Ximedes - From Kotlin in the cloud to NodeJS in the terminal, our software powers payments and public transport ticketing all over the world.
|
||||
--- Day 1: Sonar Sweep ---
|
||||
|
||||
You're minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!
|
||||
|
||||
6
2021/day02/EXAMPLE.txt
Normal file
6
2021/day02/EXAMPLE.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
1000
2021/day02/INPUT.txt
Normal file
1000
2021/day02/INPUT.txt
Normal file
File diff suppressed because it is too large
Load Diff
54
2021/day02/Makefile
Normal file
54
2021/day02/Makefile
Normal file
@@ -0,0 +1,54 @@
|
||||
# AOC daily Makefile - GNU make only.
|
||||
#
|
||||
# Copyright (C) 2021 Bruno Raoult ("br")
|
||||
# Licensed under the GNU General Public License v3.0 or later.
|
||||
# Some rights reserved. See COPYING.
|
||||
# * You should have received a copy of the GNU General Public License along with this
|
||||
# program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.htmlL>.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||
#
|
||||
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
|
||||
CC := gcc
|
||||
|
||||
LIB := aoc_$(shell uname -m)
|
||||
INCDIR := ../include
|
||||
LIBDIR := ../lib
|
||||
LDFLAGS := -L$(LIBDIR)
|
||||
LDLIB := -l$(LIB)
|
||||
|
||||
export LD_LIBRARY_PATH = $(LIBDIR)
|
||||
|
||||
CFLAGS += -std=gnu99
|
||||
CFLAGS += -O2
|
||||
CFLAGS += -g
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wextra
|
||||
CFLAGS += -march=native
|
||||
|
||||
CFLAGS += -DDEBUG_POOL # memory pools management
|
||||
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: aoc-c
|
||||
|
||||
ex1: aoc-c
|
||||
@$(TIME) aoc-c -d 5 -p 1 < $(INPUT)
|
||||
|
||||
ex2: aoc-c
|
||||
@$(TIME) aoc-c -d 5 -p 2 < $(INPUT)
|
||||
|
||||
clean:
|
||||
@rm -f aoc-c core*
|
||||
|
||||
.c:
|
||||
@echo compiling $<
|
||||
@$(CC) $(CFLAGS) $(LDFLAGS) -I $(INCDIR) $< $(LDLIB) -o $@
|
||||
39
2021/day02/README.txt
Normal file
39
2021/day02/README.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
--- Day 2: Dive! ---
|
||||
|
||||
Now, you need to figure out how to pilot this thing.
|
||||
|
||||
It seems like the submarine can take a series of commands like forward 1, down 2, or up 3:
|
||||
|
||||
forward X increases the horizontal position by X units.
|
||||
down X increases the depth by X units.
|
||||
up X decreases the depth by X units.
|
||||
|
||||
Note that since you're on a submarine, down and up affect your depth, and so they have the opposite result of what you might expect.
|
||||
|
||||
The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it's going. For example:
|
||||
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
|
||||
Your horizontal position and depth both start at 0. The steps above would then modify them as follows:
|
||||
|
||||
forward 5 adds 5 to your horizontal position, a total of 5.
|
||||
down 5 adds 5 to your depth, resulting in a value of 5.
|
||||
forward 8 adds 8 to your horizontal position, a total of 13.
|
||||
up 3 decreases your depth by 3, resulting in a value of 2.
|
||||
down 8 adds 8 to your depth, resulting in a value of 10.
|
||||
forward 2 adds 2 to your horizontal position, a total of 15.
|
||||
|
||||
After following these instructions, you would have a horizontal position of 15 and a depth of 10. (Multiplying these together produces 150.)
|
||||
|
||||
Calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth?
|
||||
|
||||
To begin, get your puzzle input.
|
||||
|
||||
Answer:
|
||||
|
||||
You can also [Shareon Mastodon] this puzzle.
|
||||
@@ -1,6 +1,6 @@
|
||||
#### My solutions to the [2020](https://adventofcode.com/2020) and [2021](https://adventofcode.com/2021) [advent of code](https://adventofcode.com).
|
||||
|
||||
#### My own rules for 2020 :
|
||||
#### My own rules :
|
||||
- **C** : Only *standard* libraries (for example, no external sort).
|
||||
- **bash**: Pure bash only: No external commands allowed (grep, sed, etc...).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user