2020/23 (C) update Makefile, switch to .org readme

This commit is contained in:
2022-10-20 10:12:09 +02:00
parent b73db03da9
commit 6e4c64db39
3 changed files with 235 additions and 114 deletions

View File

@@ -1,30 +1,108 @@
INPUT := INPUT.txt # AOC daily Makefile - GNU make only.
SHELL := /bin/bash #
CFLAGS := -w -g # Copyright (C) 2021-2022 Bruno Raoult ("br")
#CFLAGS := -w -g -pg # Licensed under the GNU General Public License v3.0 or later.
#CFLAGS := -w -O3 # Some rights reserved. See COPYING.
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n" #
# 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) 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: memcheck: memcheck1 memcheck2
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
compile: ex1-c ex2-c memcheck1: aoc-c
@$(VALGRIND) $(VALGRINDFLAGS) aoc-c -p 1 < $(INPUT)
ex1: memcheck2: aoc-c
@$(TIME) ex1.bash < $(INPUT) 2>&1 @$(VALGRIND) $(VALGRINDFLAGS) aoc-c -p 2 < $(INPUT)
@#$(TIME) ex1-c 2020 < $(INPUT) 2>&1
ex2: compile: aoc-c
@$(TIME) ex2.bash < $(INPUT) 2>&1
@#$(TIME) ex1-c 30000000 < $(INPUT) 2>&1 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: 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: .c:
@$(MAKE) -C .. deploy @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

View File

@@ -1,94 +0,0 @@
--- Day 23: Crab Cups ---
The small crab challenges you to a game! The crab is going to mix up some cups, and you have to predict where they'll end up.
The cups will be arranged in a circle and labeled clockwise (your puzzle input). For example, if your labeling were 32415, there would be five cups in the circle; going clockwise around the circle from the first cup, the cups would be labeled 3, 2, 4, 1, 5, and then back to 3 again.
Before the crab starts, it will designate the first cup in your list as the current cup. The crab is then going to do 100 moves.
Each move, the crab does the following actions:
The crab picks up the three cups that are immediately clockwise of the current cup. They are removed from the circle; cup spacing is adjusted as necessary to maintain the circle.
The crab selects a destination cup: the cup with a label equal to the current cup's label minus one. If this would select one of the cups that was just picked up, the crab will keep subtracting one until it finds a cup that wasn't just picked up. If at any point in this process the value goes below the lowest value on any cup's label, it wraps around to the highest value on any cup's label instead.
The crab places the cups it just picked up so that they are immediately clockwise of the destination cup. They keep the same order as when they were picked up.
The crab selects a new current cup: the cup which is immediately clockwise of the current cup.
For example, suppose your cup labeling were 389125467. If the crab were to do merely 10 moves, the following changes would occur:
-- move 1 --
cups: (3) 8 9 1 2 5 4 6 7
pick up: 8, 9, 1
destination: 2
-- move 2 --
cups: 3 (2) 8 9 1 5 4 6 7
pick up: 8, 9, 1
destination: 7
-- move 3 --
cups: 3 2 (5) 4 6 7 8 9 1
pick up: 4, 6, 7
destination: 3
-- move 4 --
cups: 7 2 5 (8) 9 1 3 4 6
pick up: 9, 1, 3
destination: 7
-- move 5 --
cups: 3 2 5 8 (4) 6 7 9 1
pick up: 6, 7, 9
destination: 3
-- move 6 --
cups: 9 2 5 8 4 (1) 3 6 7
pick up: 3, 6, 7
destination: 9
-- move 7 --
cups: 7 2 5 8 4 1 (9) 3 6
pick up: 3, 6, 7
destination: 8
-- move 8 --
cups: 8 3 6 7 4 1 9 (2) 5
pick up: 5, 8, 3
destination: 1
-- move 9 --
cups: 7 4 1 5 8 3 9 2 (6)
pick up: 7, 4, 1
destination: 5
-- move 10 --
cups: (5) 7 4 1 8 3 9 2 6
pick up: 7, 4, 1
destination: 3
-- final --
cups: 5 (8) 3 7 4 1 9 2 6
In the above example, the cups' values are the labels as they appear moving clockwise around the circle; the current cup is marked with ( ).
After the crab is done, what order will the cups be in? Starting after the cup labeled 1, collect the other cups' labels clockwise into a single string with no extra characters; each number except 1 should appear exactly once. In the above example, after 10 moves, the cups clockwise from 1 are labeled 9, 2, 6, 5, and so on, producing 92658374. If the crab were to complete all 100 moves, the order after cup 1 would be 67384529.
Using your labeling, simulate 100 moves. What are the labels on the cups after cup 1?
Your puzzle answer was 75893264.
--- Part Two ---
Due to what you can only assume is a mistranslation (you're not exactly fluent in Crab), you are quite surprised when the crab starts arranging many cups in a circle on your raft - one million (1000000) in total.
Your labeling is still correct for the first few cups; after that, the remaining cups are just numbered in an increasing fashion starting from the number after the highest number in your list and proceeding one by one until one million is reached. (For example, if your labeling were 54321, the cups would be numbered 5, 4, 3, 2, 1, and then start counting up from 6 until one million is reached.) In this way, every number from one through one million is used exactly once.
After discovering where you made the mistake in translating Crab Numbers, you realize the small crab isn't going to do merely 100 moves; the crab is going to do ten million (10000000) moves!
The crab is going to hide your stars - one each - under the two cups that will end up immediately clockwise of cup 1. You can have them if you predict what the labels on those cups will be when the crab is finished.
In the above example (389125467), this would be 934001 and then 159792; multiplying these together produces 149245887792.
Determine which two cups will end up immediately clockwise of cup 1. What do you get if you multiply their labels together?
Your puzzle answer was 38162588308.
Both parts of this puzzle are complete! They provide two gold stars: **

137
2020/day23/README.org Normal file
View File

@@ -0,0 +1,137 @@
** --- Day 23: Crab Cups ---
The small crab challenges /you/ to a game! The crab is going to mix up
some cups, and you have to predict where they'll end up.
The cups will be arranged in a circle and labeled /clockwise/ (your
puzzle input). For example, if your labeling were =32415=, there would
be five cups in the circle; going clockwise around the circle from the
first cup, the cups would be labeled =3=, =2=, =4=, =1=, =5=, and then
back to =3= again.
Before the crab starts, it will designate the first cup in your list as
the /current cup/. The crab is then going to do /100 moves/.
Each /move/, the crab does the following actions:
- The crab picks up the /three cups/ that are immediately /clockwise/ of
the /current cup/. They are removed from the circle; cup spacing is
adjusted as necessary to maintain the circle.
- The crab selects a /destination cup/: the cup with a /label/ equal to
the /current cup's/ label minus one. If this would select one of the
cups that was just picked up, the crab will keep subtracting one until
it finds a cup that wasn't just picked up. If at any point in this
process the value goes below the lowest value on any cup's label, it
/wraps around/ to the highest value on any cup's label instead.
- The crab places the cups it just picked up so that they are
/immediately clockwise/ of the destination cup. They keep the same
order as when they were picked up.
- The crab selects a new /current cup/: the cup which is immediately
clockwise of the current cup.
For example, suppose your cup labeling were =389125467=. If the crab
were to do merely 10 moves, the following changes would occur:
#+BEGIN_EXAMPLE
-- move 1 --
cups: (3) 8 9 1 2 5 4 6 7
pick up: 8, 9, 1
destination: 2
-- move 2 --
cups: 3 (2) 8 9 1 5 4 6 7
pick up: 8, 9, 1
destination: 7
-- move 3 --
cups: 3 2 (5) 4 6 7 8 9 1
pick up: 4, 6, 7
destination: 3
-- move 4 --
cups: 7 2 5 (8) 9 1 3 4 6
pick up: 9, 1, 3
destination: 7
-- move 5 --
cups: 3 2 5 8 (4) 6 7 9 1
pick up: 6, 7, 9
destination: 3
-- move 6 --
cups: 9 2 5 8 4 (1) 3 6 7
pick up: 3, 6, 7
destination: 9
-- move 7 --
cups: 7 2 5 8 4 1 (9) 3 6
pick up: 3, 6, 7
destination: 8
-- move 8 --
cups: 8 3 6 7 4 1 9 (2) 5
pick up: 5, 8, 3
destination: 1
-- move 9 --
cups: 7 4 1 5 8 3 9 2 (6)
pick up: 7, 4, 1
destination: 5
-- move 10 --
cups: (5) 7 4 1 8 3 9 2 6
pick up: 7, 4, 1
destination: 3
-- final --
cups: 5 (8) 3 7 4 1 9 2 6
#+END_EXAMPLE
In the above example, the cups' values are the labels as they appear
moving clockwise around the circle; the /current cup/ is marked with
=( )=.
After the crab is done, what order will the cups be in? Starting /after
the cup labeled =1=/, collect the other cups' labels clockwise into a
single string with no extra characters; each number except =1= should
appear exactly once. In the above example, after 10 moves, the cups
clockwise from =1= are labeled =9=, =2=, =6=, =5=, and so on, producing
/=92658374=/. If the crab were to complete all 100 moves, the order
after cup =1= would be /=67384529=/.
Using your labeling, simulate 100 moves. /What are the labels on the
cups after cup =1=?/
Your puzzle answer was =75893264=.
** --- Part Two ---
Due to what you can only assume is a mistranslation (you're not exactly
fluent in Crab), you are quite surprised when the crab starts arranging
/many/ cups in a circle on your raft - /one million/ (=1000000=) in
total.
Your labeling is still correct for the first few cups; after that, the
remaining cups are just numbered in an increasing fashion starting from
the number after the highest number in your list and proceeding one by
one until one million is reached. (For example, if your labeling were
=54321=, the cups would be numbered =5=, =4=, =3=, =2=, =1=, and then
start counting up from =6= until one million is reached.) In this way,
every number from one through one million is used exactly once.
After discovering where you made the mistake in translating Crab
Numbers, you realize the small crab isn't going to do merely 100 moves;
the crab is going to do /ten million/ (=10000000=) moves!
The crab is going to hide your /stars/ - one each - under the /two cups
that will end up immediately clockwise of cup =1=/. You can have them if
you predict what the labels on those cups will be when the crab is
finished.
In the above example (=389125467=), this would be =934001= and then
=159792=; multiplying these together produces /=149245887792=/.
Determine which two cups will end up immediately clockwise of cup =1=.
/What do you get if you multiply their labels together?/
Your puzzle answer was =38162588308=.
Both parts of this puzzle are complete! They provide two gold stars: **