OJ’s rants What would OJ do?

25Jul/082

Another Quick Coding Challenge

I was about to head to bed when I stumbled across another interesting coding challenge. Since I had another half hour or so to kill I thought I'd give it a shot!

24Jul/080

Validating use of Parenthesis

Yet another programming challenge appeared on dev102 the other day, and I thought that this time I'd post my solution here in the blog rather than letting it get lost in the depths of the comment thread!

14Jun/0866

An Interesting Little Problem

This post was inspired by a recent interview question that was posted over at fsharp.it. It's one of those neat little questions which looks really simple on the surface but is quite tricky.

6Mar/070

More RCE Goodness

I'm quite excited. My previous RCE solution and tutorial has been approved!

Plus, the first keygenme that I've ever written is now approved and available for download. So if you're up for a 64-bit RCE challenge, go check it out (or download it directly from here).

Feel free to let me know how good/bad/ugly you think this stuff is!

Filed under: Challenges, RCE No Comments
4Feb/076

Challenge #3 – Day of Birth

I haven't posted a challenge for a while, so I thought I'd get you all thinking again with another basic little program. It's simple, but there are a stack of possible solutions, so I'm expecting a bit of variety. So here we go.

Write a program that asks the user for their date of birth using the date format YYYY-MM-DD (eg. 1978-12-05 in my case). The program should respond by telling the user what day of the week they were born on.

You're allowed to use any language you want, but you're not allowed to use the built-in date object functionality other than to determine the current system date. That is, you can't date difference functions to determine time that's passed. You have to figure that out for yourself.

For those C# coders, don't even think about posting: dateOfBirth.Day :) You're supposed to do the hard bit yourself

Anyway, it's easy peasy :) Don't forget about leap years and stuff! I look forward to seeing your answers. I'll post up a solution in a week or so. Let me know if I haven't been clear.

Filed under: Challenges 6 Comments
12Oct/0612

Challenge #2 – The Recursive Ruler

I posted this problem a little while ago on the site I used to run, and it proved to be an interesting one that resulted in quite a large collection of solutions from the posters. So here it is again.

Your job is to write a program that generates a text-based ruler. For a clearer definition of what I mean, see the little text pic below:

|                               |                               |
|               |               |               |               |
|       |       |       |       |       |       |       |       |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

The user of the program must be able to specify a couple of parameters: those being the height of the ruler and the number of sections in the ruler (at the top level). In the above example, the values would be 6 and 2 respectively. Another example, using the values 3 and 3 would result in:

|   |   |   |
| | | | | | |
|||||||||||||

The only other thing that you have to do is make sure that your solution uses recursion instead of iteration. Feel free to use any language you want, you can write to screen or to file, it's your call. But you must use recursion.

I look forward to seeing your responses. :) Happy coding!

Filed under: Challenges 12 Comments
15Sep/068

Who’s up for a challenge?

Before starting this blog up, I spent a bit of time thinking about the kind of things I would like to talk about which other people might find interesting. I also wanted to find some areas of discussion where people would be interested in giving me feedback and comments containing their thoughts and opinions so that I can learn something and possibly benefit from other people's experience. While this is all very enlightening, it can be fun and it can be, shall we say, political.

So as well as having lots of industry-specific rants, posts on what's considered good and bad, and large chunks of text relating to experiences while out on site working for clients, I thought it'd be a good thing to post some other bits and pieces that are a bit more light hearted, and dare I say it... FUN!

Way back before I went to the U.K. I used to have a site up and running that had a small community of people interested in programming - specifically game development. While this site is long gone, never to be remembered, there were a few things that we used to do there which I thought were really good. One of which was listing programming challenges. Every now and then I'd come up with (or rip off) a programming challenge that I thought would be a good exercise for members of the community to undertake. It was surprising how many people were interested, and we ended up with many responses and submissions containing solutions to the problems.

The beauty of it was that people learned a lot from the exercise - especially from each other's varied approaches. They would come up with a solution and be eager to post it. After noticing that someone else had created a "better" solution than them, members would go away and try and improve what they had. It was great, as it bred a mindset of iteration and improvement, and over time most of the community members ended up being comfortable with the idea that their first solution generally isn't perfect and they immediately look to make it better.

I'm of the view that the first solution that you write to solve a given problem is designed to give you a better understanding of the problem space. Sure, it's not always the case that you can throw away the code you've written (depending on what you're working on, and what timelines you have to adhere to), but if you can it's a good idea to do it and start again fresh with the knowledge you've gained from your first attempt.

I would like to get this type of thing going again. I'm going to get some ideas together for problems and start posting them here for other people to have a stab at. I'll be giving some of them a go as well, and if people are interested in sharing their solutions and discussing them, they can post their solutions as comments. If the idea becomes popular and the number of submissions goes up, then I may think about setting up a basic Coding Challenges forum for the discussion and submission of the problems and solutions. If people don't like it, I'll probably continue to post them anyway just in case someone at some stage finds them as interesting as I do :) If anyone's interested in seeing my solution, then I'd be happy to post it.

The problems themselves will most likely be small. I won't be suggesting that people should go away and write a 3D rendering engine just to see the frames-per-second they can achieve on a 386! The problems will have a very small scope - meaning that solutions can be built quickly, and people won't feel that they need to put a massive amount of time in to get the results required. Hopefully they'll be quite challenging despite being small in stature.

One thing I will attempt to do when writing these problems up is make sure that the specification forces the programmer to do as much of the work as possible - without relying on the supporting framework or library set that comes with the language. In general the problems will not have a target language (or language set), but there may be cases where I state that the problem is intended to be solved using C++ or Miranda!

I hope that you'll find the challenges interesting, and that you'll perhaps find the time to give a few of them a go to exercise the mind. I think some of them will be more useful to beginners learning the ropes of development, but I can't see why experienced programmers shouldn't give them a shot. There's always the possibility that we'll learn something.

So let's begin with the first one that's popped into my head. It's a bit of a classic problem, but there's still a chance that people out there might not have heard it before - or more importantly attempted to solve it themselves in code. I first heard about this problem through a friend of a friend of a friend of a ... you get the idea ;)

Challenge #1 - Linked List Loops

"What do you think is the most efficient and resource-friendly way to determine if a singly-linked-list contains a loop?"

When you have an instance of a linked list, it is usually NULL-terminated, that is, the last reference is a NULL reference which tells you that the end of the list has been found. The question asks how you determine if the list is not NULL-terminated, instead the "last" item in the list points back to another item in the list (thus creating a loop in the list).

To solve this problem you will need to have an understanding of Singly-linked lists. You don't need to write code, I'm just interested in the algorithm you'd use.

Sounds easy, and there are quite a few ways of doing it. So give it a shot! I'm interested to see what you guys come up with.

Happy problem solving!