Welcome~~~


Another blog:
http://fun-st.blogspot.com/

It is easier to write an incorrect program than understand a correct one.

Friday, April 8, 2011

My Job Interview at Google - good coders code, great reuse

My Job Interview at Google - good coders code, great reuse

Tuesday, April 5, 2011

Refcards

Refcards


Fortran 90 Reference Card

Vim Reference Card

Python 2.5 Reference Card

LatexSuite Reference Card

Perl Reference Card

ASCII Table

regex - What's the most efficient way to find one of several substrings in Python? - Stack Overflow

regex - What's the most efficient way to find one of several substrings in Python? - Stack Overflow

Java and Python « Python Conquers The Universe

Java and Python « Python Conquers The Universe

Ways to change the background color on your computer

To protect eyes, it would be better to change the background to another color  ( Hue = 85, Sat = 90, Lum = 205)

From some online source: 
打开控制面板中的"显示" 选择外观(appearance)-高级(advanced), 然后在项目(items)那栏选窗口(windows),再点颜色(color)-其它(others),然后把Hue(色调设为85,Sat(饱和度)设为90,Lum(亮度)设为205。 然后单击 添加到自定义颜色(Add tocustom colors),一直确定。 

把窗口设成绿色之后,再来把IE的网页背景也变成养眼的绿色吧: 
打开IE,点击工具(TOOLS),点INTERNET选项(INTERNET OPTIONS),点右下角的辅助功能 (Assessibility),然后勾选 不使用网页中指定的颜色(ignore colors specifiedon web pages),然后点 确定退出。  


--

♥ ¸¸.•*¨*•♫♪♪♫•*¨*•.¸¸♥

Saturday, April 2, 2011

Python Set C++ Set -- From: Word Aligned

Word Aligned - powered by FeedBurner


Python set is an unordered container designed for fast membership, union, intersection, and differencing operations — much like the mathematical sets I learned about at school — whereas a C++ set is an ordered container, featuring logarithmic access times and persistent iterators.

Think: C++ set ≈ binary tree; Python set ≈ hashed array.

It's apparent which method is correct for which language now. To put something into a binary tree you must recurse down the tree and find where to insert it. Hence std::set::insert() is correct C++. To put something into a hashed array you hash it and add it right there. Hence set.add() is proper Python.

You insert into trees and add to hashes: so if your set is a tree, call S.insert(), and if it's a hash, S.add().

Such logical arguments don't always deliver.

Question: Suppose now that S is a string and you're after its length. Should you use S.length() orS.size()?

Answer: Neither or both.

In Python a string is a standard sequence and as for all other sequences len(S) does the trick. In C++ a string is a standard container and as for all other containers S.size() returns the number of elements; but, being std::string, S.length() does too.

Oh, and the next revision of C++ features an unordered_set (available now asstd::tr1::unordered_set) which is a hashed container. I think unordered_set is a poor name for something which models a set better than std::set does but that's the price it pays for coming late to the party. And you don't std::unordered_set::add elements to it, you std::unordered_set::insert them.


--


♥ ¸¸.•*¨*•♫♪♪♫•*¨*•.¸¸♥

Friday, April 1, 2011

Longest common subsequence

Longest common subsequence


# Find the number of digits in n!.

number of digits in n = floor(log(n)) + 1;

so for n! # of digits = (floor(log(n!)))+1;
= floor(Sum of log1+log2+--- + logn)+1;

digits = (int) log10(number), where log 10 means log for base 10

--

♥ ¸¸.•*¨*•♫♪♪♫•*¨*•.¸¸♥

#Two strings,find out they are anagrams

If two strings s1 and s2 are given find out they are anagrams are not "abc" and "bca' are string anagrams characters will be same in both but order may change

int findAna(char *s1, char*s2){
int sum = 0;
while(*s1 != '\0')
sum ^= *s1++;
while(*s2 != '\0')
sum ^= *s2++;
return sum;
void main (){
int i;
i = findAna("abcd","bac");
printf("%d",i); // i = 0 ? => anagrams .... else not anagrams :)
}

--

♥ ¸¸.•*¨*•♫♪♪♫•*¨*•.¸¸♥

# Construct tree from Ancestor Matrix

Construct tree from Ancestor Matrix « GeeksforGeeks

You are given a matrix M[n, n] for a tree with n nodes. In the given matrix M, M[i, j] is true iff node j is an ancestor of node i. Construct the tree from the given matrix.

For example, you are given below matrix.

    1  2  3  4
1  0  1  1  0

2  0  0  1  0

3  0  0  0  0

4  0  1  1  0
You need to construct the below tree. In the constructed tree ancestor relationship should be correct. A node can come on left or right of its parent as you cannot determine this information from the ancestor matrix

Node numbers used in matrix are in bracket
                   5(3)
                  /
                /
          10(2)
         /    \
       /        \
 12(1)    13(4)
This question was asked in Amazon.

'Algo:
1) Select row with all entries zero and make it as root.
2)From all entries in matrix subtract 1 if its ancestor is that root.
3) Now again search for the rows with all entries zero but dun select again the same row. You can mark all entries of that row as -1 if you have already selected that row.
4)Continue till all rows become zero.'

--

♥ ¸¸.•*¨*•♫♪♪♫•*¨*•.¸¸♥

Postfix Notation Mini-Lecture

Postfix Notation Mini-Lecture

http://www.spsu.edu/cs/faculty/bbrown/web_lectures/postfix/

The Stony Brook Algorithm Repository

The Stony Brook Algorithm Repository

Search algorithm - Wikipedia, the free encyclopedia

Search algorithm - Wikipedia, the free encyclopedia

Trie - Wikipedia, the free encyclopedia

Trie - Wikipedia, the free encyclopedia

algorithm - Pagerank and its mathematics: Explanation needed - Stack Overflow

algorithm - Pagerank and its mathematics: Explanation needed - Stack Overflow

arrays - Tricky Interview question on searching - Stack Overflow

arrays - Tricky Interview question on searching - Stack Overflow

Hidden features of Python - Stack Overflow

Hidden features of Python - Stack Overflow