Sunday, January 27, 2008

Teaser!

Another interesting pick from Topcoder archive.

You are given 4 numbers: CountA, CountB, MaxA, MaxB. and you have to make a Beautiful string out of it. Hold on a minute to find out what is actually a Beautiful string.
CountA signifies the number of A's at your disposal,
CountB signifies the number of B's at your disposal,
MaxA signifies the maximum number of consecutive A's in any substring,
MaxB signifies the maximum number of consecutive B's in any substring,

A beautiful string is a string you can form using CountA number of A's and CountB number of B's satisfying the MaxA and MaxB constraints.

I am trying to find the link with test cases and better explanation on topcoder site, will update the post with the link as soon as i get hold of it.

Meanwhile, a sample input-output sequence would be
input 3 4 1 2 outputs 7
bababab

input 20 21 1 0 ouputs 1
a

Its a simple solution and we(srujan and myself) had cracked it pretty easily. We wanted to code it to try difficult and general cases from the site. In the process we found a code snippet that solved the problem. It was very elegantly written and more importantly taught us a new operator in GCC( works only GCC compiler and not in .NET)

a < ?= b, based on our interpretation translates to "if a < b then update value of a to b"

Any comments on the new findings are welcome..

Saturday, January 26, 2008

Hello World!!

Let me first make it clear what this blog is destined to achieve :) . I created this blog due to the incompetency of my brain to remember my learnings perennially. So i will be posting anything even remotely connected to technology so that it will server as a reference in future. I assume it will help the readers too and more importantly give me their valuable comments along the way. Do not be surprised to see Math, Computer programs , few puzzles or even Philosophy related stuff in the posts :P. As for the uniqueness of a blog like this, i always believed in "Whatever you do is unique if you have never done it before because nobody can do it the exact same way you can :D" So here goes the never ending expedition...

I and srujan(IIIT buddy) were pondering on a couple of SIMPLE problems, i had to highlight "SIMPLE" for two reasons, one because its strictly relative and varies from person to person and second to stress on that fact that i am a novice at judging a problems difficulty. So please pardon me if you do not comply with me.

1) A analog watch is hanging on the wall behind you with 1 to 12 numbers, a hours and minutes hand, hour hand being a bit smaller than the minute hand to be able to distinguish. In front of you there is a mirror in which you see the reflection of the watch. You want a function which converts the time shown in mirror space to world time because you are a lazy ass to turn back every time you want to know the time and you surely want to call your girl friend strictly on time. Note, that even a primary school kid can solve it given time, judge yourself based on the time you took.

Will post few more interesting ones..