Showing posts with label Code Challenge. Show all posts
Showing posts with label Code Challenge. Show all posts

Sunday, January 4, 2009

Fun with card games

I just published one of my holiday pet projects on Codeplex. It's a very basic framework for building your own card games in .net.

With time, I'll also publish some sample projects, and hopefully even expand the project to include some basic AI logic as well.

Check it out: http://www.codeplex.com/CardGameLib

Even though it's still missing a lot of parts, I've already begun to use it for 2 other pet projects. One is a code competition I plan to put out soon - just looking for price-sponsors now, the other is a web-edition of the classic 500-Rummy card game, a game that I really enjoyed growing up - and still play when I'm vacationing with my family. Card games are an excellent form of entertainment - and remember, there's more than poker and blackjack to life.

Drop me a line - or leave a comment, if you want to contribute to the project, sponsor a price for the upcoming code-competition or just have an opinion to share :-)

Tuesday, July 10, 2007

Code Challenge: Michael the Math Maniac

Time for another summer code-challenge. Hopefully this one is a bit easier than the last one :-)

Mr. Michael was a lucky man, cause today, 20070710 (ISO standard) was his birthday!
But Michael wasn't your average lucky birthday boy. He was a Math Maniac. And on this special day, he was wondering: How many of the numbers between 0 and 1.000.000.000 contains the ciphers "20070710" (in that order) somewhere within the number?

Design a method int CountNumbers(int min, int max, int SequenceToFind); that returns the count of numbers which contains the SequenceToFind.
1st prize goes to first valid entry, 2nd prize to best performing entry.
The prizes are still "honour & mocking rights".
May the best developer win.

Friday, July 6, 2007

Code Challenge Results: No luck for the Hash-Party

So far there hasn't been a lot of entries to the latest Code Challenge so I suppose I might have overestimated the abilities of you, my honorable readers.
In fact, the only entry I received was from Peter Thygesen and he admits to actually just having adopted an algorithm by Paul Hsieh.

However just for the fun I compared it to the build-in string hashing algorithm (.GetHashCode()).
The comparison I did was fairly simple: I took 1.000.000 fairly random unique strings (well - actually Guids as strings) and timed how long time it cumulative took to run the algorithms. I also checked how many duplicate hash-codes each algorithm resulted in.
It turns out they were pretty equal.
The build-in algorithm had 114 duplicate hash-codes and took 15275 ms. while Mr. Thygesens entry had 115 duplicates and took 15318 ms.

Thanks for playing, Peter - but I think we have to declare this a no-win :-)

Monday, July 2, 2007

Code Challenge: Fun with Hash

No, this is not what you expected, crackhead. This post doesn't include getting high on anything stronger than your coding skills. It's time for another code challenge!

The challenge
Sometimes it can be very handy to make a small fingerprint of a piece of textual information so you can easily compare it to other pieces of text and check if they are identical without doing a full textual comparison.
The friendly folks at Microsoft have even been kind enough to include a "ToHashCode()" method in the .NET framework, but in this challenge I kindly ask you to ignore that.
The challenge is to code your own method that returns an integer hashcode for any string, so that two identical strings will have the same hashcode and that probability of two different strings sharing the same fingerprint is as small as possible.
So, write a method with the signature: static int MakeHash(string s); in C# and post it as a comment here.
Any posts that use ToHashCode(), MD5, or any other build-in hashing mechanism is disqualified along with posts that is almost identical to prior entries.
Post before friday and I'll make comparisons between the submissions on two different parameters:
  • Performance
  • Duplicate Hashcodes for non-identical strings

Good luck, Gentlemen!

Thursday, June 28, 2007

Code Challenge: "John the courier"

Yet another brillian idea popped into my mind today: Why not celebrate the rainy summer with a nice indoor competition - a Code Challenge!


Through the next couple of weeks I intend to publish a couple of challenges like the one below.

Think fast, solve the problem and post it as a comment!

The various challenges will have different winning criterias. These could be: "First valid solution posted", "Valid solution with fewest code-lines", "Funniest approach", "Best Performance", etc.

The Winner will win ... well... the honour along with mocking rights over all other coders in the world (at least those who read this blog and who didn't win).

We'll start off with an easy one...



Challenge #1 "John the courier"

In John's little world there is n cities, named by numbers starting at 0. In every city there is a parcel that's supposed to go to another city in John's world.

John live in City no. 0 and starts by picking up a package there. Then, whenever he delivers a package in a city he takes the package from that city and takes it to where it should go.

The distance between the cities is oddly enough the same as the difference in their names (e.g. the distance between city 10 and city 7 is 10-7=3).

John starts off his day with receiving a list of where the parcels in each city should be delivered. Now, John wonders: How far will I have to travel before I get back to my home (City 0).

Suggest a method that takes an int-array where the city is the index and the value is the destination of the package in the city (like this: int CalculateDistanceToHome(int[] CityPackages);) that returns the distance John must travel before he gets home. You can assume that the packages are distributed in such a way that John will always eventually get home.
First valid solution posted is the winner. Bonus points for recursive solutions.
Let the games begin!