Skip to content

Instantly share code, notes, and snippets.

@kupp1
Last active June 12, 2019 08:11
Show Gist options
  • Save kupp1/b3dfd15375469c0e5dbf7c34e12d23c6 to your computer and use it in GitHub Desktop.
Save kupp1/b3dfd15375469c0e5dbf7c34e12d23c6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <inttypes.h>
#define N 100000
uint_fast16_t f()
{
static uint_fast16_t last = 0, indxs[N] = {0}, i = 0;
i++;
uint_fast16_t tmp = last;
if (indxs[last] == 0)
last = 0;
else
last = i - indxs[tmp];
indxs[tmp] = i;
return last;
}
int main(int argc, char **argv)
{
printf("USAGE:\n\t%s | gnuplot --persist\n", argv[0]);
FILE *out = fopen("out.csv", "w+");
fputs("0, 0\n", out);
for (int i = 0; i < 100000; i++)
fprintf(out, "%i, %lu\n", i + 1, f());
puts("plot 'out.csv' with boxes");
fclose(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment