[algogeeks] Re: Amazon Question-Linux Shell

2010-09-21 Thread Prem Mallappa
@Neeraj: Your approach is good, this however lists .999.999.999 which is not a valid IP address. grep -lR [0-255]\.[0-255]\.[0-255]\.[0-255] * further filter out the output of above to invalidate any ip address that are reserved. -l is for suppressing normal output and printing only

[algogeeks] Re: Amazon Question-Linux Shell

2010-09-21 Thread Prem Mallappa
Sorry this doesn't work all grep out there ... On 22 Sep, 01:40, Prem Mallappa prem.malla...@gmail.com wrote: @Neeraj: Your approach is good, this however lists .999.999.999 which is not a valid IP address. grep -lR [0-255]\.[0-255]\.[0-255]\.[0-255] * further filter out the output

[algogeeks] Re: Brent's algorithm

2010-08-18 Thread Prem Mallappa
information is available on Internet, - Wikipedia is a ocean of knowledge. - Google.com - Numerical recipies in C ( I think it has some reference to Brents algo) Not sure about this algo's applications in detection of loops in linked list. On 18 Aug, 04:42, jayapriya surendran

[algogeeks] Re: Generate all bit strings of length n

2010-08-14 Thread Prem Mallappa
On 13 Aug, 17:05, Chonku cho...@gmail.com wrote: Start with number 1. It will have a binary representation of 00...1 (Total of n-bits) Keeping adding 1 to it until you reach a number with all 1's in its binary representation. Looks correct to me, here is a small implementation

[algogeeks] Re: how to implement TAIL command of unix.

2010-08-14 Thread Prem Mallappa
Tail by default displays last 10 lines of file. 1. mmap the file 2. keep two pointers(A, B) pointing to beginning of the file 2. search for 10th \n using B, if not found i.e file has less than 10 lines, print from beginning to end 3. if found, start incrementing both A and B to the next \n.