Skip to content

Instantly share code, notes, and snippets.

# 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
# 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
#include <stdio.h>
#include <limits.h>
int
rle_encode(FILE *src, FILE *dest) {
int c, prev, cnt;
prev = fgetc(src);
cnt = 1;
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
int
parse_signed(const char src[static 1], intmax_t min, intmax_t max,
intmax_t dest[static 1], char **endptr) {
int sign;
intmax_t value;
# sample input: 10-1000,15-350,50-1500,2100,1700-1800,45,40,145,2-1300
set -o pipefail
tr , '\n' | sort -n | awk '
BEGIN {
FS = OFS = "-"
}
NF < 1 || NF > 2 || (NF == 2 && $1 > $2) {
print "bad input: " $0 | "cat >&2"
exit 1
}
#include <stdio.h>
#include <ctype.h>
#include <strings.h>
static int
is_palindromic(const char *str, size_t n) {
size_t i, j;
if (n == 0)
return 1;
# Takes an IPv6 address as argument
# and encodes it as described in RFC1924.
export LC_ALL=C
export POSIXLY_CORRECT=1
unset BC_ENV_ARGS
unset BC_LINE_LENGTH
d0='0' d10='A' d20='K' d30='U' d40='e' d50='o' d60='y' d70='+' d80='`'
d1='1' d11='B' d21='L' d31='V' d41='f' d51='p' d61='z' d71='-' d81='{'
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define WIDTH 64
#define HEIGHT 64
#define AREA (WIDTH * HEIGHT)
#define WHITE 255
#define BLACK 0
wrapper=
status=0
badsrc() {
printf 'skipping %s\n' "$src" >&2
status=1
}
randstr() {
tr -cd '[:alnum:]' </dev/urandom | head -c 10
#include <assert.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node *node;
typedef struct node *leaf;
typedef struct {
int last;