Filed under: Algorithms

Haiku

No, this is not the operating system. Sorry to disappoint. This is actually an interesting question i came across a few days back. The problem is actually quite simple: code generate as many Haikus as the user wants. Now, why this got me interested is because i used to write a couple of Haikus myself. And i was decent at it as well (it was enough to get a couple of them published in my college magazine). So i sat about thinking what the possible methods of generating Japanese 3 line poetry with a 5-7-5 syllable rule via code be possible. Here is one idea that bounced my mind today and i would like to share it.

Read the rest of this post »

Name and Address

As a south indian, with my surname coming before my own name, unconventionally, i have always had all the issues in the world trying to fill forms right from my child hood days. My name would figure in ten different manners at ten different places. And quite frankly it is a matter of great importance to any sapient being, his identity i mean. Another such issue is that of ones address. Now, even here i have had a lot of explaining to do every time i had to change SIM cards for Mobile phones, or while getting official documents processed. So, i thought with the on set of the new age information technology, and everything having an eVersion, forms (especially) official ones will not be far behind and they might just resolve some of these issues. But, as luck (or poor efforts) would have it, it has not. Every now and again i still hear people complaining about the issue of mismatched or wrong addresses especially because there is a great diversity in the manner how a Human Being identifies himself. Now, let me clarify, while the instruments of identity are virtually the same across the globe, i.e his Name and the Place where he lives. The issue comes in the manner in which these two entities are conveyed. The diversity comes here. And this is where i feel that as responsible software developers we must ensure that the customer must be given the freedom and flexibility to express and represent his name and address the way he deems fit, not us. And do not tell me that it is not possible.

Read the rest of this post »

My First TopCoder Problem

Well, i was looking into some old and favorite codes and algorithms i developed while in college. That is when nostalgia hit me a little when i got reminded of my first Top Coder problem. It was a witty problem, which hardly required any coding skills, but expected you to be a real thinker. So here it is - used in the Single Round Match 449 Round 1 - Division II, Level One, The Mountain Road Problem:
Media_httpwwwtopcoder_aekkh
Problem Summary: This picture represents a probable path your friend took while he was vacationing in the mountains. Now the mountains are represented as right angled isosceles triangles, with their hypotenuse lying on the ground. The entire trail or the path taken by your friend is guaranteed to be continuously along the slopes of the mountains. Thus, e.g. in the given picture, your friend took the path shown in bold lines. Given the start and end points of all the mountains (the mountain co-ordinates, assuming the base as the x-axis starting from 0), what is the total distance traveled by your friend. For instance, the mountain co-ordinates in the given figure is: {{0,5} , {3,9} , {4,6}} I will leave the answers for you to figure it. Trust me it is simpler than rocket science. Hint: Try using high school math, you should get it.

Combinations

I like things to be simple. And i like it better when i have simple alternatives to complicated solutions. One such problem was that of finding Combinations or make all possible selections from a given set of things. I had this as a part of my course in my second year of engineering. Most of us solved it using a weird recursive approach, which has haunted me till date. Never quite got the complete grasp of it. Well, that is because i found a simpler, sweeter and much more elegant way of finding C(n,n).

Read the rest of this post »