Friday, September 28, 2007

Redundancies in google search design


Isn't it a bit redundant or what?

Tuesday, September 25, 2007

Sudoku verifier using bit fields

A while back, a friend of mine had this idea of writing the most efficient sudoku verifier.

So I thought I would give it a shot. And this is what I've come up with:

char VerifySudoku(char grid[81])
{
   unsigned int bitFlags = 0;
   unsigned short buffer; // to speed up things
   char r, c;

   for (r = 0; r < 9; bitFlags = 0, ++r)
   {
      for (c = 0; c < 9; ++c)
      {
         buffer = r/3*3+c/3;

                     // check horizontally
         bitFlags |= 1 << (27-grid[(r<<3)+r+c])
                     // check vertically
                  |  1 << (18-grid[(c<<3)+c+r])
                     
// check subgrids
                  |  1 << (9-grid[(buffer<<3)+buffer+r%3*3+c%3]);
      }
      if (bitFlags != 0x7ffffff)
         return 0;
   }
   return 1;
}



Normally, one would have 3 loop one to scan horizontally, the other to scan vertically and lastly one to scan the 4 subgrids. If any one of that contain duplicated number, the grid is invalid. But here, one is enough. I scan 3 of the criteria in one single loop. Nothing fancy here, just the work of a boring soul. Haha...

Monday, September 24, 2007

Writing the shortest code

If you have not heard about the web site http://golf.shinh.org, a short introduction. It's a site with a list of programming problems, and people are expected to submit their shortest code to solve the problem with their language of choice.

Just to have some fun, I participated in the "FizzBuzz" category. Basically, all you have to do is: Print integers 1 to 100, but replace multiples of 3 with "Fizz" and multiples of 5 with "Buzz" and multiples of both with "FizzBuzz". Simple right?

Shown below are some of my solutions. How short can you go?

PHP: while($i++<100)echo$i%3?$i%5?$i:'':'fizz',$i%5?'':'buzz',"\n"

C: main(i){while(printf(i%5?i%3?"%d\n":"Fizz\n":"FizzBuzz\n"+(i%3?4:0),i),i++<100);}

This take advantage of ternary operation ?: in C. Also, look at how we can "offset" a static string by using an integer. For example let say u have a character array "Hello" in C. printf("Hello"+1); will print you "ello" on the screen. Pretty nifty no?

eGenting programming competition 2007 experience

On the 22th of September, me and my friends participated in this year's programming contest. In my case, I managed to complete (or almost) 2 questions. The Financial Statements (report) and the Air Polution Monitor.

For the first question, I (believe) I almost nailed it but with mistakes here and there nonetheless. The code that I wrote was also extremely inefficient. It was a pain to write a program without a computer or with a decent IDE like NetBeans. I guess my programming has got rusty by being overly dependent on IDE.

For the forth question, I did slightly worse than the first question as I got some of the concept wrong. For example, for the file reading part, I read the wrong function (I used a binary file reader) and thus it won't work. What an idiot!

As for the other 2 questions, well, they are blank, as I had ran out of time.

Overall, I feel that the questions are getting *slightly* easier as the year goes by, but still considerably tough for most students. Either that, or my skills are improving. Haha!

For those who are interested at looking at the questions, heard over to http://www.searcy.com.au/comp_epilogue_2007.html. The solution is there as well.

If nothing comes out of it, well, at least it was a great experience.

Thursday, September 13, 2007

First post

You know some people are willing to sacrifice anything just to have the chance to say "First!" in a forum or commentary section? Well, I don't have to, since this is my own blog :).

Well, this is my first blog post, so let me introduce myself.

My name is Simon Lim Hao Wooi, born 1984. I'm currenly Year 3 student at the University of Tunku Abdul Rahman, studying computer engineering. Think of it as a little bit of Electronics and computer science.

I started my interests in computer by doing some web design and web-based scripting. Thus, one of the first language that I learned happens to be ASP. Well, technically ASP is not a language. But at that time, VBScript is the only way you could use to do ASP. I was quick to switch to the "open source" side however, by learning PHP and subsequently fall in love with it. I never look back.

Like all things, people change. Soon after I got bored of doing plain old HTML page (It may be generated by ASP, but it's still plain old HTML), JavaScript came along and changes everything. All of a sudden, you could made all sort of cool, interactive stuff with a plain old HTML page. The funny thing is I've been playing with JavaScript for so long that it would later be collectively called AJAX, along with the advent of XML and the rise of asynchronous function calling.

Later, I would start moving myself out of web development, and dived myself into the world of software development. That's where I started playing with C and C#. That's also the time I introduced myself to dotNet. Slowly but surely, I realized that programming is like like writing poem. Without knowing the algorithm, you don't know what to write in the first place. That's why, nowadays I like to solve hard problems using programming. I begin visiting topcoder.com for interesting problems to solve. After all, what is so fun with programming if you are not solving any problem?

Currently, I am working on my AI project entitled "Machine Learning Approach to Real Time Unconstrained Multiple Vehicle License Plate Recognition". And 1 more year before I graduate. So that's all about me for now. And thanks for reading.