Initial Commit - days 01-12

This commit is contained in:
2020-12-21 14:58:15 +01:00
commit 11844d1904
131 changed files with 16060 additions and 0 deletions

98
day11/INPUT.txt Normal file
View File

@@ -0,0 +1,98 @@
LLLLL.LLLL.LLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLL.LLLLLLLLLLLL.LL.LLLLLLLLL.LLL
LLLLLLLL.L.LLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLL.LLL.LLL.LLLLL.LLLL.L..LLLLLL.LLLLLLLL
LLLLLLLLLLLLLLLLLLLLLLLLLLL.LL.LLLLLLLLLLLLLL..LLLLLLLL.L.LLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLL
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLL.LLLLL.LL
LLLLLLLLLL.LLLLL.LLL.LLLLLL.LLLLLLL..LLLLLLLL.LLLLLLLLL.LLLLLLL.LLLLL.LLLLLL..LLLLLL.LLLLLLLL
LLLLLLLLLL..LLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLL.LL.LLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLL.L
L.LL.L...LL......LLL........LL...L.L.L...L...L....L........LL......L.............LL..LL.L...L
LLLLLLLLL..LL.LLLL.L.LL.LLL.LLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLL
LLLLLL.LLL.LLLLLLL.LLLLLLLL.LLLLLLL.LLLLLL.LL.LLLLLLLLL.L.LLLLL.LLLLL.L.LLLL.LLLLLLLLLLLLLLLL
LLLLLLLLLL.L.LLLLLLLLL.LLL..LLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLL.LLLLL.LLLLLL.LLLLLLL.LLLLLLLL
LLLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLLLL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LLLLLLL.LLL.L.LLLL.LLLLLLLLL.LLLLLLLL
..L...LLL..LL...L.L.LLLL..L.L...L..LLL...L...LLL.....L.....LL.L....L....L.L..L.L.L....L..L..L
LLLLLLLLLLLLLLLLLL.LLL.LLLL.LLLLLLL.LLLLLLLLL.LL.LLLL.LLLLL.L.L.LLLLL.LLLLLL.LLL.LLL.LLLLLL.L
LLLLLLLLLL.LLLLLLLLLLLLLLLL.LL.LL.L.LLLLLLLLL..LL.LLLLL.LLLLLLLLLLL.L.L.L.LL.LLLLLLL.LLLLLLLL
LLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLL.LL.LLLLLLLLLLLLLLLLLLL.LL.LL.L.LLLLL.LLLLLLLLL.LLLL.LLLLLLLL
LLLLLLLLLL..LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLL.L.LLLLLLL.LLLLLLLLLLLL.LLLLLLL..LLLLLLL
LL.LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLL.LLLLLL.LLL..LL.LLLLLLLL

30
day11/Makefile Normal file
View File

@@ -0,0 +1,30 @@
INPUT := INPUT.txt
SHELL := /bin/bash
#CFLAGS := -w -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"
export PATH := .:$(PATH)
.PHONY: clean all compile deploy ex1 ex2
all: ex1 ex2
output:
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
compile: ex1-c ex2-c
ex1: ex1-c
@#$(TIME) ex1-slow.bash < $(INPUT) 2>&1
@$(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

16
day11/OUTPUT Normal file
View File

@@ -0,0 +1,16 @@
ex1.bash : res=2386
time: 0:41.94 real, 41.86 user, 0.03 sys
context-switch: 4503+14, page-faults: 0+1329
ex1-c : res=2386
time: 0:00.01 real, 0.01 user, 0.00 sys
context-switch: 1+1, page-faults: 0+91
ex2.bash : res=2091
time: 1:20.09 real, 80.00 user, 0.03 sys
context-switch: 8232+13, page-faults: 0+1721
ex2-c : res=2091
time: 0:00.01 real, 0.01 user, 0.00 sys
context-switch: 2+1, page-faults: 0+91

219
day11/README Normal file
View File

@@ -0,0 +1,219 @@
--- Day 11: Seating System ---
Your plane lands with plenty of time to spare. The final leg of your journey is a ferry that goes directly to the tropical island where you can finally start your vacation. As you reach the waiting area to board the ferry, you realize you're so early, nobody else has even arrived yet!
By modeling the process people use to choose (or abandon) their seat in the waiting area, you're pretty sure you can predict the best place to sit. You make a quick map of the seat layout (your puzzle input).
The seat layout fits neatly on a grid. Each position is either floor (.), an empty seat (L), or an occupied seat (#). For example, the initial seat layout might look like this:
L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL
Now, you just need to model the people who will be arriving shortly. Fortunately, people are entirely predictable and always follow a simple set of rules. All decisions are based on the number of occupied seats adjacent to a given seat (one of the eight positions immediately up, down, left, right, or diagonal from the seat). The following rules are applied to every seat simultaneously:
If a seat is empty (L) and there are no occupied seats adjacent to it, the seat becomes occupied.
If a seat is occupied (#) and four or more seats adjacent to it are also occupied, the seat becomes empty.
Otherwise, the seat's state does not change.
Floor (.) never changes; seats don't move, and nobody sits on the floor.
After one round of these rules, every seat in the example layout becomes occupied:
#.##.##.##
#######.##
#.#.#..#..
####.##.##
#.##.##.##
#.#####.##
..#.#.....
##########
#.######.#
#.#####.##
After a second round, the seats with four or more occupied adjacent seats become empty again:
#.LL.L#.##
#LLLLLL.L#
L.L.L..L..
#LLL.LL.L#
#.LL.LL.LL
#.LLLL#.##
..L.L.....
#LLLLLLLL#
#.LLLLLL.L
#.#LLLL.##
This process continues for three more rounds:
#.##.L#.##
#L###LL.L#
L.#.#..#..
#L##.##.L#
#.##.LL.LL
#.###L#.##
..#.#.....
#L######L#
#.LL###L.L
#.#L###.##
#.#L.L#.##
#LLL#LL.L#
L.L.L..#..
#LLL.##.L#
#.LL.LL.LL
#.LL#L#.##
..L.L.....
#L#LLLL#L#
#.LLLLLL.L
#.#L#L#.##
#.#L.L#.##
#LLL#LL.L#
L.#.L..#..
#L##.##.L#
#.#L.LL.LL
#.#L#L#.##
..L.L.....
#L#L##L#L#
#.LLLLLL.L
#.#L#L#.##
At this point, something interesting happens: the chaos stabilizes and further applications of these rules cause no seats to change state! Once people stop moving around, you count 37 occupied seats.
Simulate your seating area by applying the seating rules repeatedly until no seats change state. How many seats end up occupied?
Your puzzle answer was 2386.
--- Part Two ---
As soon as people start to arrive, you realize your mistake. People don't just care about adjacent seats - they care about the first seat they can see in each of those eight directions!
Now, instead of considering just the eight immediately adjacent seats, consider the first seat in each of those eight directions. For example, the empty seat below would see eight occupied seats:
.......#.
...#.....
.#.......
.........
..#L....#
....#....
.........
#........
...#.....
The leftmost empty seat below would only see one empty seat, but cannot see any of the occupied ones:
.............
.L.L.#.#.#.#.
.............
The empty seat below would see no occupied seats:
.##.##.
#.#.#.#
##...##
...L...
##...##
#.#.#.#
.##.##.
Also, people seem to be more tolerant than you expected: it now takes five or more visible occupied seats for an occupied seat to become empty (rather than four or more from the previous rules). The other rules still apply: empty seats that see no occupied seats become occupied, seats matching no rule don't change, and floor never changes.
Given the same starting layout as above, these new rules cause the seating area to shift around as follows:
L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL
#.##.##.##
#######.##
#.#.#..#..
####.##.##
#.##.##.##
#.#####.##
..#.#.....
##########
#.######.#
#.#####.##
#.LL.LL.L#
#LLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLL#
#.LLLLLL.L
#.LLLLL.L#
#.L#.##.L#
#L#####.LL
L.#.#..#..
##L#.##.##
#.##.#L.##
#.#####.#L
..#.#.....
LLL####LL#
#.L#####.L
#.L####.L#
#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##LL.LL.L#
L.LL.LL.L#
#.LLLLL.LL
..L.L.....
LLLLLLLLL#
#.LLLLL#.L
#.L#LL#.L#
#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##L#.#L.L#
L.L#.#L.L#
#.L####.LL
..#.#.....
LLL###LLL#
#.LLLLL#.L
#.L#LL#.L#
#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##L#.#L.L#
L.L#.LL.L#
#.LLLL#.LL
..#.L.....
LLL###LLL#
#.LLLLL#.L
#.L#LL#.L#
Again, at this point, people stop shifting around and the seating area reaches equilibrium. Once this occurs, you count 26 occupied seats.
Given the new visibility method and the rule change for occupied seats becoming empty, once equilibrium is reached, how many seats end up occupied?
Your puzzle answer was 2091.
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.

10
day11/TEST.txt Normal file
View File

@@ -0,0 +1,10 @@
L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL

187
day11/ex1-c.c Normal file
View File

@@ -0,0 +1,187 @@
/* ex1-c: Advent2020 game, day 10/game 1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct seats {
char status;
unsigned neighbours;
};
struct plane {
unsigned nrow;
unsigned ncol;
unsigned size;
unsigned last;
unsigned seated;
struct seats *seats;
};
#define BLOCKSIZE (10*1024) /* number of elements for realloc() */
void print_count(plane)
struct plane *plane;
{
unsigned i, psize=plane->last;
unsigned ncols=plane->ncol;
struct seats *ptr=plane->seats;
for (i=0; i<psize; ++i) {
if (i>0 && !(i%ncols)) {
putchar('\n');
}
printf("%2d ", (ptr+i)->neighbours);
}
putchar('\n');
}
void print_seats(plane)
struct plane *plane;
{
unsigned i, psize=plane->last;
unsigned ncols=plane->ncol, nrow=plane->nrow;
struct seats *ptr=plane->seats;
fprintf(stderr, "PLANE: address=%p seat=%p rows=%d cols=%d size=%d\n",
plane, ptr, nrow, ncols, psize);
for (i=0; i<psize; ++i) {
if (i>0 && !(i%ncols)) {
putchar('\n');
}
printf("%c ", (ptr+i)->status);
}
putchar('\n');
}
void reset_seats(plane)
struct plane *plane;
{
unsigned i, last=plane->last;
struct seats *seat=plane->seats;
for (i=0; i<last; ++i, ++seat)
seat->neighbours=0;
}
struct plane *add_row(plane, c)
struct plane *plane;
char *c;
{
unsigned size;
if (!plane) {
plane=malloc(sizeof(struct plane));
plane->seats=malloc(sizeof(struct seats)*BLOCKSIZE);
plane->size=BLOCKSIZE;
plane->ncol=strlen(c)-1;
plane->last=0;
}
size=plane->size;
while (*c) {
if (*c != '\n') {
if (plane->last == size) {
size+=BLOCKSIZE;
plane->size=size;
plane->seats=realloc(plane->seats, sizeof(struct seats)*size);
}
plane->seats[plane->last].status=*c;
plane->last++;
plane->nrow=plane->last/plane->ncol;
}
c++;
}
//sscanf(line, "%d", &val);
return plane;
}
int sit(plane)
struct plane *plane;
{
unsigned changed=0, cur, seated=0;
unsigned last=plane->last;
struct seats *seats=plane->seats;
for (cur=0; cur<last; ++cur) {
switch (seats[cur].status) {
case '.':
break;
case '#':
if (seats[cur].neighbours >= 4) {
seats[cur].status='L';
changed++;
} else {
seated++;
}
break;
case 'L':
if (seats[cur].neighbours == 0) {
seats[cur].status='#';
changed++;
seated++;
}
break;
}
}
plane->seated=seated;
return changed;
}
int calc(plane)
struct plane *plane;
{
unsigned row, col, cur;
unsigned last=plane->last;
unsigned cols=plane->ncol;
unsigned rows=plane->nrow;
struct seats *seats=plane->seats;
for (cur=0; cur<last; ++cur) {
row=cur/cols;
col=cur%cols;
if (seats[cur].status == '#') {
if (row > 0) {
seats[cur - cols].neighbours++;
if (col > 0)
seats[cur - cols - 1].neighbours++;
if (col < (cols-1))
seats[cur - cols + 1].neighbours++;
}
if (col > 0) {
seats[cur - 1].neighbours++;
if (row < (rows-1))
seats[cur + cols - 1].neighbours++;
}
if (col < (cols-1)) {
seats[cur + 1].neighbours++;
if (row < (rows-1))
seats[cur + cols + 1].neighbours++;
}
if (row < (rows-1))
seats[cur + cols].neighbours++;
}
}
return 1;
}
int main(ac, av)
int ac;
char **av;
{
char line[512];
struct plane *plane=NULL;
while (fgets(line, sizeof line, stdin)) {
plane=add_row(plane, line);
}
do {
reset_seats(plane);
calc(plane);
} while (sit(plane) > 0);
printf("%s : res=%d\n", *av, plane->seated);
exit (0);
}

175
day11/ex1-slow.bash Executable file
View File

@@ -0,0 +1,175 @@
#!/bin/bash
#
# ex1.bash: Advent2020 game, day 10/game 1.
CMD=${0##*/}
shopt -s extglob
declare -a rowsstr rows
declare -i RLENGTH
declare -i NROWS
declare floor
function adj() {
local -i r="$1" n="$2" c="$3" count=0
local -a prow=(${rows[r-1]})
local -a row=(${rows[r]})
local -a nrow=(${rows[r+1]})
#echo
#echo p="${prow[*]}"
#echo r="${row[*]}"
#echo p1=${prow[1]}
#echo r1=${row[1]}
#return
#echo r="$row"
#echo n="$nrow"
if (( row[n] == 0 )); then
echo "-1"
return
fi
for ((i=n-1; i<n+2; ++i)); do
#echo p: $i ${prow:i:1}
(( prow[i] == c )) && ((count++))
#echo p: $i ${nrow:i:1}
(( nrow[i] == c )) && ((count++))
done
(( row[n-1] == c )) && ((count++))
(( row[n+1] == c )) && ((count++))
echo "$count"
}
function run() {
local -i c r
local -a row
local -a new
local -i cur
local -i changed=1
local -i loop=0 seated=0
#echo "$floor;"
while ((changed > 0)); do
changed=0
seated=0
for ((r=1; r<=NROWS; ++r)); do
row=(${rows[r]})
newrow=(0)
for ((c=1; c<=RLENGTH; ++c)); do
newrow+=("${row[c]}")
#if ((r == 1 && c ==1 )); then
# printf "r1c1: %s %d\n" "${row[c]}" $(adj $r $c 2)
#fi
case ${row[c]} in
0) continue
;;
1) if (( $(adj $r $c 2) == 0 )); then
((++changed))
newrow[c]=2
fi
#printf "[%d][%d]: %s %s %d\n" $r $c "${row[c]}" "${newrow[c]}" $(adj $r $c 2)
;;
2) if (( $(adj $r $c 2) >= 4 )); then
((++changed))
newrow[c]=1
fi
;;
esac
((newrow[c] == 2)) && ((seated++))
done
newrow+=(0)
new[$r]="${newrow[*]}"
#echo "${newrow[*]} ;"
done
#echo "$floor"
#echo "${new[*]}"
#echo changed=$changed
((loop++))
#echo loop="$loop"
for ((r=1; r<=NROWS; ++r)); do
rows[r]="${new[$r]}"
done
#printf "loop %d seated %d\n" "$loop" "$seated" >&2
done
echo "$seated"
}
readarray -t rowsstr
for ((i=0; i<${#rowsstr[@]}; ++i)); do
rowsstr[i]=${rowsstr[i]//./0}
rowsstr[i]=${rowsstr[i]//L/1}
#echo "${rowsstr[i]}"
done
RLENGTH=${#rowsstr[0]}
NROWS=${#rowsstr[@]}
#echo "L=$RLENGTH N=$NROWS"
# add floor rows at beginning and end
printf -v floor '%0.s0 ' $(seq 1 $((RLENGTH+2)))
#echo floor="$floor"
#echo floor="$floor"
#echo
#for ((i=0; i<${#rowsstr[@]}; ++i)); do
# rowsstr[i]=0${rowsstr[i]}0
# echo "${rowsstr[i]}"
#done
# split arrays in integers
for ((r=0; r<NROWS; ++r)); do
srow="${rowsstr[r]}"
nrow=(0)
for ((c=0 ; c<=RLENGTH+1 ; c++ )); do
nrow+=("${srow:c:1}")
done
nrow+=(0)
rows[r]="${nrow[*]}"
done
rows=("$floor" "${rows[@]}" "$floor")
#for ((r=0; r<=NROWS+1; ++r)); do
# printf "row %d: %s\n" $r "${rows[r]}"
#done
#for ((r=0; r<=NROWS+1; ++r)); do
# echo "row $r=${rows[r]}"
#done
#echo -n "adj 1 1 2: "
#adj 1 1 2
res=$(run)
printf "%s: res=%d\n" "$CMD" "$res"
exit 0
echo -n "adj 1 1 2: "
adj 1 1 2
echo -n "adj 1 2 1: "
adj 1 2 1
echo -n "adj 1 3 2: "
adj 1 3 2
echo -n "adj 1 4 1: "
adj 1 4 1
exit 0
numbers=(0 "${numbers[@]}")
size=${#numbers[@]}
((last=${numbers[size-1]}+3))
numbers+=("$last")
((size++))
#echo S="$size" $last "[${numbers[@]}]"
# last
declare -a res=(0 0 0 0)
for ((i=1; i<size; ++i)); do
prev=${numbers[$i-1]}
cur=${numbers[$i]}
diff=$((cur-prev))
((res[diff]++))
done
res1="${res[1]}"
res3="${res[3]}"
printf "%s : diff1=%d diff2=%d res=%d\n" "$CMD" "$res1" "$res3" $((res1*res3))
exit 0

103
day11/ex1.bash Executable file
View File

@@ -0,0 +1,103 @@
#!/bin/bash
#
# ex1.bash: Advent2020 game, day 11/game 1.
CMD=${0##*/}
shopt -s extglob
declare -a rowsstr rows
declare -i NCOLS NROWS
declare zeroed
function run() {
local -i c r cell
local -a seats control
local -i changed=1
local -i loop=0 seated=0
read -ra seats <<< "${rows[*]}"
while ((changed > 0)); do
changed=0
seated=0
read -ra control <<< "$zeroed"
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
((cell=r*NCOLS+c))
if (( seats[cell] == 2 )); then
((control[(r)*(NCOLS+2) + c ]++))
((control[(r)*(NCOLS+2) + c+1]++))
((control[(r)*(NCOLS+2) + c+2]++))
((control[(r+1)*(NCOLS+2) + c ]++))
# this cell: control[(r+1)*(NCOLS+2) + c+1]
((control[(r+1)*(NCOLS+2) + c+2]++))
((control[(r+2)*(NCOLS+2) + c ]++))
((control[(r+2)*(NCOLS+2) + c+1]++))
((control[(r+2)*(NCOLS+2) + c+2]++))
fi
done
done
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
((cell=r*NCOLS+c))
((ccell=(r+1)*(NCOLS+2) + c+1))
case ${seats[cell]} in
0) continue
;;
1) if (( control[ccell] == 0 )); then
((++changed))
seats[cell]=2
fi
;;
2) if (( control[ccell] >= 4 )); then
((++changed))
seats[cell]=1
fi
esac
#printf "r=%d c=%d cell=%d val=%s\n" "$r" "$c" "$cell" "${seats[cell]}"
done
#echo
done
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
((cell=(r*(NCOLS))+c))
((seats[cell] == 2)) && ((seated++))
done
done
((loop++))
done
echo "$seated"
}
readarray -t rowsstr
for ((i=0; i<${#rowsstr[@]}; ++i)); do
rowsstr[i]=${rowsstr[i]//./0}
rowsstr[i]=${rowsstr[i]//L/1}
rowsstr[i]=${rowsstr[i]//#/2}
done
NCOLS=${#rowsstr[0]}
NROWS=${#rowsstr[@]}
printf -v zeroed '%0.s0 ' $(seq 1 $(((NCOLS+2)*(NROWS+2))))
# split arrays in integers
for ((r=0; r<NROWS; ++r)); do
srow="${rowsstr[r]}"
nrow=()
for ((c=0 ; c<NCOLS ; c++ )); do
nrow+=("${srow:c:1}")
done
rows[r]="${nrow[*]}"
done
res=$(run)
printf "%s : res=%d\n" "$CMD" "$res"
exit 0

219
day11/ex2-c.c Normal file
View File

@@ -0,0 +1,219 @@
/* ex1-c: Advent2020 game, day 10/game 1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct seats {
char status;
unsigned neighbours;
};
struct plane {
unsigned nrow;
unsigned ncol;
unsigned size;
unsigned last;
unsigned seated;
struct seats *seats;
};
#define BLOCKSIZE (10*1024) /* number of elements for realloc() */
void print_count(plane)
struct plane *plane;
{
unsigned i, psize=plane->last;
unsigned ncols=plane->ncol;
struct seats *ptr=plane->seats;
for (i=0; i<psize; ++i) {
if (i>0 && !(i%ncols)) {
putchar('\n');
}
printf("%2d ", (ptr+i)->neighbours);
}
putchar('\n');
}
void print_seats(plane)
struct plane *plane;
{
unsigned i, psize=plane->last;
unsigned ncols=plane->ncol, nrow=plane->nrow;
struct seats *ptr=plane->seats;
fprintf(stderr, "PLANE: address=%p seat=%p rows=%d cols=%d size=%d\n",
plane, ptr, nrow, ncols, psize);
for (i=0; i<psize; ++i) {
if (i>0 && !(i%ncols)) {
putchar('\n');
}
printf("%c ", (ptr+i)->status);
}
putchar('\n');
}
void reset_seats(plane)
struct plane *plane;
{
unsigned i, last=plane->last;
struct seats *seat=plane->seats;
for (i=0; i<last; ++i, ++seat)
seat->neighbours=0;
}
struct plane *add_row(plane, c)
struct plane *plane;
char *c;
{
unsigned size;
if (!plane) {
plane=malloc(sizeof(struct plane));
plane->seats=malloc(sizeof(struct seats)*BLOCKSIZE);
plane->size=BLOCKSIZE;
plane->ncol=strlen(c)-1;
plane->last=0;
}
size=plane->size;
while (*c) {
if (*c != '\n') {
if (plane->last == size) {
size+=BLOCKSIZE;
plane->size=size;
plane->seats=realloc(plane->seats, sizeof(struct seats)*size);
}
plane->seats[plane->last].status=*c;
plane->last++;
plane->nrow=plane->last/plane->ncol;
}
c++;
}
return plane;
}
int sit(plane)
struct plane *plane;
{
unsigned changed=0, cur, seated=0;
unsigned last=plane->last;
struct seats *seats=plane->seats;
for (cur=0; cur<last; ++cur) {
switch (seats[cur].status) {
case '.':
break;
case '#':
if (seats[cur].neighbours >= 5) {
seats[cur].status='L';
changed++;
} else {
seated++;
}
break;
case 'L':
if (seats[cur].neighbours == 0) {
seats[cur].status='#';
changed++;
seated++;
}
break;
}
}
plane->seated=seated;
return changed;
}
int calc(plane)
struct plane *plane;
{
unsigned row, col, cur;
unsigned last=plane->last;
int cols=plane->ncol;
int rows=plane->nrow;
int c, r;
struct seats *seats=plane->seats;
reset_seats(plane);
for (cur=0; cur<last; ++cur) {
if (seats[cur].status == '#') {
row=cur/cols;
col=cur%cols;
// up left
for (r=row-1, c=col-1; r>=0 && c>=0; --r, --c) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// up right
for (r=row-1, c=col+1; r>=0 && c<cols; --r, ++c) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// down left
for (r=row+1, c=col-1; r<rows && c>=0; ++r, --c) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// down right
for (r=row+1, c=col+1; r<rows && c<cols; ++r, ++c) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// up
for (r=row-1, c=col; r>=0; --r) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// down
for (r=row+1, c=col; r<rows; ++r) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// left
for (r=row, c=col-1; c>=0; --c) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
// right
for (r=row, c=col+1; c<cols; ++c) {
seats[r*cols + c].neighbours++;
if (seats[r*cols + c].status != '.')
break;
}
}
}
return 1;
}
int main(ac, av)
int ac;
char **av;
{
char line[512];
struct plane *plane=NULL;
while (fgets(line, sizeof line, stdin)) {
plane=add_row(plane, line);
}
do {
calc(plane);
//print_seats(plane);
//print_count(plane);
} while (sit(plane) > 0);
printf("%s : res=%d\n", *av, plane->seated);
exit (0);
}

184
day11/ex2.bash Executable file
View File

@@ -0,0 +1,184 @@
#!/bin/bash
#
# ex1.bash: Advent2020 game, day 11/game 1.
CMD=${0##*/}
shopt -s extglob
declare -a rowsstr rows seats control
declare -i NCOLS NROWS SIZE
declare zeroed
function print_control() {
local -i r c
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
printf "%2d " "${control[r*NCOLS+c]}" >&2
done
echo >&2
done
echo >&2
}
function print_seats() {
local -i r c
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
printf "%d " "${seats[r*NCOLS+c]}" >&2
done
echo >&2
done
echo >&2
}
function run() {
local -i c r i cell changed=1
#local -a control
local -i loop=0 seated=0
read -ra seats <<< "${rows[*]}"
#print_seats
while ((changed > 0)); do
changed=0
seated=0
read -ra control <<< "$zeroed"
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
((cell=r*NCOLS+c))
if (( seats[cell] == 2 )); then
# diagonal up left
r1=$((r-1))
c1=$((c-1))
while ((r1>=0 && c1>=0)); do
((control[r1*NCOLS+c1]++));
#echo up >&2
((seats[r1*NCOLS+c1] != 0)) && break
((r1--))
((c1--))
done
# diagonal up right
r1=$((r-1))
c1=$((c+1))
while ((r1>=0 && c1<NCOLS)); do
((control[r1*NCOLS+c1]++));
((seats[r1*NCOLS+c1] != 0)) && break
((r1--))
((c1++))
done
# diagonal down left
r1=$((r+1))
c1=$((c-1))
while ((r1<NROWS && c1>=0)); do
((control[r1*NCOLS+c1]++));
((seats[r1*NCOLS+c1] != 0)) && break
((r1++))
((c1--))
done
# diagonal down right
r1=$((r+1))
c1=$((c+1))
while ((r1<NROWS && c1<NCOLS)); do
((control[r1*NCOLS+c1]++));
((seats[r1*NCOLS+c1] != 0)) && break
((r1++))
((c1++))
done
# line left
c1=$((c-1))
while ((c1>=0)); do
((control[r*NCOLS+c1]++));
((seats[r*NCOLS+c1] != 0)) && break
((c1--))
done
# line right
c1=$((c+1))
while ((c1<NCOLS)); do
((control[r*NCOLS+c1]++));
((seats[r*NCOLS+c1] != 0)) && break
((c1++))
done
# column up
r1=$((r-1))
while ((r1>=0)); do
((control[r1*NCOLS+c]++));
((seats[r1*NCOLS+c] != 0)) && break
((r1--))
done
# column down
r1=$((r+1))
while ((r1<NROWS)); do
((control[r1*NCOLS+c]++));
((seats[r1*NCOLS+c] != 0)) && break
((r1++))
done
fi
done
done
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
((cell=r*NCOLS+c))
#((ccell=(r+1)*(NCOLS+2) + c+1))
case ${seats[cell]} in
0) continue
;;
1) if (( control[cell] == 0 )); then
((++changed))
seats[cell]=2
fi
;;
2) if (( control[cell] >= 5 )); then
((++changed))
seats[cell]=1
fi
esac
#printf "r=%d c=%d cell=%d val=%s\n" "$r" "$c" "$cell" "${seats[cell]}" >&2
done
#echo >&2
done
for ((r=0; r<NROWS; ++r)); do
for ((c=0; c<NCOLS; ++c)); do
((cell=(r*(NCOLS))+c))
((seats[cell] == 2)) && ((seated++))
done
done
#print_control
#print_seats
((loop++))
done
echo "$seated"
}
readarray -t rowsstr
for ((i=0; i<${#rowsstr[@]}; ++i)); do
rowsstr[i]=${rowsstr[i]//./0}
rowsstr[i]=${rowsstr[i]//L/1}
rowsstr[i]=${rowsstr[i]//#/2}
done
NCOLS=${#rowsstr[0]}
NROWS=${#rowsstr[@]}
SIZE=$((NCOLS * NROWS))
printf -v zeroed '%0.s0 ' $(seq 1 $SIZE)
# split arrays in integers
for ((r=0; r<NROWS; ++r)); do
srow="${rowsstr[r]}"
nrow=()
for ((c=0 ; c<NCOLS ; c++ )); do
nrow+=("${srow:c:1}")
done
rows[r]="${nrow[*]}"
done
read -ra seats <<< "${rows[*]}"
#echo "S=${#seats[@]} C=${#control[@]}"
#print_seats
res=$(run)
printf "%s : res=%d\n" "$CMD" "$res"
exit 0