Skip to content

Instantly share code, notes, and snippets.

View clausecker's full-sized avatar

Robert Clausecker clausecker

View GitHub Profile
#include <signal.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static void winch_handler(int);
static void print_tdim(void);
Note 'author'
The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Robert Clausecker <[email protected]>
)
NB. entry at x,y of infinite matrix A
A =: >:@:[ %@:+ -:@:(* >:)@:+
NB. get the first y by y elements of A
@clausecker
clausecker / goscore.c
Last active August 29, 2015 14:15 — forked from anonymous/goscore.c
/*
* access the array b at row d, column e. Allow extra index parts before the
* closing bracket. Usually used as I] to get b[d * g + e]. All occurances of
* this macros are commented in the next parts.
*/
#define I b[d*g+e
/* int */ a; /* updated content of cell at b[d*g+e] */
/* int */ b[65536]; /* array containing the board */
/* int */ c; /* cleared if the flood-fill fills something, score */
/*-
* Reference implementation and judging program for the Paeth challenge.
* Published under CC-BY by Robert Clausecker (FUZxxl).
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* http://codegolf.stackexchange.com/q/48528/134 */
/* by Robert Clausecker (FUZxxl) */
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
enum opcode { HALT, PRINTX, INCX, INCY, JMP, DJZX, DJZY };
const char *mnemonics[7] = {
@clausecker
clausecker / urlscanner.l
Created May 25, 2015 16:01
lexing html with regices
/* http://stackoverflow.com/a/1732454/417501 */
%{
#include <ctype.h>
#include <string.h>
#include "urlscanner.h"
%}
/* yylineno ist unportabel und nicht Teil von POSIX! */
@clausecker
clausecker / bcd2dpd.s
Last active December 2, 2015 16:31
Routines to convert BCD to DPD
.section .text
.type bcd2dpd,@function
.globl bcd2dpd
# convert three digits in packed BCD to DPD
# input in edi, all but the lower three nibbles are ignored
# does not check if nibble > 9
.align 8
bcd2dpd:
# prepare arguments for call to decimal2dpd
extern unsigned
decimal2dpd(unsigned a, unsigned b, unsigned c)
{
unsigned result = c & 1 | (a & 7) << 7;
if (a < 8) {
if (b < 8)
return result | b << 4 | c;
else
return result | (c > 7 ? 0104 : (c & 6) << 4) | (b & 1) << 4 | 0012;
.section .text
.type bcd2dpd_mul,@function
.globl bcd2dpd_mul
# convert BCD to DPD with multiplication tricks
# input abcd efgh iklm in edi
.align 8
bcd2dpd_mul:
mov %edi,%eax # = 0000 abcd efgh iklm
shl %al # = 0000 abcd fghi klm0
package main
// https://www.reddit.com/r/coding/comments/3vsw5o/gettin_arithmetic_mean_right/
import "fmt"
import "math/big"
import "math/rand"
func naiveMean(rnd *rand.Rand, n int) float64 {
sum := 0.0