Wednesday, October 24, 2007

New England Foliage

Recently I was able to visit my parents in New England. While I was there I took a few pictures from the outside of my parents house. I've done this many times before, but never have been able to stitch the images back together again once I made it home. Photoshop to the rescue. Photoshop made it ridiculously easy to align the images and blend the colors. As proof I present this:

Thursday, October 11, 2007

Coding Puzzle

Supposedly this is one of the Google Interview Questions:

There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1].

When I first looked at it I didn't know what to do with it. I think a lot of it had to do with the fact that I was busy with work and didn't take the time to think about it. So today I was driving and came across an answer. Here is my proposed answer written in ruby (the machine I'm doing this on didn't have a C complier but it did have a ruby interpreter). Pardon my ruby style, I'm still new at it.

Also, it has a bit of unnecessary code to print out the multiplications that are happening (proof to me that it worked)


#Total O(2n) = O(n)
def SecondArray(orig)
arr2 = Array.new(orig.length,1)
strArr = Array.new(orig.length,"")
#First Loop O(n)
arr2.each_index do |x|
if(x != 0)
arr2[x] = arr2[x-1]*orig[x-1]
char = ""
if( strArr[x-1].length > 0 )
char = "*"
end
strArr[x] = strArr[x-1]+char+orig[x-1].to_s
end
end

temp = 1
i = orig.size - 1
tempStr = ""

#Second Loop O(n)
while (i >= 0 )
arr2[i] = arr2[i]*temp
temp = temp*orig[i]
char = ""
if( strArr[i].length > 0 && tempStr.length > 0)
char = "*"
end
strArr[i] = strArr[i]+char+tempStr

tempStr = orig[i].to_s+char+tempStr
i = i-1
end

i = 0
strArr.each do |x|
print i,":",x,"\n"
i = i+1
end
print "\n"

arr2
end


arrSize = 10
arr = Array.new(arrSize){|idx| idx+1}
#print arr
arr.each{|x| print x-1,":",x,"\n"}
print "\n"
arr2 = SecondArray(arr)

#Print the resulting Array
i = 0
arr2.each do |x|
print i,":",x,"\n"
i = i+1
end
print "\n"

Sunday, October 7, 2007

Maths

I always loved Maths. That's why I wanted to post this video about it.

Thursday, October 4, 2007

Frog





I found a frog. Unfortunately I had to let it go (well, if I must be honest he hopped away)