diff --git a/2021/day12/EXAMPLE.txt b/2021/day12/EXAMPLE.txt new file mode 100644 index 0000000..6fd8c41 --- /dev/null +++ b/2021/day12/EXAMPLE.txt @@ -0,0 +1,7 @@ +start-A +start-b +A-c +A-b +b-d +A-end +b-end diff --git a/2021/day12/EXAMPLE2.txt b/2021/day12/EXAMPLE2.txt new file mode 100644 index 0000000..62cc714 --- /dev/null +++ b/2021/day12/EXAMPLE2.txt @@ -0,0 +1,10 @@ +dc-end +HN-start +start-kj +dc-start +dc-HN +LN-dc +HN-end +kj-sa +kj-HN +kj-dc diff --git a/2021/day12/EXAMPLE3.txt b/2021/day12/EXAMPLE3.txt new file mode 100644 index 0000000..65f3833 --- /dev/null +++ b/2021/day12/EXAMPLE3.txt @@ -0,0 +1,18 @@ +fs-end +he-DX +fs-he +start-DX +pj-DX +end-zg +zg-sl +zg-pj +pj-he +RW-he +fs-DX +pj-RW +zg-RW +start-pj +he-WI +zg-he +pj-fs +start-RW diff --git a/2021/day12/INPUT.txt b/2021/day12/INPUT.txt new file mode 100644 index 0000000..262ee68 --- /dev/null +++ b/2021/day12/INPUT.txt @@ -0,0 +1,19 @@ +lg-GW +pt-start +pt-uq +nx-lg +ve-GW +start-nx +GW-start +GW-nx +pt-SM +sx-GW +lg-end +nx-SM +lg-SM +pt-nx +end-ve +ve-SM +TG-uq +end-SM +SM-uq diff --git a/2021/day12/Makefile b/2021/day12/Makefile new file mode 100644 index 0000000..d90d573 --- /dev/null +++ b/2021/day12/Makefile @@ -0,0 +1,58 @@ +# 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 . +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +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 += -Wmissing-declarations +CFLAGS += -Wno-unused-result + +CFLAGS += -DDEBUG_DEBUG # activate general debug (debug.c) +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 ex1 ex2 + +all: ex1 ex2 + +compile: aoc-c + +ex1: aoc-c + @$(TIME) aoc-c -p 1 < $(INPUT) + +ex2: aoc-c + @$(TIME) aoc-c -p 2 < $(INPUT) + +clean: + @rm -f aoc-c core* + +.c: + @echo compiling $< + @$(CC) $(CFLAGS) $(LDFLAGS) -I $(INCDIR) $< $(LDLIB) -o $@ diff --git a/2021/day12/README.txt b/2021/day12/README.txt new file mode 100644 index 0000000..2606a50 --- /dev/null +++ b/2021/day12/README.txt @@ -0,0 +1,100 @@ +--- Day 12: Passage Pathing --- + +With your submarine's subterranean subsystems subsisting suboptimally, the only way you're getting out of this cave anytime soon is by finding a path yourself. Not just a path - the only way to know if you've found the best path is to find all of them. + +Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example: + +start-A +start-b +A-c +A-b +b-d +A-end +b-end + +This is a list of how all of the caves are connected. You start in the cave named start, and your destination is the cave named end. An entry like b-d means that cave b is connected to cave d - that is, you can move between them. + +So, the above cave system looks roughly like this: + + start + / \ +c--A-----b--d + \ / + end + +Your goal is to find the number of distinct paths that start at start, end at end, and don't visit small caves more than once. There are two types of caves: big caves (written in uppercase, like A) and small caves (written in lowercase, like b). It would be a waste of time to visit any small cave more than once, but big caves are large enough that it might be worth visiting them multiple times. So, all paths you find should visit small caves at most once, and can visit big caves any number of times. + +Given these rules, there are 10 paths through this example cave system: + +start,A,b,A,c,A,end +start,A,b,A,end +start,A,b,end +start,A,c,A,b,A,end +start,A,c,A,b,end +start,A,c,A,end +start,A,end +start,b,A,c,A,end +start,b,A,end +start,b,end + +(Each line in the above list corresponds to a single path; the caves visited by that path are listed in the order they are visited and separated by commas.) + +Note that in this cave system, cave d is never visited by any path: to do so, cave b would need to be visited twice (once on the way to cave d and a second time when returning from cave d), and since cave b is small, this is not allowed. + +Here is a slightly larger example: + +dc-end +HN-start +start-kj +dc-start +dc-HN +LN-dc +HN-end +kj-sa +kj-HN +kj-dc + +The 19 paths through it are as follows: + +start,HN,dc,HN,end +start,HN,dc,HN,kj,HN,end +start,HN,dc,end +start,HN,dc,kj,HN,end +start,HN,end +start,HN,kj,HN,dc,HN,end +start,HN,kj,HN,dc,end +start,HN,kj,HN,end +start,HN,kj,dc,HN,end +start,HN,kj,dc,end +start,dc,HN,end +start,dc,HN,kj,HN,end +start,dc,end +start,dc,kj,HN,end +start,kj,HN,dc,HN,end +start,kj,HN,dc,end +start,kj,HN,end +start,kj,dc,HN,end +start,kj,dc,end + +Finally, this even larger example has 226 paths through it: + +fs-end +he-DX +fs-he +start-DX +pj-DX +end-zg +zg-sl +zg-pj +pj-he +RW-he +fs-DX +pj-RW +zg-RW +start-pj +he-WI +zg-he +pj-fs +start-RW + +How many paths through this cave system are there that visit small caves at most once?