Skip to content

Instantly share code, notes, and snippets.

View clausecker's full-sized avatar

Robert Clausecker clausecker

View GitHub Profile
@clausecker
clausecker / bubblelist.c
Created May 10, 2017 11:27
Bubblesort on singly linked lists
/* bubble sort a linked list */
#include <stdio.h>
#include <stdlib.h>
static struct list *scan_list(void);
static void sort_list(struct list **);
static void print_list(struct list *);
static void free_list(struct list *);
struct list {
#include <stdio.h>
#include <locale.h>
/* estimate the endgame tablebase size of micro shogi */
enum {
/*
* number of ways to place the kings such that they don't check
* each other. This assumes that the Sente king is always placed
* on the right half of the board, we can cut the number of
/*-
* Copyright (c) 2014 Robert Clausecker <[email protected]>
*/
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
/*
* Imagine a 5x5 grid. We begin coloring in some of the squares on that
* grid. What is the minimum number of squares we must color in, such
* that in every row, in every column, and in every 2x2 square grid,
* there is at least one colored square?
*/
#include <stdio.h>
typedef unsigned grid;
@clausecker
clausecker / grpcache.c
Last active March 6, 2016 00:59
Caching functions for the group and passwd database
/*-
* Copyright (c) 2016 Robert Clausecker. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
.text
.globl is_eof_block
.type is_eof_block,@function
.align 16
is_eof_block:
mov $7,%eax
movups 0x00(%rdi),%xmm0
movups 0x10(%rdi),%xmm1
movups 0x20(%rdi),%xmm2
.text
.globl is_eof_block
.type is_eof_block,@function
.align 16
is_eof_block:
xor %eax,%eax
vmovupd 0x00(%rdi),%ymm0
vmovupd 0x20(%rdi),%ymm1
vmovupd 0x40(%rdi),%ymm2
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#define TESTS 10000000
#ifndef MISALIGNED
# define MISALIGNED 0
#endif
.text
.globl is_eof_block
.type is_eof_block,@function
.align 16
is_eof_block:
xor %eax,%eax
vmovupd 0x00(%rdi),%ymm0
vmovupd 0x20(%rdi),%ymm1
vmovupd 0x40(%rdi),%ymm2
/*
* yesno.c - Get a yes/no answer from the user
*/
#define _POSIX_C_SOURCE 200809L
#include <langinfo.h>
#include <regex.h>
#include <stdio.h>
/*