Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, April 4, 2014

Microsoft Sculpt Ergonomic Desktop Review

Here's what I just got:

Reason was that I've been doing a "lot" of writing and coding when at home and my old clunky keyboard / standard MS mouse was starting to give me wrist pain. I already have a MS 4000 Keyboard + Logitech Trackball in the office (which I took from home) and I can write code comfortably all day long. So clearly there was something that needed to be done for my home rig. I thought I'd give something new a shot. Out of the box:


 Has a raise bar for the keyboard as well (which I very much like):

I don't care for the numeric keyboard, so I like that it was separated. I left it in the box. My desk looks pretty clean:  

I have to admit : the best thing about this setup : the mouse. Its heavy, tall and nearly vertical. It feels like I am resting my hand on a ball. Very nicely done Microsoft!

Sunday, August 21, 2011

Prove intuitively that X * Y == Y * X

I needed an intuitive way to show this to my nephew (why is 6* 7 same as 7 * 6). Its really simple.

By definition of multiplication (Y * X) is read as "Y Xs are" which literally means X items stacked Y number of times. i.e. :


But notice that if we view this data horizontally it is Y items stacked X times i.e. X * Y!

therefore X * Y == Y * X

Enjoy! 

Tuesday, August 2, 2011

Programming Interview Question : Prove that a circle will be surrounded by exactly (and maximum) 6 congruent circles if each circle makes contact with this central circle and no circles overlap

I have known since a child that a tennis ball is surrounded by exactly 6 tennis balls. Here I show a glass being surrounded by exactly 6 glasses :







HINT1 : Use the nature of Equilateral triangles.


HINT2 : By Nature I mean angle :)




Solution : 
This image is pretty self explanatory (though not pretty ...... I a paper cup!)

And so if the centers of each surrounding circle are separated by 60 degrees the full 360 is completed by (360/60) = 6 circles.

Enjoy!

Saturday, July 30, 2011

Programming Interview Tip : What is the probability that when you open a random page in a phone book the contact you are looking for is in there?

Lets say the phone book pages are numbered from  1 - 1000. And assume that the contact is definitely there in the book.

So when you randomly flip open a book there are 1 of 500 choices that it is one one of the two pages that appear before you.

So the probability is 1/500.

Next Question : How many attempts will it take for me to be certain that the contact is there? 
Well you can NEVER be 100% sure .... for obvious reasons :)

Next Question : So how many attempts will it take for me to be 50% sure that the contact is found in one of the two pages that show up?
The 50% is called percent confidence in statistics lingo.
This is best solved by the difference from 1 for the probability of the contact NOT being on the page.
For each attempt to fail we need to multiply 499/500 . So for n attempts to fail it is (499/500)^n. So the probability of it being successful in n attempts is {1-(499/500)^n}
So you need to solve the equation :
{1-(499/500)^n} = .5
which is obviously :
(499/500)^n = .5
And taking log to the base 499/500 on both sides (using python) :
>>> math.log(.5,499/500.0)
346.22690104949118

n = 347 attempts

double verify :
>>> math.pow(499/500.0,346.22690104949118)
0.5

Monday, July 18, 2011

Programming interview tip : Finding anagrams

Find all the words in a list of words (listA) which are anagrams of a single input word (wordA).

Bad solution (the trap): 
look at all the possible permutations of wordA and find them in listA.

This is a terrible solution and has a complexity of countOfCharactersInWord(wordA)!
where ! is the factorial symbol :)

Good solution:
take all the characters in wordA and sort them. Then compare it with the each item in listA first sorting the characters of that item as well :)

In python :


This yields for my friend "omair" the following interesting (i made them bold) anagrams:
mario
arimo
moria
omari
maori
moira

I used the SCOWL wordlist for this. You can get the complete working code (including the wordlist) from here:
https://bitbucket.org/basarat/pyanagram/overview
Enjoy!

Thursday, June 16, 2011

How to be an awesome intern

Don't you just love the stackoverflow network? I do :)
This post really caught my eye : http://programmers.stackexchange.com/q/84396/8867

Basically I have seen interns become a burden in programming teams more so than in other fields. This is because a deep knowledge of how to write functioning softwares is something not taught in schools. It is something that only comes with self effort and internet research / books. So the intern's / new hires have a tendency to ask the senior team members questions at every small step of the way. And I feel that joels post hits right on home on how a new team member should actually behave : http://programmers.stackexchange.com/questions/84396/how-many-questions-is-it-appropriate-to-ask-as-an-intern/84398#84398 Quote:

Be respectful of your mentor's time by keeping a list of questions and asking them in batches, to the extent possible. Don't actually interrupt your mentor until you literally cannot make any forward progress without help.

A lot of times you'll learn a lot by struggling to find the answer yourself, even in cases where your mentor can teach you something in 10 seconds. For example, if you want to know where something is in the code, you can ask them (10 seconds), or you can spend four hours studying the code and trying to figure it out yourself. The advantage of the "four hour" option is that you will actually be learning 200 new things about the code, all of which will help you later on. Struggling to find your own answers can be a waste of time, but it can also be a way to learn a big complicated code base.

Needless to say if it's a programming question that doesn't concern your company's own proprietary code, you should try to figure it out yourself using the internet.

The section in bold is what I think is really important. Feel free to use stackoverflow for this. No team has enough resources (and perhaps quality) as stackoverflow :).

Other than this teams should have regular meetings to discuss stuff so that knowledge can be shared. Beyond that the internet and books (lots and lots of books ... start with the programming language essentials e.g c# essential / C# in depth and build up to the technology e.g. wpf / silverlight / wcf) are your best friend. 

Wednesday, April 20, 2011

Recursive Function Design 101

Everyone has his approach to how to start writing a function. For a recursive function as soon as you identify that the problem can be simplified by recursion, heres how you should structure your code :

  • First write for the simplest case and return. This would be the boundary condition on the function call. e.g. for factorial write the code for case when input == 0 || input == 1  
  • Build up from there. 
Basically if you put down the simplest case first and test it so you are sure it is reliable writing the rest of the recursive function becomes super easy. 

Enjoy!