It’s getting closer and closer to the ACM-ICPC Programming contest in UCC this year so now more then ever we need practice. If you’re not up to speed on what it’s all about check out Carl’s first post on another ACM problem. So let’s get straight to the problem. I will present the problem in as clear and simple manner as I can, as the actual problem sheet is a little off putting if you ask me. You can download the pdf for it here.

The problem is all about entering your name into a high score table using a joystick. Quite like old video games where you would be presented with an initial string of A’s which moving the Joystick right and left selected a different character. Moving up and down cycled though the alphabet. Both these movements wrap around. Eg: If you move left at “A” you get to “Z” and if you move right at the last character you get to the first. So if I want to input the string “JAN” how many moves will it take me to do this? (23 😀 ) Moving left, right, up, down is counted as a move. So your task is to develop an algorithm that will find the shortest amount of moves to achieve this. For more information and sample input download the ACM problem sheet.

So there are the basics of the problem, though my explanation is not complete so do download the ACM problem sheet. I solved this problem myself today and I will post the solution in the next few days. I need to refine my solution as its quite crude. Oh, and my solution is written in JavaScript as I solved the problem by coding, so I needed something that would let me program loosely. So anyway, I challenge you, dear reader, to attempt this problem and post your solution in the comments.

Some words of inspiration and motivation. Anyone can solve these problems if they put their mind too it. I wouldn’t count myself as smart individual, but I worked at it and solved a programming problem from a prestigious contest. So, give it a go, even if you can’t solve it, the experience of thinking about the problem and an algothrim to solve is great exercise for your brain. Watch this place or follow me on twitter to keep up-to-date @C_McCann

PS: I have a live demo of my solution below. The JavaScript is obfuscated so you can’t peek (at my horrible solution). Oh, and beware that I haven’t refined the solution yet so it could crash.





WARNING: (Only works with WebKit atm)

There are bugs and certain inputs will crash the script, just to warn you. A refined solution with bugs fixed will be posted in the coming days with source code and explaination. Follow @Flaxproject and @C_McCann for updates

Do the magic

[ad#adsence_inline_banner_468*60]