A satirical C library that redistributes array wealth according to Party doctrine. Mocks communism, Stalinism, and left-authoritarian ideologies through code.
Let S = Σ aᵢ. The redistributed array A' is defined as:
a'[0] = S − (k − 1) // The Party Secretary — takes everything
a'[1..k-1] = 1 // The Apparatchiks — minimum ration
a'[k..n-1] = 0 // The People — liquidated
Where k is the size of the ruling class (Party + apparatchiks).
Input: [3, 5, 1, 2, 9, 7, 5, 4], S = 36, k = 4
Output: [33, 1, 1, 1, 0, 0, 0, 0]
a'[0] = 36 − 3 = 33— the Party Secretary's sharea'[1..3] = 1— rations for the privilegeda'[4..7] = 0— everyone else
meson setup build
meson compile -C build
meson test -C build#include <communism.h>
// Redistribute an int64_t array in-place.
// Returns COMMUNISM_OK, COMMUNISM_ERR_ARGS, or COMMUNISM_ERR_BURZH.
int communism_apply(int64_t *arr, size_t n, size_t k);
// Same for double arrays.
int communism_apply_f(double *arr, size_t n, size_t k);
// Sum helpers.
int64_t communism_sum(const int64_t *arr, size_t n);
double communism_sum_f(const double *arr, size_t n);
// Human-readable accusation for a return code.
const char *communism_strerror(int rc);| Code | Value | Meaning |
|---|---|---|
COMMUNISM_OK |
0 |
Success |
COMMUNISM_ERR_ARGS |
-1 |
Invalid arguments (NULL, k=0, k>n) |
COMMUNISM_ERR_BURZH |
-2 |
Petty-bourgeois deviation: leader's share would be less than 1 |
If the resulting leader share S − (k−1) < 1, the library refuses to proceed
and returns COMMUNISM_ERR_BURZH. The array is left unmodified.
double arr[] = {0.5, 0.5};
int rc = communism_apply_f(arr, 2, 2);
// rc == COMMUNISM_ERR_BURZH
printf("%s\n", communism_strerror(rc));
// PETTY-BOURGEOIS DEVIATION: you attempted to give the leader less
// than a rank-and-file Party member. You are under arrest.This is free and unencumbered software released into the public domain — The Unlicense.