2019 day 8 init
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,4 +13,5 @@ GTAGS
|
||||
FOO*
|
||||
BAR*
|
||||
QUAX*
|
||||
TOTO*
|
||||
TOTO*
|
||||
README.html
|
||||
|
1
2019/day08/EXAMPLE.txt
Normal file
1
2019/day08/EXAMPLE.txt
Normal file
@@ -0,0 +1 @@
|
||||
123456789012
|
1
2019/day08/INPUT.txt
Normal file
1
2019/day08/INPUT.txt
Normal file
File diff suppressed because one or more lines are too long
93
2019/day08/Makefile
Normal file
93
2019/day08/Makefile
Normal file
@@ -0,0 +1,93 @@
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
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 $@
|
52
2019/day08/README.org
Normal file
52
2019/day08/README.org
Normal file
@@ -0,0 +1,52 @@
|
||||
** --- Day 8: Space Image Format ---
|
||||
The Elves' spirits are lifted when they realize you have an opportunity
|
||||
to reboot one of their Mars rovers, and so they are curious if you would
|
||||
spend a brief sojourn on Mars. You land your ship near the rover.
|
||||
|
||||
When you reach the rover, you discover that it's already in the process
|
||||
of rebooting! It's just waiting for someone to enter a
|
||||
[[https://en.wikipedia.org/wiki/BIOS][BIOS]] password. The Elf
|
||||
responsible for the rover takes a picture of the password (your puzzle
|
||||
input) and sends it to you via the Digital Sending Network.
|
||||
|
||||
Unfortunately, images sent via the Digital Sending Network aren't
|
||||
encoded with any normal encoding; instead, they're encoded in a special
|
||||
Space Image Format. None of the Elves seem to remember why this is the
|
||||
case. They send you the instructions to decode it.
|
||||
|
||||
Images are sent as a series of digits that each represent the color of a
|
||||
single pixel. The digits fill each row of the image left-to-right, then
|
||||
move downward to the next row, filling rows top-to-bottom until every
|
||||
pixel of the image is filled.
|
||||
|
||||
Each image actually consists of a series of identically-sized /layers/
|
||||
that are filled in this way. So, the first digit corresponds to the
|
||||
top-left pixel of the first layer, the second digit corresponds to the
|
||||
pixel to the right of that on the same layer, and so on until the last
|
||||
digit, which corresponds to the bottom-right pixel of the last layer.
|
||||
|
||||
For example, given an image =3= pixels wide and =2= pixels tall, the
|
||||
image data =123456789012= corresponds to the following image layers:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
Layer 1: 123
|
||||
456
|
||||
|
||||
Layer 2: 789
|
||||
012
|
||||
#+END_EXAMPLE
|
||||
|
||||
The image you received is /=25= pixels wide and =6= pixels tall/.
|
||||
|
||||
To make sure the image wasn't corrupted during transmission, the Elves
|
||||
would like you to find the layer that contains the /fewest =0= digits/.
|
||||
On that layer, what is /the number of =1= digits multiplied by the
|
||||
number of =2= digits?/
|
||||
|
||||
To begin, [[file:8/input][get your puzzle input]].
|
||||
|
||||
Answer:
|
||||
|
||||
You can also [Shareon
|
||||
[[https://twitter.com/intent/tweet?text=%22Space+Image+Format%22+%2D+Day+8+%2D+Advent+of+Code+2019&url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F8&related=ericwastl&hashtags=AdventOfCode][Twitter]]
|
||||
[[javascript:void(0);][Mastodon]]] this puzzle.
|
Reference in New Issue
Block a user