Skip to content

Instantly share code, notes, and snippets.

@weirddan455
weirddan455 / part1.c
Created December 18, 2022 01:14
Advent of Code Day 16 Part 1
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#define MAX_NEIGHBORS 8
typedef struct Room
@weirddan455
weirddan455 / part2.c
Created December 15, 2022 10:55
Advent of Code Day 15 Part 2
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#define SCAN_BOUNDS 4000000
typedef struct Position
@weirddan455
weirddan455 / part1.c
Created December 14, 2022 03:35
Advent of Code Day 13 Part 1
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct Packet
{
int *data;
size_t size;
size_t capacity;
size_t num_lists;
@weirddan455
weirddan455 / visual.c
Created December 10, 2022 00:17
Advent of Code Day 9 Visualization
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#define TARGET_MS 20
#define SEGMENT_SIZE 3
static SDL_Renderer *init_sdl(void)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@weirddan455
weirddan455 / day3_part2.c
Created December 3, 2022 06:27
Advent of Code Day 3 Part 2
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static char get_priority(char c)
{
@weirddan455
weirddan455 / day3_part1.c
Created December 3, 2022 06:26
Advent of Code Day 3 Part 1
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static char get_priority(char c)
{
if (c >= 'a' && c <= 'z') {
@weirddan455
weirddan455 / day2.c
Created December 2, 2022 07:32
Advent of Code Day 2 Part 2
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
typedef enum ParseState
{
OPPONENT,
SPACE,
YOU,
NEWLINE
from time import perf_counter_ns
array_size = 1000000
array = []
with open("unsorted.txt") as unsorted:
for i in range(array_size):
array.append(int(unsorted.readline()))
start = perf_counter_ns()
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#define ARRAY_SIZE 1000000
int compare(const void *a, const void *b)
{
int ia = *(int*)a;
void swap_xor(int *x, int *y)
{
*x = *x ^ *y;
*y = *x ^ *y;
*x = *x ^ *y;
}
void swap_normal(int *x, int *y)
{
int temp = *x;