Skip to content

Instantly share code, notes, and snippets.

@weirddan455
weirddan455 / aoc.c
Created December 25, 2021 08:56
Advent of Code Day 25
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
int main()
@weirddan455
weirddan455 / aoc.c
Created December 28, 2021 06:02
Advent of Code Day 23 Part 2
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define ROOM_A_ENTRANCE 2
#define ROOM_B_ENTRANCE 4
#define ROOM_C_ENTRANCE 6
#define ROOM_D_ENTRANCE 8
@weirddan455
weirddan455 / time.c
Created December 31, 2021 16:43
clock_gettime benchmark
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#define MILLION 1000000
#define BILLION 1000000000
int main(void)
{
struct timespec start, end;
@weirddan455
weirddan455 / parse.c
Created January 1, 2022 19:51
Advent of Code Input Parsing
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main(void)
{
// Using POSIX open/read functions
// If using Windows, you probably want to use fopen/fread (or native Windows API)
#define CHECKMATE_EVALUATION -9001
#define STALEMATE_EVALUATION 0
static int AISearch(int depth, GameState *state, int alpha, int beta)
{
if (depth == 0)
{
return AIEvaluate(state);
}
uint16_t moves[1024];
@weirddan455
weirddan455 / xbox.patch
Created April 4, 2022 17:28
Xbox One Controller Bluetooth Patch
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 071fd093a5f4..a4ba824395b0 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -27,6 +27,7 @@
#define MS_DUPLICATE_USAGES BIT(5)
#define MS_SURFACE_DIAL BIT(6)
#define MS_QUIRK_FF BIT(7)
+#define MS_QUIRK_XBOX BIT(8)
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
struct rng {
uint64_t state;
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;
#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;
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()