Last active
June 12, 2019 08:11
-
-
Save kupp1/b3dfd15375469c0e5dbf7c34e12d23c6 to your computer and use it in GitHub Desktop.
Van Eck's sequence with gnuplot https://youtu.be/etMJxB-igrc https://oeis.org/A181391 https://codegolf.stackexchange.com/questions/186654/nth-term-of-van-eck-sequence
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 <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