{{ message }}

Instantly share code, notes, and snippets.

Created May 26, 2012
sssfd
View f1.hs
 magic :: Int -> Int -> [Int] magic 0 _ = [] magic m n = m : (magic n (m+n)) getIt :: [Int] -> Int -> Int getIt [] _ = 0 getIt (x:xs) 1 = x getIt (x:xs) n = getIt xs (n-1)
Created Mar 20, 2014
Liu, Shi's solution of permutation of 7 number.
View liushi_7_perm.java
 package demo; import java.util.ArrayList; import java.util.List; public class demo { static List cout(List one,String str){ List t = new ArrayList();
Last active Aug 29, 2015
print all permutation of a list
View jinzhou_7_perm.c
 #include #include #include /* two solution: * 1. function "perm" * 2. function "print_permutation" */ void swap(int data[], int a, int b)
Created Mar 20, 2014
the KMP algorithm for indexing sub-strings.
View kmp.c
 #include #include #include int *build_next(const char *pat, int pat_len) { int i; int *next = (int *)malloc(pat_len * sizeof(*next)); next[0] = -1;
Last active Aug 29, 2015
compute the fact fo a very large number.
View fact.c
 #include int multi(char *a, int len, int b) { int i; int carry = 0; for (i = 0; i < len; i++) { int tmp = (a[i] - '0') * b + carry; a[i] = tmp % 10 + '0';
Created Mar 27, 2014
print all permutation of a character list.
View print_character_permutation.c
 # include /* Function to swap values at two pointers */ void swap (char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; }
Created May 4, 2014
segmented sieve of eratosthenes
View seg_sieve.rkt
 (define (s-sieve limit) (define sieve-size (add1 (integer-sqrt limit))) (define sieve (make-vector sieve-size #t)) ; sieve of eratosthenes (for* ([i (in-range 2 sieve-size)] #:when (vector-ref sieve i) [j (in-range (* i i) sieve-size i)]) (vector-set! sieve j #f)) ; collect sieve (define primes (for/list ([n (in-range 2 sieve-size)]
Last active Aug 29, 2015
Project Euler, Problem 26.
View pro26.c
 #include #include #include int num_of_cycle(int n) { int ret; /* return value */ int *rem_seen = (int *)malloc(n * sizeof(*rem_seen)); memset(rem_seen, 0, n*sizeof(*rem_seen));
Created May 15, 2014
Modified version of Molly's pro26.c
View pro26_molly.c
 #include #include #include int findmax(int a[]) { int i; for(i=1; i<1000; i++) { if(a[i]>a[0])
Created Jun 24, 2014
POJ 1011
View poj_1011.c
 #include #include #include #include #define MAX_ELEMENT 64 int num_of_sticks; bool used[MAX_ELEMENT]; int sticks[MAX_ELEMENT]; int sum;