2020 day 21: init for C version
This commit is contained in:
@@ -1,30 +1,108 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w -g
|
||||
#CFLAGS := -w -g -pg
|
||||
#CFLAGS := -w -O3
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
# AOC daily Makefile - GNU make only.
|
||||
#
|
||||
# Copyright (C) 2021-2022 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
|
||||
BEAR := bear
|
||||
CCLSFILE:= compile_commands.json
|
||||
|
||||
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=gnu11
|
||||
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 deploy ex1 ex2
|
||||
.PHONY: clean all compile assembly memcheck memcheck1 memcheck2 ex1 ex2 ccls
|
||||
|
||||
all: ex1 ex2
|
||||
all: README.org ccls ex1 ex2
|
||||
|
||||
output:
|
||||
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
|
||||
memcheck: memcheck1 memcheck2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
memcheck1: aoc-c
|
||||
@$(VALGRIND) $(VALGRINDFLAGS) aoc-c -p 1 < $(INPUT)
|
||||
|
||||
ex1:
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@#$(TIME) ex1-c 2020 < $(INPUT) 2>&1
|
||||
memcheck2: aoc-c
|
||||
@$(VALGRIND) $(VALGRINDFLAGS) aoc-c -p 2 < $(INPUT)
|
||||
|
||||
ex2:
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@#$(TIME) ex1-c 30000000 < $(INPUT) 2>&1
|
||||
compile: aoc-c
|
||||
|
||||
cpp: aoc-c.i
|
||||
|
||||
assembly: aoc-c.s
|
||||
|
||||
ex1: aoc-c
|
||||
@$(TIME) ex1.bash -p 1 < $(INPUT)
|
||||
@$(TIME) aoc-c -p 1 < $(INPUT)
|
||||
|
||||
ex2: aoc-c
|
||||
@$(TIME) ex2.bash -p 2 < $(INPUT)
|
||||
@$(TIME) aoc-c -p 2 < $(INPUT)
|
||||
|
||||
ccls: $(CCLSFILE)
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
@rm -f aoc-c core* vgcore* gmon.out aoc-c.s aoc-c.i README.html compile_commands.json
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
||||
.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 $@
|
||||
|
||||
# generate compile_commands.json
|
||||
$(CCLSFILE): aoc-c.c Makefile
|
||||
$(BEAR) -- make clean compile
|
||||
|
||||
bear: clean
|
||||
@$(BEAR) -- make compile
|
||||
@touch .ccls-root
|
||||
|
@@ -1,45 +0,0 @@
|
||||
--- Day 21: Allergen Assessment ---
|
||||
|
||||
You reach the train's last stop and the closest you can get to your vacation island without getting wet. There aren't even any boats here, but nothing can stop you now: you build a raft. You just need a few days' worth of food for your journey.
|
||||
|
||||
You don't speak the local language, so you can't read any ingredients lists. However, sometimes, allergens are listed in a language you do understand. You should be able to use this information to determine which ingredient contains which allergen and work out which foods are safe to take with you on your trip.
|
||||
|
||||
You start by compiling a list of foods (your puzzle input), one food per line. Each line includes that food's ingredients list followed by some or all of the allergens the food contains.
|
||||
|
||||
Each allergen is found in exactly one ingredient. Each ingredient contains zero or one allergen. Allergens aren't always marked; when they're listed (as in (contains nuts, shellfish) after an ingredients list), the ingredient that contains each listed allergen will be somewhere in the corresponding ingredients list. However, even if an allergen isn't listed, the ingredient that contains that allergen could still be present: maybe they forgot to label it, or maybe it was labeled in a language you don't know.
|
||||
|
||||
For example, consider the following list of foods:
|
||||
|
||||
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
|
||||
trh fvjkl sbzzf mxmxvkd (contains dairy)
|
||||
sqjhc fvjkl (contains soy)
|
||||
sqjhc mxmxvkd sbzzf (contains fish)
|
||||
|
||||
The first food in the list has four ingredients (written in a language you don't understand): mxmxvkd, kfcds, sqjhc, and nhms. While the food might contain other allergens, a few allergens the food definitely contains are listed afterward: dairy and fish.
|
||||
|
||||
The first step is to determine which ingredients can't possibly contain any of the allergens in any food in your list. In the above example, none of the ingredients kfcds, nhms, sbzzf, or trh can contain an allergen. Counting the number of times any of these ingredients appear in any ingredients list produces 5: they all appear once each except sbzzf, which appears twice.
|
||||
|
||||
Determine which ingredients cannot possibly contain any of the allergens in your list. How many times do any of those ingredients appear?
|
||||
|
||||
Your puzzle answer was 2211.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: *
|
||||
--- Part Two ---
|
||||
|
||||
Now that you've isolated the inert ingredients, you should have enough information to figure out which ingredient contains which allergen.
|
||||
|
||||
In the above example:
|
||||
|
||||
mxmxvkd contains dairy.
|
||||
sqjhc contains fish.
|
||||
fvjkl contains soy.
|
||||
|
||||
Arrange the ingredients alphabetically by their allergen and separate them by commas to produce your canonical dangerous ingredient list. (There should not be any spaces in your canonical dangerous ingredient list.) In the above example, this would be mxmxvkd,sqjhc,fvjkl.
|
||||
|
||||
Time to stock your raft with supplies. What is your canonical dangerous ingredient list?
|
||||
|
||||
Answer:
|
||||
|
||||
Although it hasn't changed, you can still get your puzzle input.
|
||||
|
||||
You can also [Share] this puzzle.
|
76
2020/day21/README.org
Normal file
76
2020/day21/README.org
Normal file
@@ -0,0 +1,76 @@
|
||||
** --- Day 21: Allergen Assessment ---
|
||||
You reach the train's last stop and the closest you can get to your
|
||||
vacation island without getting wet. There aren't even any boats here,
|
||||
but nothing can stop you now: you build a raft. You just need a few
|
||||
days' worth of food for your journey.
|
||||
|
||||
You don't speak the local language, so you can't read any ingredients
|
||||
lists. However, sometimes, allergens are listed in a language you /do/
|
||||
understand. You should be able to use this information to determine
|
||||
which ingredient contains which allergen and work out which foods are
|
||||
safe to take with you on your trip.
|
||||
|
||||
You start by compiling a list of foods (your puzzle input), one food per
|
||||
line. Each line includes that food's /ingredients list/ followed by some
|
||||
or all of the allergens the food contains.
|
||||
|
||||
Each allergen is found in exactly one ingredient. Each ingredient
|
||||
contains zero or one allergen. /Allergens aren't always marked/; when
|
||||
they're listed (as in =(contains nuts, shellfish)= after an ingredients
|
||||
list), the ingredient that contains each listed allergen will be
|
||||
/somewhere in the corresponding ingredients list/. However, even if an
|
||||
allergen isn't listed, the ingredient that contains that allergen could
|
||||
still be present: maybe they forgot to label it, or maybe it was labeled
|
||||
in a language you don't know.
|
||||
|
||||
For example, consider the following list of foods:
|
||||
|
||||
#+begin_example
|
||||
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
|
||||
trh fvjkl sbzzf mxmxvkd (contains dairy)
|
||||
sqjhc fvjkl (contains soy)
|
||||
sqjhc mxmxvkd sbzzf (contains fish)
|
||||
#+end_example
|
||||
|
||||
The first food in the list has four ingredients (written in a language
|
||||
you don't understand): =mxmxvkd=, =kfcds=, =sqjhc=, and =nhms=. While
|
||||
the food might contain other allergens, a few allergens the food
|
||||
definitely contains are listed afterward: =dairy= and =fish=.
|
||||
|
||||
The first step is to determine which ingredients /can't possibly/
|
||||
contain any of the allergens in any food in your list. In the above
|
||||
example, none of the ingredients =kfcds=, =nhms=, =sbzzf=, or =trh= can
|
||||
contain an allergen. Counting the number of times any of these
|
||||
ingredients appear in any ingredients list produces /=5=/: they all
|
||||
appear once each except =sbzzf=, which appears twice.
|
||||
|
||||
Determine which ingredients cannot possibly contain any of the allergens
|
||||
in your list. /How many times do any of those ingredients appear?/
|
||||
|
||||
Your puzzle answer was =2211=.
|
||||
|
||||
** --- Part Two ---
|
||||
Now that you've isolated the inert ingredients, you should have enough
|
||||
information to figure out which ingredient contains which allergen.
|
||||
|
||||
In the above example:
|
||||
|
||||
- =mxmxvkd= contains =dairy=.
|
||||
- =sqjhc= contains =fish=.
|
||||
- =fvjkl= contains =soy=.
|
||||
|
||||
Arrange the ingredients /alphabetically by their allergen/ and separate
|
||||
them by commas to produce your /canonical dangerous ingredient list/.
|
||||
(There should /not be any spaces/ in your canonical dangerous ingredient
|
||||
list.) In the above example, this would be /=mxmxvkd,sqjhc,fvjkl=/.
|
||||
|
||||
Time to stock your raft with supplies. /What is your canonical dangerous
|
||||
ingredient list?/
|
||||
|
||||
Your puzzle answer was
|
||||
=vv,nlxsmb,rnbhjk,bvnkk,ttxvphb,qmkz,trmzkcfg,jpvz=.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||
|
||||
At this point, all that is left is for you to [[/2020][admire your
|
||||
Advent calendar]].
|
Reference in New Issue
Block a user