Friday, October 27, 2006

Above Three Four and Five

Have you ever noticed the three punctations above 3,4,5 on a standard US keyboard?

Yes, they are #(sharp), $(dollar), and %(percent).

You will notice that on a US keyboard, shift-4 is "$", which is the bash variable expansion character. On the keyboard, immediately to the left of "$" is "#". So, you can see that "#" is "at the beginning" of "$", and thus (according to our mnemonic), "#" removes characters from the beginning of the string. You may wonder how we remove characters from the end of the string. If you guessed that we use the character immediately to the right of "$" on the US keyboard ("%"), you're right!


So, #, which is before $, will remove characters from the beginning, and %, which is after $, will remove characters from the end of the string.

"${1##*.}"

"${1%.*}"

The bash is funny, easy while powerful. ;)

For more infomation about bash, click here.

Friday, October 20, 2006

Cygwin is not linux at all

Cygwin behaves strangely.

Gnome can not run.

Althought X works.

Collision with mingw.

Thursday, October 19, 2006

Java Reference

Java passes parameters by reference which brings convinience as well as strange errors. For example:


import java.util.*;

public class Test {
public static void main(String[] args) {
Vector v = new Vector();
int [] a = new int[5];
for(int i=0;i<10;i++) {
for(int j=0;j<5;j++) a[j] = i*j;
v.add(new Obj(a)); // this won't work!
}
for(Iterator it=v.iterator();it.hasNext();) {
it.next().dump();
}
}
}

class Obj {
int [] a;
Obj(int [] a) {
this.a = a;
}
void dump() {
for(int i=0;i System.out.println();
}
}


Well, the line

v.add(new Obj(a));

won't work as expected. Instead all arrays 'a' in 'Obj' are the same.

Change it to

v.add(new Obj(a.clone()));

so that every time a new array is passed.

Monday, September 25, 2006

Unexpected Error

printf("%d %d", 1ll, 1ll);

This will not output the expected result. A 64-bit integer will not cooperate with a %d argument.

So, instead

printf("%d %d", (int)1ll, (int)1ll);

or

printf("%I64d %I64d", 1ll, 1ll);

or

printf("%lld %lld", 1ll, 1ll);

should be used.

Monday, September 11, 2006

Strongly Connected Components

//Graph
//Strongly Connected Components

//call DFS(G) to compute finishing times f[u] for each vertex u
//compute GT, the transpose of G
//call DFS(GT), but in the main loop of DFS, consider the vertices
// in order of decreasing f[u] (as computed in line 1)
//output the vertices of each tree in the depth-first forest formed in line 3 as
// a separate strongly connect component

Saturday, September 2, 2006

First Unscheduled System Down

We experienced the first unscheduled system down today. The reason is that the server of our service provider met some unforeseen problem.

Now, problems are fixed and data seems not affected.

Sunday, August 27, 2006

Generalized Euclidean Algorithm

Generalized Euclidean Algorithm, or Integer Relation:

A set of real numbers x_1, x_2, ..., x_n is said to possess integer relation if there exist integers a_i such that
a_1x_1+a_2x_2+...+a_nx_n==0
with not all a_i==0.