Skip to content

Instantly share code, notes, and snippets.

View lotabout's full-sized avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / liushi_7_perm.java
Created March 20, 2014 06:34
Liu, Shi's solution of permutation of 7 number.
package demo;
import java.util.ArrayList;
import java.util.List;
public class demo {
static List<String> cout(List<String> one,String str){
List<String> t = new ArrayList<String>();
@lotabout
lotabout / jinzhou_7_perm.c
Last active August 29, 2015 13:57
print all permutation of a list
#include <stdio.h>
#include <malloc.h>
#include <string.h>
/* two solution:
* 1. function "perm"
* 2. function "print_permutation"
*/
void swap(int data[], int a, int b)
@lotabout
lotabout / kmp.c
Created March 20, 2014 08:48
the KMP algorithm for indexing sub-strings.
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int *build_next(const char *pat, int pat_len)
{ int i;
int *next = (int *)malloc(pat_len * sizeof(*next));
next[0] = -1;
@lotabout
lotabout / fact.c
Last active August 29, 2015 13:57
compute the fact fo a very large number.
#include <stdio.h>
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';
@lotabout
lotabout / print_character_permutation.c
Created March 27, 2014 08:46
print all permutation of a character list.
# include <stdio.h>
/* Function to swap values at two pointers */
void swap (char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
@lotabout
lotabout / seg_sieve.rkt
Created May 4, 2014 09:06
segmented sieve of eratosthenes
(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)]
@lotabout
lotabout / pro26.c
Last active August 29, 2015 14:01
Project Euler, Problem 26.
#include <stdio.h>
#include <malloc.h>
#include <string.h>
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));
@lotabout
lotabout / pro26_molly.c
Created May 15, 2014 09:05
Modified version of Molly's pro26.c
#include<stdio.h>
#include<sys/types.h>
#include<memory.h>
int findmax(int a[])
{
int i;
for(i=1; i<1000; i++)
{
if(a[i]>a[0])
@lotabout
lotabout / poj_1011.c
Created June 24, 2014 12:48
POJ 1011
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ELEMENT 64
int num_of_sticks;
bool used[MAX_ELEMENT];
int sticks[MAX_ELEMENT];
int sum;
@lotabout
lotabout / wiznote.SlackBuild
Created November 26, 2014 08:51
SlackBuild script for wiznote
#!/bin/sh
# Slackware build script for <appname>
# Copyright <year> <you> <where you live>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#