Skip to content

Clojure TopCoder Timelapse, Rainy Road, SRM 525, Div II, Level 1

December 1, 2011

I figured out how to make a timelapse video. Yay! Then I decided to tackle another topcoder challenge. RainyRoad –

At the beginning of the video, you’ll notice that I have my browser open – I hadn’t read the problem statement yet, which is dangerous since it could be a really tough problem!

Turns out, it was a dead simple problem. At first it looked like I needed to do some pathfinding (was about to brush up on a*).. but then it was just a matter of checking if both sides of the road is occupied with a “W” or not.. Fairly simple.

So I recorded myself building two solutions and have checked in another (better, imho) solution into the mix. The video is recorded at 5 fps, and each frame is 5 seconds apart, so each second is 25 real seconds..

Take note that I had not prepared at all for the problem. I hadn’t created a project yet or setup anything on my emacs. In the first second or two you’ll see me ‘lein new’ and cd to the new project folder. And then a little later start the swank server for emacs to connect to (about 15s in).

My first approach was to map pairs of path together so that I could just test each pair individually – the second approach, i didn’t bother with that, just doing a for over and index range, concating the letters together and checking for “WW”, then filtering the result for the word “NO” and check the count

The third approach, which you can view here as the function (another-reachable) was a lot more interesting – It interleaved the characters, then used a loop / recur to take pairs off the resulting array, concat the characters and check for “WW” – returning immediately with “NO” if not possible to cross.

You’ll notice that I’m running functions in a *slime-repl clojure* buffer – that’s connected to my running project (lein swank), so I could fire off a thread and have it continue without me being connected.. that’s pretty cool 🙂

Otherwise – enjoy the video – As always, feedback is really appreciated 🙂

From → Coding

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: