Technology: April 2008 Archives

Butterflies within! :)

| | Comments (9)

Awrite this is confusing.. i got two three cool guys preparing the questions for two mega programming events and they're the judges for those two events! damn did you read that all too well?? This is sick man.. this is insane in a way that puts greed in my heart :P

Munir Usman is handling things in Procom's speed programming competition and Noman Shaukat and Sarfaraz Soomro are handling the same stuff at TechElite.. these days I'm trying my best to send as many gifts to all three as possible!

Ah well, its nothing like that.. i am such a good boy i even rejected 50:50 and 60:40 offers! :P (No! that's just a joke you bottle of coke). Well, this is tricky.. we had this programming competition held in our uni where the best of KIET were competing. I came at the top luckily ;) having solved 3 out of 5 questions in that 90 minutes competition. But getting the first spot within KIET was no big deal to be honest. I think Procom and TechElite are gonna be real testers for sure.. where you have to control the amount of sweat you get... that basically means the amount of pressure you are able to handle silly!

Ah well.. peace :)

My brother Tariq (whose beginning to become a serious web design guru) has made his own site. Wish you all the best bro! I like.. no.. i LOVE the introduction at your site! And he had a play list on his site where I saw this James Blunt song titled 'Tears and Rain'. I kinda liked it a lot!

How I wish I could surrender my soul;
Shed the clothes that become my skin;
See the liar that burns within my needing.
How I wish I'd chosen darkness from cold.
How I wish I had screamed out loud,
Instead I've found no meaning.

I guess it's time I run far, far away; find comfort in pain,
All pleasure's the same: it just keeps me from trouble.
Hides my true shape, like Dorian Gray.
I've heard what they say, but I'm not here for trouble.
It's more than just words: it's just tears and rain.

How I wish I could walk through the doors of my mind;
Hold memory close at hand,
Help me understand the years.
How I wish I could choose between Heaven and Hell.
How I wish I would save my soul.
I'm so cold from fear.

I guess it's time I run far, far away; find comfort in pain,
All pleasure's the same: it just keeps me from trouble.
Hides my true shape, like Dorian Gray.
I've heard what they say, but I'm not here for trouble.
Far, far away; find comfort in pain.
All pleasure's the same: it just keeps me from trouble.
It's more than just words: it's just tears and rain.

Just for fun, I jumped in to solve a few programming problems that you get when you participate in one of those programming contests. Below is one such problem that I took out from the MIT Programming Contest Practice Set and came up with a C# based solution. The solution files are provided for download below. I was too lazy to create too many test cases of my own and I've only checked the solution on the given test cases plus a few of my own. But I feel it should work fine on others. Programming gurus are welcome to suggest improvements, after all, I am of the opinion to drop the programming best practices when solving such problems in quick time. Bottom line: Kaam hogaya poora, bhaar mei jaye Noora.. where Noora is best practices ;)


The Problem

A common task performed by word processors and desktop publishing programs is justifying a paragraph of text, breaking lines at appropriate places given a fixed column width. In this problem, you will write a program to perform simple text justification.

Input to your program will consist of pairs of lines. The first line in each pair is an integer between 0 and 100. If this number is 0, the program has reached the end of input and should terminate. Otherwise, the number indicates the maximum number of characters on each justified line output by your program. The second line is a paragraph to be formatted; this line contains only printable characters (i.e., ASCII 32 through 126), and is guaranteed to be
no longer than 2000 characters. In addition, this line is guaranteed to contain at least one character that is not a space. Your program should then format the paragraph according to the rules described below, then write out the resulting formatted lines, followed by a blank line, to standard output.

Each paragraph should be formatted as follows:

  • Each formatted line should not contain any spaces at the beginning or at the end, and should be no longer than the maximum width specified as the first line in the pair of lines in the input.

  • Line breaks should occur only at spaces in the original input paragraph. If a "word" will fit on a previous line, it should not be placed in the following line. In other words, each line should be filled up before the next line is started. Here, a "word" is defined as a maximal contiguous sequence of characters that are not space. The length of each word in the input is guaranteed to not exceed the given maximum width.

  • All spaces at the beginning of or at the end of the paragraph should be ignored. The number of spaces between each pair of adjacent words in the input paragraph should be preserved in the output, except at line breaks.

Again, please be reminded that exactly one blank line must be output after each formatted paragraph to signify that the program is done with the paragraph.

Sample Input

10
Please make check payable to Harvard Univ.
20
Take the T to Kendall.  Walk across the street.
0

Sample Output

Please
make check
payable to
Harvard
Univ.

Take the T to
Kendall.  Walk
across the street.


Note that there is one blank line at the end of the sample output above.

Downloads

TextJustificationProblem.zip (Contains the problem statement, the source file and the sample input file)

I've been writing a lot about things not techy enough to have that balance between what I do most of the time and what I want to do most of the time. I often find it challenging to pass my third-rate programming skills to this blog and come up with things the search engines love.

For instance, the posts which I made regarding my OBJ Loader and other similar posts, I am able to get a lot of hits on them. People search for these things and they come over and find something useful. I, on the other hand prefer writing my own stuff which has far less significance to anyone else (if at all).

I've been in the middle of some really useful drafts that are related to software development. I'm thinking of thinking about coming up with more of such tech-filled curry so that my friends (or anyone) coming in from Google or other search engines are able to find what they're looking for.

After all, it feels so much better to help somebody than to type all the non-sense you have to fill your blog up. Plus, I'm so kinda occupied in other things that I usually want to spend most of my time in useful things. I personally think that I read blogs of other people more for availing something valuable than their personal "rants". Anyways, that's just a way to feel better for everybody, it depends on personal taste of what makes them feel better.

DigitalEyez Experience

| | Comments (10)

Old memories brought back when I visited FAST NU Karachi Campus today. The memories were incidently of FAST NU's Lahore Campus, which is built (almost) exactly like the one in Karachi. It was DigitalEyez - the event people of creative flare were looking forward to. I went in quite late, and I saw a welcoming group of people over there. I was with my friend Sarfaraz and we were treated like special guests which was surprising. BTW this 'special' is not the one you may end up thinking about. Faisal Abidi, who was the participant and guest relations executive showed us around. I'm almsot certain he took us as if we are from press or CIA, or he was damn too generous in helping us have a nice experience. Anyways, the good thing was, we were happy! We settled into the auditorium for the short movies, and some of them were really well made, and different. I liked how the audience enjoyed.

Since we were late, we only discovered the web design competition lab with judges trying to figure out what design to choose as the winner.

Afterwards Sarfoo had to have his camera looked after by the Sony service centre people, so we left just before the prize distribution ceremony over there.

I feel bad that I was not able to participate in the web design competition, but anyways, it must be better, that is why God disabled me from taking part in the competition.

I noticed that Procom is coming, so I'll have to try and find time to sharpen my algorithm skills, just in case I decide to dive into Procom. Strangely enough, this time its Procom.net instead of Procom, and that .net is for what? I don't know. That's not a domain name or anything, its just a name. I know Microsoft has .net but looking at what Procom offers, I am still confused what that additional ".net" is doing in there now.

Anyways, cheerz!

Happy Times :)

| | Comments (2)

Except for one thing: Youtube is not opening up :( and I am tired of watching all those previously downloaded videos. I'm not sure what's happening.

Other than that, I am having so much fun these days! We had an ammmazing story back in the old pavillion! Awrite, I'm into code words here so I better shut up :)

Its so much like as if the whole world is going through a while loop and I am an argument to some interesting function being called in that loop!

Internet TV is a cool thing. I am almost sure about the fact that one day, the TV sets at our homes will be useless as on demand iTV (yepp) will overtake the usual format for the current style the TV works. The computers will become much more convenient that housewives will begin to watch their favorite soaps on demand and that means no late chaye and dinner for ghar walas! :) Or daddy will be ready all the time to take the kids to the park as his favorite sports show can always be played back again later! If you're confused about what the heck I'm talking about, don't be, these ideas are based on something I am in touch with these days :P

Anyways, please please pray for my YouTube to be back soon!

YUI saved the day!

| | Comments (0)

Yahoo User Interface (YUI) Library is really a wonderful package to have. It's free and amazingly useful and powerful. Today was one of those days when I was stuck at something, some spooky little thing that just wasn't coming up right. Here comes YUI, I scanned through the wonderful YUI developers site and found the right component for my use.

Yahoo has some excellent people working for it and tools like YUI are, well no surprise given the amount of talent this company has inside.

Thanks Yahoo, your awesome library made me happy today :)