rename repo, subdir for yearly challenges

This commit is contained in:
2021-07-25 11:17:46 +02:00
parent 1806f79e14
commit 4a2318edc9
203 changed files with 212 additions and 1 deletions

743
2020/day05/INPUT.txt Normal file
View File

@@ -0,0 +1,743 @@
FBBFBFFRRL
BBFFBFBRRR
BFBBFFFLRR
FFBFFFBLLR
BFBBBBBRLR
FBFFFBFLRL
BFBBBBFLRR
FFBBBFBRRL
FBFBBFBLRL
BBFFFFBRRR
FBBBBBBRRR
FFBBFFBLLL
BBFFFFFRRR
BFFBFBFRLL
BFBFFFBRLR
FBBBFFFLRL
BFBFBBFLRL
BFFFBBBRRR
FBFFBBFRRL
BBFBFFFLLR
FBBFBBBRLL
BBFFBFBRLR
BFFFFFBRLL
BBFFFBBRRR
FBFFBBFRLL
FBBBBBFRRL
BBFBFFFLRL
BFBFBBBRLR
FBBFBBBRRR
BFBBBFFLLL
BFFFFFFLLL
BFBFFFBLRL
FBBFBBBLLR
BFFFBFBRLL
FFBFFBFLRL
FBFBFFBRLR
BBFFFBBLLR
BFFBFFFRRR
FBFFBBBLLL
BFBFFFFRLL
FBFBBFFRRL
BFBFBBBLLL
BFBFBFFRLR
FBBFBFFLRL
BFFFFBBLLR
FBBBFBBRRR
FBBBFFFLRR
FFBBBBFLRR
BFFFFFFRRL
BBFFFFFLRL
BFFBFBFRLR
FFBBBBBLLR
FBFFBFBRLL
BFBBFFBLRR
BFFFFBFLLR
FBBBBFFRLL
FBBBFFBLLR
BFFBBBFLLL
FFBFBBBLLL
BBFBFFFLRR
FBFBFFFLRL
BFFBBFFRRL
FBFBFBBLRR
FFBBFBBRLL
FFBBFBFRLL
BFFFBFBRRL
BFBBBBFRLL
BFFFBFBLLL
BFFFBBBLLL
FBBBBFBRRL
BFBBFFBRLL
BFBBFFFRLR
FFBBBBFLLL
FFBBFFBRLL
FFBFBFFLRR
FBBBFBBRRL
FFBFBBBLRR
BFBFFFFRRR
BFFBBFBRRR
BFFFFBBRLL
BFFFBBFRRR
BFFFBFBRLR
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LRR
BFBBFFFRRL
FFBBBBFLLR
FBBFFFBRLL
FBFBBBBLLL
FBFFFBFLRR
FBBBBFFLRL
BFBFFFBRRR
FBBFFBBRLL
FBFFFFBRRL

25
2020/day05/Makefile Normal file
View File

@@ -0,0 +1,25 @@
INPUT := INPUT.txt
SHELL := /bin/bash
CFLAGS := -w
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
all: ex1 ex2
compile: ex1-c ex2-c
ex1: ex1-c
@$(TIME) ex1.bash < $(INPUT) 2>&1
@$(TIME) ex1-c < $(INPUT) 2>&1
ex2: ex2-c
@$(TIME) ex2.bash < $(INPUT) 2>&1
@$(TIME) ex2-c < $(INPUT) 2>&1
clean:
@rm -f ex1-c ex2-c core
deploy:
@$(MAKE) -C .. deploy

12
2020/day05/OUTPUT Normal file
View File

@@ -0,0 +1,12 @@
ex1.bash : lines=743 max=838
time: 0:00.94 real, 0.62 user, 0.41 sys
ex1-c : lines=743 max=838
time: 0:00.00 real, 0.00 user, 0.00 sys
ex2.bash : lines=743 seat=714
time: 0:00.99 real, 0.65 user, 0.43 sys
ex2-c : lines=743 seat=714
time: 0:00.00 real, 0.00 user, 0.00 sys

62
2020/day05/README Normal file
View File

@@ -0,0 +1,62 @@
--- Day 5: Binary Boarding ---
You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.
Instead of zones or groups, this airline uses binary space partitioning to seat people. A seat might be specified like FBFBBFFRLR, where F means "front", B means "back", L means "left", and R means "right".
The first 7 characters will either be F or B; these specify exactly one of the 128 rows on the plane (numbered 0 through 127). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the front (0 through 63) or the back (64 through 127). The next letter indicates which half of that region the seat is in, and so on until you're left with exactly one row.
For example, consider just the first seven characters of FBFBBFFRLR:
Start by considering the whole range, rows 0 through 127.
F means to take the lower half, keeping rows 0 through 63.
B means to take the upper half, keeping rows 32 through 63.
F means to take the lower half, keeping rows 32 through 47.
B means to take the upper half, keeping rows 40 through 47.
B keeps rows 44 through 47.
F keeps rows 44 through 45.
The final F keeps the lower of the two, row 44.
The last three characters will be either L or R; these specify exactly one of the 8 columns of seats on the plane (numbered 0 through 7). The same process as above proceeds again, this time with only three steps. L means to keep the lower half, while R means to keep the upper half.
For example, consider just the last 3 characters of FBFBBFFRLR:
Start by considering the whole range, columns 0 through 7.
R means to take the upper half, keeping columns 4 through 7.
L means to take the lower half, keeping columns 4 through 5.
The final R keeps the upper of the two, column 5.
So, decoding FBFBBFFRLR reveals that it is the seat at row 44, column 5.
Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID 44 * 8 + 5 = 357.
Here are some other boarding passes:
BFFFBBFRRR: row 70, column 7, seat ID 567.
FFFBBBFRRR: row 14, column 7, seat ID 119.
BBFFBBFRLL: row 102, column 4, seat ID 820.
As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?
Your puzzle answer was 838.
--- Part Two ---
Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
It's a completely full flight, so your seat should be the only missing boarding pass in your list. However, there's a catch: some of the seats at the very front and back of the plane don't exist on this aircraft, so they'll be missing from your list as well.
Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.
What is the ID of your seat?
Your puzzle answer was 714.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
You can also [Share] this puzzle.

5
2020/day05/TEST.txt Normal file
View File

@@ -0,0 +1,5 @@
FBFBBFFRLR
BFFFBBFRRR
FFFBBBFRRR
BBFFBBFRLL
BBBBBBBRRR

35
2020/day05/ex1-c.c Normal file
View File

@@ -0,0 +1,35 @@
/* ex1-c: Advent2020 game, day 5/game 1
*/
#include <stdio.h>
#include <stdlib.h>
int str2int(str)
char *str;
{
int res=0;
while (*str) {
res <<= 1;
if (*str == 'B' || *str == 'R')
res ^= 1;
str++;
}
return res;
}
int main(ac, av)
char **av;
{
int max=0, cur, count=0;
char rowstr[80], colstr[80], line[80];
while (fgets(line, sizeof line, stdin)) {
count++;
sscanf(line, "%[FB]%[RL]", rowstr, colstr);
cur=(str2int(rowstr)<<3) ^ str2int(colstr);
if (cur > max)
max=cur;
}
printf("%s : lines=%d max=%d\n", *av, count, max);
exit (0);
}

33
2020/day05/ex1.bash Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
#
# ex1.bash: Advent2020 game, day 5/game 1.
CMD=${0##*/}
shopt -s extglob
function rownum() {
local val=${1%%???}
val=${val//F/0}
val=${val//B/1}
echo $((2#$val))
}
function colnum() {
local val=${1##???????}
val=${val//L/0}
val=${val//R/1}
echo $((2#$val))
}
declare -i lines=0 max=0 row col res
while read -r line; do
((lines++))
row=$(rownum "$line")
col=$(colnum "$line")
res=$((row * 8 + col))
((max < res)) && max=$res
#echo "row=$row col=$col res=$res"
done
printf "%s : lines=%d max=%d\n" "$CMD" "$lines" "$max"
exit 0

53
2020/day05/ex2-c.c Normal file
View File

@@ -0,0 +1,53 @@
/* ex2-c: Advent2020 game, day 5/game 2
*/
#include <stdio.h>
#include <stdlib.h>
static int seats[128][8];
int str2int(str)
char *str;
{
int res=0;
while (*str) {
res <<= 1;
if (*str == 'B' || *str == 'R')
res ^= 1;
str++;
}
return res;
}
void print_seats()
{
int i, j;
printf("seats:\n");
for (i=0; i<128; i++) {
printf("%03d : ", i);
for (j=0; j<8; ++j)
printf("%d ", seats[i][j]);
printf("\n");
}
}
int main(ac, av)
char **av;
{
int cur, count=0;
char rowstr[80], colstr[80], line[80];
int *pseats=(int *)seats;
while (fgets(line, sizeof line, stdin)) {
count++;
sscanf(line, "%[FB]%[RL]", rowstr, colstr);
cur=(str2int(rowstr)<<3) ^ str2int(colstr);
*(pseats+cur)=1;
}
for (; *pseats == 0; ++pseats)
;
for (; *pseats == 1; ++pseats)
;
printf("%s : lines=%d seat=%ld\n", *av, count, pseats-(int *)seats);
exit (0);
}

40
2020/day05/ex2.bash Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
#
# ex2.bash: Advent2020 game, day 5/game 2.
CMD=${0##*/}
shopt -s extglob
declare -a seats
function rownum() {
local val=${1%%???}
val=${val//F/0}
val=${val//B/1}
echo $((2#$val))
}
function colnum() {
local val=${1##???????}
val=${val//L/0}
val=${val//R/1}
echo $((2#$val))
}
declare -i lines=0 max=0 row col res next
while read -r line; do
((lines++))
row=$(rownum "$line")
col=$(colnum "$line")
res=$((row * 8 + col))
seats[$res]=1
#((max < res)) && max=$res
#echo "row=$row col=$col res=$res"
done
for seat in ${!seats[@]}; do
((next=seat+1))
[[ -v seats[$next] ]] || break
done
printf "%s : lines=%d seat=%d\n" "$CMD" "$lines" "$next"
exit 0