2019 day 6 init

This commit is contained in:
2022-09-25 12:28:40 +02:00
parent 3d18e36ff4
commit 8783eca22c
4 changed files with 2488 additions and 0 deletions

11
2019/day06/EXAMPLE.txt Normal file
View File

@@ -0,0 +1,11 @@
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L

2306
2019/day06/INPUT.txt Normal file

File diff suppressed because it is too large Load Diff

93
2019/day06/Makefile Normal file
View File

@@ -0,0 +1,93 @@
# 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.html>.
#
# 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) -lm
LDLIB := -l$(LIB)
export LD_LIBRARY_PATH = $(LIBDIR)
CFLAGS += -std=gnu99
CFLAGS += -O2
CFLAGS += -g
# for gprof
#CFLAGS += -pg
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -march=native
# Next one may be useful for valgrind (some invalid instructions)
# CFLAGS += -mno-tbm
CFLAGS += -Wmissing-declarations
CFLAGS += -Wno-unused-result
CFLAGS += -DDEBUG_DEBUG # activate general debug (debug.c)
CFLAGS += -DDEBUG_POOL # memory pools management
VALGRIND := valgrind
VALGRINDFLAGS := --leak-check=full --show-leak-kinds=all --track-origins=yes \
--sigill-diagnostics=yes --quiet --show-error-list=yes
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 assembly memcheck memcheck1 memcheck2 ex1 ex2
all: README.org ex1 ex2
memcheck: memcheck1 memcheck2
memcheck1: aoc-c
@$(VALGRIND) $(VALGRINDFLAGS) aoc-c -p 1 < $(INPUT)
memcheck2: aoc-c
@$(VALGRIND) $(VALGRINDFLAGS) aoc-c -p 2 < $(INPUT)
@#@valgrind -s --track-origins=yes aoc-c -p 2 < $(INPUT)
compile: aoc-c
assembly: aoc-c.s
ex1: aoc-c
@$(TIME) aoc-c -p 1 < $(INPUT)
ex2: aoc-c
@$(TIME) aoc-c -p 2 < $(INPUT)
clean:
@rm -f aoc-c core* vgcore* gmon.out aoc-c.s aoc-c.i README.html
.c:
@echo compiling $<
@$(CC) $(CFLAGS) $(LDFLAGS) -I $(INCDIR) $< $(LDLIB) -o $@
# generate pre-processed file (.i) and assembler (.s)
%.i: %.c
@echo generating $@
@$(CC) -E $(CFLAGS) -I $(INCDIR) $< -o $@
%.s: %.c
@echo generating $@
@$(CC) -S -fverbose-asm $(CFLAGS) -I $(INCDIR) $< -o $@
# generate README.org from README.html (must cleanup !)
%.org: %.html
@echo generating $@. Cleanup before commit !
@pandoc $< -o $@

78
2019/day06/README.org Normal file
View File

@@ -0,0 +1,78 @@
** --- Day 6: Universal Orbit Map ---
You've landed at the Universal Orbit Map facility on Mercury. Because
navigation in space often involves transferring between orbits, the
orbit maps here are useful for finding efficient routes between, for
example, you and Santa. You download a map of the local orbits (your
puzzle input).
Except for the universal Center of Mass (=COM=), every object in space
is in orbit around exactly one other object. An
[[https://en.wikipedia.org/wiki/Orbit][orbit]] looks roughly like this:
#+BEGIN_EXAMPLE
\
\
|
|
AAA--> o o <--BBB
|
|
/
/
#+END_EXAMPLE
In this diagram, the object =BBB= is in orbit around =AAA=. The path
that =BBB= takes around =AAA= (drawn with lines) is only partly shown.
In the map data, this orbital relationship is written =AAA)BBB=, which
means "=BBB= is in orbit around =AAA=".
Before you use your map data to plot a course, you need to make sure it
wasn't corrupted during the download. To verify maps, the Universal
Orbit Map facility uses /orbit count checksums/ - the total number of
/direct orbits/ (like the one shown above) and /indirect orbits/.
Whenever =A= orbits =B= and =B= orbits =C=, then =A= /indirectly orbits/
=C=. This chain can be any number of objects long: if =A= orbits =B=,
=B= orbits =C=, and =C= orbits =D=, then =A= indirectly orbits =D=.
For example, suppose you have the following map:
#+BEGIN_EXAMPLE
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
#+END_EXAMPLE
Visually, the above map of orbits looks like this:
#+BEGIN_EXAMPLE
G - H J - K - L
/ /
COM - B - C - D - E - F
\
I
#+END_EXAMPLE
In this visual representation, when two objects are connected by a line,
the one on the right directly orbits the one on the left.
Here, we can count the total number of orbits as follows:
- =D= directly orbits =C= and indirectly orbits =B= and =COM=, a total
of =3= orbits.
- =L= directly orbits =K= and indirectly orbits =J=, =E=, =D=, =C=, =B=,
and =COM=, a total of =7= orbits.
- =COM= orbits nothing.
The total number of direct and indirect orbits in this example is =42=.
/What is the total number of direct and indirect orbits/ in your map
data?