init AoC 2022, cleanup useless files
This commit is contained in:
109
2022/day01/Makefile
Normal file
109
2022/day01/Makefile
Normal file
@@ -0,0 +1,109 @@
|
||||
# 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 assembly memcheck memcheck1 memcheck2 ex1 ex2 ccls bear org
|
||||
|
||||
all: README.org ccls 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
|
||||
|
||||
cpp: aoc-c.i
|
||||
|
||||
assembly: aoc-c.s
|
||||
|
||||
ex1: aoc-c
|
||||
@$(TIME) aoc-c -p 1 < $(INPUT)
|
||||
|
||||
ex2: aoc-c
|
||||
@$(TIME) aoc-c -p 2 < $(INPUT)
|
||||
|
||||
ccls: $(CCLSFILE)
|
||||
|
||||
clean:
|
||||
@rm -f aoc-c core* vgcore* gmon.out aoc-c.s aoc-c.i README.html compile_commands.json
|
||||
|
||||
.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: README.org
|
||||
|
||||
%.org: %.html
|
||||
@echo generating $@. Cleanup before commit !
|
||||
@pandoc $< -o $@
|
||||
|
||||
# generate compile_commands.json
|
||||
$(CCLSFILE): aoc-c.c Makefile
|
||||
$(BEAR) -- make clean compile
|
||||
|
||||
bear: clean
|
||||
@touch .ccls-root
|
||||
@$(BEAR) -- make compile
|
73
2022/day01/README.org
Normal file
73
2022/day01/README.org
Normal file
@@ -0,0 +1,73 @@
|
||||
** --- Day 1: Calorie Counting ---
|
||||
Santa's reindeer typically eat regular reindeer food, but they need a
|
||||
lot of [[/2018/day/25][magical energy]] to deliver presents on
|
||||
Christmas. For that, their favorite snack is a special type of /star/
|
||||
fruit that only grows deep in the jungle. The Elves have brought you on
|
||||
their annual expedition to the grove where the fruit grows.
|
||||
|
||||
To supply enough magical energy, the expedition needs to retrieve a
|
||||
minimum of /fifty stars/ by December 25th. Although the Elves assure you
|
||||
that the grove has plenty of fruit, you decide to grab any fruit you see
|
||||
along the way, just in case.
|
||||
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on
|
||||
each day in the Advent calendar; the second puzzle is unlocked when you
|
||||
complete the first. Each puzzle grants /one star/. Good luck!
|
||||
|
||||
The jungle must be too overgrown and difficult to navigate in vehicles
|
||||
or access from the air; the Elves' expedition traditionally goes on
|
||||
foot. As your boats approach land, the Elves begin taking inventory of
|
||||
their supplies. One important consideration is food - in particular, the
|
||||
number of /Calories/ each Elf is carrying (your puzzle input).
|
||||
|
||||
The Elves take turns writing down the number of Calories contained by
|
||||
the various meals, snacks, rations, etc. that they've brought with them,
|
||||
one item per line. Each Elf separates their own inventory from the
|
||||
previous Elf's inventory (if any) by a blank line.
|
||||
|
||||
For example, suppose the Elves finish writing their items' Calories and
|
||||
end up with the following list:
|
||||
|
||||
#+begin_example
|
||||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
||||
#+end_example
|
||||
|
||||
This list represents the Calories of the food carried by five Elves:
|
||||
|
||||
- The first Elf is carrying food with =1000=, =2000=, and =3000=
|
||||
Calories, a total of =6000= Calories.
|
||||
- The second Elf is carrying one food item with =4000= Calories.
|
||||
- The third Elf is carrying food with =5000= and =6000= Calories, a
|
||||
total of =11000= Calories.
|
||||
- The fourth Elf is carrying food with =7000=, =8000=, and =9000=
|
||||
Calories, a total of =24000= Calories.
|
||||
- The fifth Elf is carrying one food item with =10000= Calories.
|
||||
|
||||
In case the Elves get hungry and need extra snacks, they need to know
|
||||
which Elf to ask: they'd like to know how many Calories are being
|
||||
carried by the Elf carrying the /most/ Calories. In the example above,
|
||||
this is /=24000=/ (carried by the fourth Elf).
|
||||
|
||||
Find the Elf carrying the most Calories. /How many total Calories is
|
||||
that Elf carrying?/
|
||||
|
||||
To begin, [[file:1/input][get your puzzle input]].
|
||||
|
||||
Answer:
|
||||
|
||||
You can also [Shareon
|
||||
[[https://twitter.com/intent/tweet?text=%22Calorie+Counting%22+%2D+Day+1+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F1&related=ericwastl&hashtags=AdventOfCode][Twitter]]
|
||||
[[javascript:void(0);][Mastodon]]] this puzzle.
|
Reference in New Issue
Block a user