This file contains hidden or 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 <stdlib.h> | |
| #include <math.h> | |
| unsigned long nth_prime(unsigned long n) { | |
| unsigned long p = 2, i=0, c; | |
| while (i < n) { | |
| unsigned long n_f = 0; // number of factors | |
| for (c=(unsigned long)sqrt(p); c>0; c--) | |
| n_f += (p%c==0); |
This file contains hidden or 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
| /******************************* | |
| * Example of double buffering | |
| * in Canvas2D | |
| ********************************/ | |
| import java.awt.*; | |
| import java.awt.event.*; | |
| import java.awt.image.*; | |
| import java.util.*; |
This file contains hidden or 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 <stdlib.h> | |
| int main(int argc, char *argv[]) { | |
| if (argc < 2) return -1; | |
| int n = atoi(argv[1]), i, l=0, c; | |
| for (i=1; l<=n; l++,i=l%n+1) | |
| for (c=1; c<n+i; c++) | |
| printf("%s%s", c>n-i?"*":" ", c==n+i-1?"\n":""); | |
| return 0; |
This file contains hidden or 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
| // k_elements_from_n | |
| // c99 | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| unsigned long factorial(long n) { | |
| return n==1 ? 1 : n*factorial(n-1); | |
| } | |
| void print_arr(int arr[], int length) { |
This file contains hidden or 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
| // w_lambert.c Lambert W-function | |
| // c99 | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| double W(double z) { | |
| double EPSILON = 0.000000000000001; | |
| double w = 0, ew, wN = z; |
This file contains hidden or 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> | |
| void printb(unsigned long v) { | |
| if (v>>1 > 0) printb(v>>1); | |
| putchar((v&1) + '0'); | |
| } | |
| int main(int argc, char *argv[]) { | |
| if (argc > 1) | |
| printb(atol(argv[1])); |
This file contains hidden or 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 <stdlib.h> | |
| #include <time.h> | |
| #include <string.h> | |
| #define sz 100 | |
| void msort(int *out, int *begin, int *end); | |
| static void merge(int *out, int *lbeg, int *lend, int *rend); | |
| void printr(int *arr, int *end); |
This file contains hidden or 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
| void insertion_sort(int *arr, int len) { | |
| int p; | |
| for (p=1; p<len; p++) { | |
| int n = arr[p], p2 = p; | |
| while (p2 > 0 && n < arr[p2-1]) | |
| arr[p2] = arr[--p2]; | |
| arr[p2] = n; | |
| } | |
| } |
This file contains hidden or 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
| // tests the President's Dilemma through genetic algorithm | |
| // Princeton Ferro - Jun 9, 2014 | |
| #include <stdio.h> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| #define FUND 100 | |
| #define N 1000 // members per generation | |
| #define DEBUG 0 |
This file contains hidden or 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
| typedef unsigned long uli; | |
| uli fact(uli n) { | |
| if (n < 2) return 1; | |
| uli r = (n % 2) ? 1+n/2 : 1; // if odd... | |
| uli p = n, a = n, b = n-2; | |
| while (b>1) { | |
| p *= a + b; | |
| a += b; | |
| b -= 2; |
OlderNewer