This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref: https://old.reddit.com/r/C_Programming/comments/1e30ce8/ | |
#include <stddef.h> | |
#include <stdio.h> | |
#define S(s) (str){s, sizeof(s)-1} | |
typedef struct { | |
char *data; | |
ptrdiff_t len; | |
} str; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quilt layout solver (example) | |
// $ cc -o quilt quilt.c | |
// Ref: https://old.reddit.com/r/algorithms/comments/1dn97c0 | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define countof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref: https://old.reddit.com/r/C_Programming/comments/1dlc4kw | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define new(n, t) (t *)calloc(n, sizeof(t)) | |
typedef struct node node; | |
struct node { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Flawless Squares | |
// $ cc -fopenmp -O2 -o squares squares.c | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1de40e0 | |
// This is free and unencumbered software released into the public domain. | |
#include <stdio.h> | |
int main(void) | |
{ | |
#pragma omp parallel for schedule(dynamic, 100000) | |
for (long long root = 1; root < 3037000500; root++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ c++ -o kanzi kanzi.cpp | |
#define WIN32_LEAN_AND_MEAN // avoids std::byte conflicts | |
#include "src/app/BlockDecompressor.cpp" | |
#include "src/app/Kanzi.cpp" | |
#include "src/app/InfoPrinter.cpp" | |
#include "src/app/BlockCompressor.cpp" | |
#include "src/transform/BWTS.cpp" | |
#include "src/transform/BWTBlockCodec.cpp" | |
#include "src/transform/SBRT.cpp" | |
#include "src/transform/ZRLT.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define assert(c) while (!(c)) __builtin_unreachable() | |
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t)) | |
enum { PAGESIZE = 1<<12 }; | |
typedef signed int b32; | |
typedef signed int i32; | |
typedef char byte; | |
typedef signed long long iz; | |
typedef unsigned long long uz; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mini lisp-like interpreter | |
// $ cc -o lisp lisp.c | |
// $ ./lisp "(cons (+ 1 2 3 (* -40 million)) (cdr (quote (1 2 3))))" | |
// (-39999994 2 3) | |
// This is free and unencumbered software released into the public domain. | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Draw a triangle on Windows using OpenGL 1.1 | |
// $ gcc -mwindows -o triangle triangle.c -lopengl32 | |
// This is free and unencumbered software released into the public domain. | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
#include <GL/gl.h> | |
#define countof(a) (int)(sizeof(a) / (sizeof(*(a)))) | |
static LRESULT CALLBACK handler(HWND h, UINT msg, WPARAM wparam, LPARAM lparam) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 8-bit indexed PNG writer, no dependencies | |
// $ cc -o png png.c | |
// $ ./png >image.png | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
static uint32_t adler32(uint32_t sum, uint8_t *buf, ptrdiff_t len) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "Two Sum" benchmark | |
// $ cc -O1 -nostartfiles -o twoSum.exe twoSum.c | |
// $ cl /O1 twoSums.c /link /subsystem:console kernel32.lib libvcruntime.lib | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1c36391 | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define new(a, t, n) (t *)alloc(a, sizeof(t), _Alignof(t), n) |
NewerOlder