Skip to content

Instantly share code, notes, and snippets.

@sjmulder
Created November 16, 2016 09:32
Show Gist options
  • Save sjmulder/1d947035d31036be75e3bbca0967b81c to your computer and use it in GitHub Desktop.
Save sjmulder/1d947035d31036be75e3bbca0967b81c to your computer and use it in GitHub Desktop.
Pascal’s triangle using vector additions
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#define N 64
#define VECSZ ((N+1)/2)
int main(int argc, const char* argv[])
{
uint64_t vec[VECSZ] = {1};
for (int i = 1; i < N; i++)
for (int j = min(i, VECSZ-1); j > 0; j--)
vec[j] += vec[j-1];
for (int i = 0; i < VECSZ; i++) printf("%llu\n", vec[i]);
for (int i = N/2-1; i >= 0; i--) printf("%llu\n", vec[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment