I get similar times (~ 15 sec), and I also use map to store instructions. I briefly tried with ETS, which shaved a few secs. One thing which I thought of, but didn't try was to optimize the case where the current instruction is 0. In that case, you can skip extra map store/lookup and immediately move on to the next iteration (though you need to somehow indicate that you made two moves). I didn't really have the time to try it out, and it would uglify the code, so I just left it as it was.