Got it done, 14 hour marathon today. And was a code test, for an interview, not a review.
I fucked up a bit due to exhaustion.... I had a very long if/else chain that called a different function in each "if" clause.
I realised too late I should have used a rules engine, but I was concentrated...