This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MAX_NAME 7 | |
#define NAME_FMT "%7[a-z] " | |
#define ALPHABET_SIZE 26 | |
#define IS_ALPHA(c) ((c) >= 'a' && (c) <= 'z') | |
#define TO_INDEX(c) ((c)-'a') | |
#define NAME_SIZE (MAX_NAME+1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
gsub(/./, "& ") | |
for(i = 1; i <= NF; i++) | |
risk_level[i, NR] = $i | |
} | |
END { | |
find_lowest_total_risk() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
pos[NR] = $NF | |
} | |
END { | |
count_wins(pos[1], pos[2]) | |
if (wins[1] > wins[2]) | |
print wins[1] | |
else | |
print wins[2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bc <<EOF | |
$(awk -F, ' | |
NR == 1 { | |
print "t = " $0 | |
next | |
} | |
{ | |
j = 0 | |
for (i = 1; i <= NF; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
gsub(/,/, "") | |
incr[$NF] = $(NF-1) | |
for (i = 1; i < NF-2; i += 2) { | |
reqs[$NF, ++nreqs[$NF]] = $(i+1) | |
qtys[$NF, $(i+1)] = $i | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <limits.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MAX_WIDTH 100 | |
#define MAX_HEIGHT 100 | |
#define QUEUE_CAP 4096 | |
struct position { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <math.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
#include <unistd.h> | |
#ifdef __WIN32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# header | |
for d in 7 42 77 101 121 1001 1111 7512 12345 110000 902180; do | |
n=0 | |
# code (124 bytes) | |
f()for e do case $e in *==*=*|*[!0-9]0[0-9]*);;*=*)((n+=e));esac done;h=${d%?};eval "f ${h//?/&{+,-,*,==,\}}${d#$h}";echo $n | |
# footer | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: jq -s -f aoc22-13.jq input.txt | |
def cmp_list($l; $r): | |
def cmp_elem($l; $r): | |
($l | type) as $lt | |
| ($r | type) as $rt | |
| if $lt == $rt then | |
if $lt == "null" then | |
0 | |
elif $lt == "number" then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
int | |
rle_encode(FILE *src, FILE *dest) { | |
int c, prev, cnt; | |
prev = fgetc(src); | |
cnt = 1; |