Programming challenges

One of the interesting aspects of looking for a job this time around is that most of the companies that I have applied at have asked me to do a programming challenge as a kind of weed-out step. It has been fun and a good way of keeping in practice. In fact, I have resolved to learn at least one new feature of the programming language that I am using for each one.

Time series framework

My latest programming challenge is to build a framework for time series generation. The framework will take a function $f$ that looks at the $n$ previous timesteps and returns the next timestep. The other goals are:

  • Efficiency

    Adding a new timestep should be a $O(1)$ operation.

  • Ease of debugging

    If an error occurs in computing the next timestep, the stack trace should be easily comprehensible and show the current state of the time series.

  • Traceability

    It should be possible to see the differences between two different functions.

Ideas so far

This seems like the perfect time to learn about monads. Yikes! I've tried before, but have never seen a practical use for them. As far as I understand so far, they should be very good for storing the state (i.e. the previous $n$ timesteps).

A simpler solution might be just to use lazy sequences. There's not much to such a solution, so I might just implement it first and then try to replicate it with monads. In this solution, the previous $n$ timesteps are simply the last $n$ elements of the lazy sequence. Getting those elements might be tough to do in constant time, but I have a feeling it's possible.

On the debugging front, there shouldn't be too much complexity: it should just be a combination of try, catch, and throw. There's also clojure.stacktrace if I want to get even fancier.

As far as tracing goes, I might have a look at tools.trace to see if there's anything interesting there that I can use. I think that monads might provide another way of doing the same thing. We'll see which is simpler. It might also be nice to use incanter to display the differences between two (or more) different functions.

On to the coding!

blog comments powered by Disqus