Skip to content

Instantly share code, notes, and snippets.

View lotabout's full-sized avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / score.html
Created March 18, 2015 13:21
score management in JS
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
#table_score {
border-collapse: collapse;
padding: 12px;
}
@lotabout
lotabout / valid_train.c
Created January 12, 2015 09:41
validate if a sequence of push/pop is valid.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdbool.h>
bool check(int max, char *p)
{
/* simulate the push/pop of stacks */
bool *stack = (bool *)malloc((max+1) * sizeof(*stack));
@lotabout
lotabout / subset.py
Created January 3, 2015 09:42
subset.py
class Solution:
def subsets(self, S):
self.ht = {}
ret = [[]]
s_sorted = sorted(S)
for set_length in range(1, len(S)+1):
ret += self.subset(s_sorted, 0, set_length)
return ret
def subset(self, S, index, l):
@lotabout
lotabout / qsort.cpp
Created December 1, 2014 02:12
quicksort following the algorithm of "Introduction to Algorithms"
#include <iostream>
using namespace std;
int partition(int array[], int lo, int hi)
{
// pivot=A[hi]; A[i] < pivot; A[j] >= pivot
int i = lo-1;
int j = lo;
for (j = 0; j < hi; ++j) {
@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:
#
@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 / 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 / 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 / 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 / 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;
}