Skip to content

Instantly share code, notes, and snippets.

View chaoxu's full-sized avatar
😀

Chao Xu chaoxu

😀
  • University of Electronic Science and Technology of China
  • Chengdu, Sichuan, China
View GitHub Profile
import java.util.*;
import java.math.*;
public class MultiWordIntersection{
public static int MultiIntersection(ArrayList<String> a, String sword){
int sum = 0;
SurfaceWord sw = new SurfaceWord(sword);
for(int i=0;i<a.size();i++){
WordVector p = new WordVector(sw.toNumber(a.get(i)));
for(int j=i+1;j<a.size();j++){
WordVector p1 = new WordVector(sw.toNumber(a.get(j)));
import java.util.*;
public class bio{
public static void main(String[] args){
char[] c = "aabc".toCharArray();
//String s = "eabahgcabah";
String s = "aaaaaaabc";
int[] r = list(c,s);
for(int i=0;i<r.length;i++){
System.out.println(r[i]);
}
import java.util.*;
public class expectedcars {
public static void main(String[] args){
int n = 100000;
int l = 10000;
long z = 0;
for(int i=0;i<l;i++){
z+=n-simulate(n);
}
System.out.println(((double) z)/((double) l));
#include <stdlib.h>
#include <time.h>
#include "iostream"
#include <math.h>
using namespace std;
double p;
int interval(double l, double a){
a = a - floor(a);
if(l<1.0) return 0;
@chaoxu
chaoxu / SquareRoot.java
Created October 26, 2010 09:36
Using Lagrange's four-square theorem and geometry to solve for square root.
public class SquareRoot {
public static double sqrt(int n){
int[] v = vector(n);
return magnitude(v);
}
public static double magnitude(int[] v){
double a=v[1],b=v[0];
if(v.length>2){
int[] u = new int[v.length-1];
#include <stdlib.h>
#include <time.h>
#include "iostream"
#include <math.h>
using namespace std;
double p;
//n is the length of a car
double n;
double e = 0.0000001;
//double e = 0;
@chaoxu
chaoxu / screenshot.sh
Created January 7, 2011 18:47
Take a screenshot and upload to imageshack.us, then copy the link to clipboard. Allow one argument, use s for selection, a integer for amount of seconds to wait. (Can't do both)
#!/bin/bash
rm screenshot.png -f
if [ $# -ne 0 ]
then
if [ "X$1" = "Xs" ]
then
scrot screenshot.png -s
else
scrot screenshot.png -d $1
fi
@chaoxu
chaoxu / keycounter.py
Created March 5, 2011 07:07
count amount of key strokes
#!/usr/bin/python
import sys
import atexit
import time
global count
global fname
fname = '/home/mgccl/.keycount'
def savecounter():
f = open(fname,'w')
import string
import sys
input = sys.stdin
ls = input.readlines()
a = "!!!!!!! "
b = "!!!!!!! "
c = "尼玛"
d = "???!!!! "
e = "???!!!! "
@chaoxu
chaoxu / wallpaper.sh
Created March 12, 2011 07:50
randomly pick 2 images, combine them, and set it as desktop
#!/bin/sh
d="$HOME/wallpaper"
o=`mktemp`
c=`ls $d | grep -iE "(.jpg|.gif|.png)" | sort -R | head -2`
if [ $# -gt 0 ] ; then
a=$1
else
a=`echo $c | cut -d " " -f 1`