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
// Robust Lock: if a "thread" exits while holding a lock, it is unlocked | |
// linux $ cc -pthread example.c | |
// w64dk $ cc example.c -lntdll | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1jd82ux | |
// Ref: https://github.com/cozis/timestamp_lock | |
// This is free and unencumbered software released into the public domain. | |
#include <assert.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> |
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
// https://old.reddit.com/r/C_Programming/comments/1iljkn2 | |
// https://github.com/jamesnolanverran/dmap | |
#include "dmap.c" | |
#include <string.h> | |
#define KEYLEN 8 | |
#define RUNS 10 | |
#define KEYS 1000000 | |
static void encode(char *key, int x) |
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
// 1. Input: | |
// A number N, representing the size of the square board grid. N rows of | |
// N characters each, where each character is either R (red) or A (blue). | |
// | |
// 2. Objective: | |
// Rearrange the rows of the board to maximize the area of the largest | |
// contiguous rectangular zone for each color (R for The Famous, A for | |
// The Warriors). | |
// | |
// Determine the winning team based on the larger rectangular area of |
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
// Examples of quick hash tables and dynamic arrays in C | |
// https://nullprogram.com/blog/2025/01/19/ | |
// This is free and unencumbered software released into the public domain. | |
#include <assert.h> | |
#include <stdarg.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> |
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
Question 2: Steganography using 4-bit LSB algorithm | |
Scope: File Processing, Pointers, Dynamic Memory Allocation (No arrays) | |
File to use: stego_lsb.c | |
Preliminary: | |
This question should be solved using dynamic memory allocation along with | |
pointers. Any submitted work which includes an array will be given | |
automatically a zero mark. To view pgm files, you can use the “Irfan View” |
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
#include <assert.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t)) | |
#define S(s) (Str){(uint8_t *)s, sizeof(s)-1} |
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
// Slim Reader/Writer Condition Variable Demo / Test | |
// $ cc -nostartfiles -o main.exe demo.cpp | |
// $ cl /GS- demo.cpp /link /subsystem:console kernel32.lib | |
// This is free and unencumbered software released into the public domain. | |
#define assert(c) while (!(c)) *(volatile i32 *)-4 = 0 | |
using b32 = signed; | |
using i32 = signed; | |
using uz = decltype(sizeof(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
// Quick test of environment variable passing | |
// $ cc -nostartfiles -o testenv testenv.cpp | |
// $ cl testenv.cpp /link /subsystem:console kernel32.lib | |
// | |
// Spawns a copy of itself with a custom-built environment block, and | |
// the spawned child examines/probes that block. | |
// | |
// This is free and unencumbered software released into the public domain. | |
typedef int I; |
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))) |
NewerOlder