Showing posts from 2014

How to create random files and folders?

During this week of one hour of code, this post refers to a quick and easy way to create random files and folders. Nothing complicated as it was the case in some previous posts. This one came out of a real at-work problem in Bing : in order to validate some scenarios, we wanted a cheap and quick way to create thousands of files and folders, subfolders too, in a semi-random fashion. A simple task. The 50 lines of code down below did the trick. I think the two key interesting points of this code for the novice developer are the following: a) A way to achieve something with probability N is to simply do something like this: Rand(0, 100) < N. I've seen junior developers trying complicated things - this should do the trick. These are the spots in the code where we do it. b) State control. Notice that that we use a simple depth variable to determine when we can come down a folder, or to keep creating subfolders. Just by increasing and decreasing this variable controls where we ar

The one gap in technical interviews!

I've been doing interviews at Microsoft for over 15 years now. When I looked at the system that tracks all the interviews that I'd participated in, I counted at least 500. First, let me make something clear: interviewing a ton of candidates does not make you into a great candidate yourself. If you look at my own performance as a candidate, looks pretty average: 6 attempts, 3 hires, 3 no-hires. I guess I'm one of those who feel way more comfortable on one side of the table than the other. I believe that in a good interview process, not only the candidate is learning along the way, but so is the interviewer. I love open discussions with candidates about technical problems, and it is very rewarding to me to discuss different technical ideas with folks who bring to the table different perspectives. Some other day I read an article that gave me an instant epiphany with regard to something so obvious that I have ignored in all those years interviewing candidates. As you may kno

Inception-Like Programming

When the moving Inception  came out in 2010, everyone thought that it would become the next Matrix sensation. It did not. However, the plot was interesting. In essence, folks in a dream (level 1) have a dream (level 2) where they have a dream (level 3) where they have a dream (level 4) where some action happens. 4-levels of dreaming. Now a dream by itself is already a very abstract entity, hard to grasp the concept most of the time. Never mind 4 levels of dreaming. It just so happens that a programming problem that I stumbled upon requires kind of the same paradigm of abstraction in order to solve it. Here is the problem gave to me by a friend at Microsoft: In the game 24 , you get four numbers and try to use +,-,x,÷ and () to make an equation using all four that equals 24. For example, if I gave you 4, 4, 6, 9, you might write: (4 + 4) x (9 - 6) = 24. One nifty thing about 24 is that it is actually the product of the run of the first four positive integers: 1 x 2 x 3 x 4 = 24.

2^(3^(4^(5^(6^(7^(8^9)))))) - Part III

The trilogy comes to an end! The solution to the problem has been posted on the IBM ponder this page . If you use the hint from the previous post, you'll notice that all you have to do is keep getting the last ~12 digits of the results of the exponentiation (basically one of two more than 10), and keep using those digits to raise the inner numbers, repeating the process all the way from 9 to 2. The ModPow function is your friend here. Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; namespace IBMPonderThisOctober2014 {     class Program     {         static void Main(string[] args)         {             BigInteger result = 1;             for (int i = 9; i >= 2; i--)             {                 result = BigInteger.ModPow(i, result, 1000000000000);                 Console.WriteLine("{0} => ...{1}", i, result);             }             Console.WriteLine("\nSolution: {0}", result % 10000

Machine Learning and Poems

"S he played out to me to me!!! in those two years till sometimes dropping from the devil foe, I triumphed!!! and singing the least some one! big words that cover "                                                - By ThinkPad Lenovo X220, 2012-? A poem is a work of art. But it can also be seen as a work of science! This post is about teaching a computer in < 600 lines of code how to create English poems. Well, poems in general are abstract entities, so if the computer is going to learn how to write poems, it will have to learn that poems are most of the time deeply abstract, and deeply complex to understand :) To a degree, that makes our lives easier. Ok, so how do we go about teaching a computer how to write somewhat valid (albeit abstract!) poems? We'll use Machine Learning. Machine Learning consists of building a model representing what you want the computer (the machine) to learn, and then instructing the computer to tell us what it learned off of that model