Announcing: The Infectious Madness of Doctor Dekker


Coding for the day job eats most of my time. But when I’m not doing that, I’m working on other things – for myself, and in collaboration with others.

That's what I do. I write and I code things.

That’s what I do. I write and I code things.

This one’s still in progress, and probably won’t be released until mid-next year, but I’m going to announce it early.

“The Infectious Madness of Doctor Dekker” is a Full Motion Video game with Lovecraftian themes. Think “Her Story” meets Cthulhu.

The game framework is being coded by me in Node.js and runs on Windows, OS/X and Linux. My brother and sister-in-law are working hard on producing the content.

It’s currently in Steam Greenlight concepts. Feel free to take a peek / vote / follow / fave.


Javascript has won web scripting.

As such — I’m officially giving in to the darkside.

Javascript on the client. Javascript on the server. Javascript everywhere.

Why wrestle with multiple languages, when you can choose to just wrestle with one?

Node.js is now my new weapon of choice on the server for future personal projects. Runs on Windows, Linux and Mac. HTML5 browser for Web, Electron for Desktops, Cordova for Mobile.


Code Golfing – Smallest Multiple

Code Golfing is the art of taking some code and making it as small as you possibly can. Normally, it takes the form of a function and tests are run against it to make sure your code still works, after you’ve tweaked it for size.

I’ve avoided it, up until now, because other than a form of entertainment, it doesn’t have much useful function. In terms of production code – code that you can understand and easily maintain is much more useful than code that’s difficult to read, but smaller. Now that we’re in the age where it’s fairly normal to download 10gb patch files for games, aside from web pages, I can’t remember the last time I overly worried about the size of the source code.

Anyway. I tried some Code Golfing this weekend, and it’s actually quite fun. I learnt a couple of things, too about stuff I’d never try in production – like if you weld a for loop into an infinite one, by using a blank middle condition, then the compiler is intelligent enough to realise that anything which follows (including the usual default return) will never be reached.

Best of all – it got my brain sparking again.

The challenge I attempted was this one:

Given a positive integer n, find the first positive integer divisible by 2, 3, 5, and 7 with at least n digits. Return the result as a string, as n may be as up to 10³.

So, 1,000 digit numbers. The kind of territory I find fun.

I checked to see whether I could use the System.Numerics.Biginteger class. No such luck. At which point, the problem became how to easily cope with 1,000 digit numbers.

I could write my own Biginteger class, but that would take up a lot of characters. Being Code Golf, that would be a total no-no, but I could jury-rig something just for plain addition.

So, I quickly hacked together a couple of byte arrays to represent individual digits, started at 210 and just added 210 continually, testing to see if I ever reached n digits of use, and taking the result afterwards.

At which point, I ran nose-first into another Code Golf constraint: All solutions have to run in under a second.

While my solution was working and small, it certainly wasn’t fast – and it needed to be all three.

I realised that I needed a completely different approach – and what I ended up with, was this:

string smallestMultiple(int n) {
 // This solution uses several "Tricks".
 // The first "Trick" is realising that the number to be returned will always be
 // within 210 of 10 ^ n.
 // The second "Trick" relies on a combination of two divisibility rules, namely:
 // Anything divisible by 2 ends in 0,2,4,6, or 8
 // Anything divisible by 5 ends in 0 or 5
 // Combine those two rules, and it should be obvious that our number
 // must end with a 0. 
 // The third "Trick" is that for a number to be divisible by 3, the sum of all it's
 // digits must also be divisible by 3.
 // In combination with our first trick, for any numbers which have four digits or more,
 // we know that we will always have:
 // A 1, a number of zeros, and a number between 0 and 209.
 // Given that we know it must end in a zero, that leaves valid values for our number as:
 // 20, 50, 80, 110, 140, 170, or 200
 // The fourth "Trick" is that for a number to be divisible by 7, the sum of 
 // alternating sets of 3 digits from the right added and subtracted together
 // is also divisible by 7. So, again - for any number that has four digits or more,
 // the number we are looking for is going to look like this:
 // Either: 1 + a number of zeros, and 20, 50, 80, 110, 140, 170, or 200
 // or: 10 + a number of zeros, and 20, 50, 80, 110, 140, 170, or 200
 // or: 100 + a number of zeros, and 20, 50, 80, 110, 140, 170, or 200
 // Depending on how big n is. If n = 4, then it's 1, if n = 5 then it's 10,
 // n=6 = 100, n = 7 = 1 again (and 3 0's) etc.
 // We need to work out whether to add or subtract the 1, 10 or 100 to our
 // 20, 50, 80, 110, 140, 170, or 200 before testing by divisibility by 7.
 // If n=4-6, we subtract, if it's 7-9 we add, 10-12 we subtract, 13-15 we add, etc.
 // Note that because any other set of 3 digits are zero's, we can ignore them 
 // And now - to the code.
 // First off - for any number less than 1000 (n = 4), the answer is always
 // 210 (2 * 3 * 5 * 7)
 if (n < 4) return "210";
 // Work out if we're going to adjust the number by 100, 10 or 1. 
 int a = n % 3 == 0 ? 100 : n % 3 == 1 ? 1 : 10;
 // Work out if we should add or subtract that adjustment (1 is add, -1 is subtract)
 int b = n % 6 > 3 || n % 6 == 0 ? -1 : 1; 
 // Loop guesses starting at 20, adding 30 each loop
 for (int x=20;; x+=30)
 // if our guess modified by the adjustment is divisible by 7 - then we have our answer.
    if ((x + a * b) % 7 == 0) return "1".PadRight(n - 3, '0')
       + x.ToString().PadLeft(3, '0');

 // Note that there's no return here. Because our for statement is missing it's
 // conditional check to exit, the compiler's intelligent enough to know that it's
 // never going to get this far. As I *know* that I'm going to get an early hit, I can
 // get away with an infinite loop for code golfing purposes, but I'd never advise using
 // one in the real world, other than for tight game loops, etc.

In total – 194 characters (Comments aren’t counted). Fairly decent, I thought.

The shortest entry, however, was 104 characters. Looking at their code (you’re allowed to, afterwards), it seems that there’s a repeating pattern of results – curiously not including  140. (I’m sure there’s a good Maths reason for that. Just not sure what it is).

Anyway – I finished 6th overall. Not bad, but not 1st, obviously. Still – for my first code golf outing – pretty pleased with that.

On “Said”

There’s currently a bit of a hoo-hah about the word “said” – the hoo-hah being that its made its way onto at least one teacher’s list of words that should not be used by school children.

Instead, they’re urged to use what are referred to in the trade as said-bookisms. Words such as barked, howled,  demanded, cackled. The reason being that they’re more emotive.

“This is terrible,” John barked.
“Why would you think that?” cried Mary.
“Because he does,” growled Peter.

Why is this a problem? Because by the time you’ve learned that John has barked those words, you’ve already parsed them in your head. You then have to go back and re-imagine them as being barked.

Most of the time, “said” will work perfectly fine. It holds no emotional surprises. For speech attribution, it’s virtually punctuation. If you want to evoke emotion, you should clue the reader in the character’s emotion prior to the words that are spoken. For example:

John swept the test papers off his desk. “This is terrible.”
As the papers fluttered to the ground, Mary felt her stomach flip. “Why would you think that?”
Peter put his hand on Mary’s shoulder and then glared at John. “Because he does.”

Doe John actually bark “This is terrible”? Depends if you, the reader, thinks he does. What you may lose in precision, you gain in congruence. The real key to immersive writing is choosing your words so that the reader only needs to parse them once, in a forward direction.

The side-project

September just vanished in a blur. So did October. The new job’s eaten a lot of my time.

The side-project I mentioned last time? That’s now in progress. I know it’s a tease, but I’m sworn to secrecy. Details to follow,  hopefully sometime in the first quarter of next year, as soon as it’s out of secret Beta.

I’m currently desperately trying to ignore that NaNoWriMo starts this Sunday. First time in four years I won’t be participating, due to said side-project and work eating every available minute.

In the meantime – Happy Halloween, everyone 🙂

A Long August

It’s been a bit of an eventful month for me.

My youngest son came over to visit from Sweden for the Summer. Managed to get to Universal Studios with him, last weekend. We had a lot of fun together. He’s even more of a computer addict than I am. A true Screenager.

He flew back, early Monday morning. I really miss him.

On top of that, I’m starting a new job shortly. I’ll be working for a company based in Malta, this time, coding online gambling software. Will be doing so alongside a couple of my old friends from previous jobs – Mike and Matt – who I’m really looking forward to working with again.

I’m sad to be leaving the current job – they’re a really great bunch of people – but five years is a really long time for any coder to work on just one software system.

I’m looking forward to the vertical learning curve and the new challenges ahead. Will be nice to get the Maths part of my brain whirring again. It’s been a while.

The part I’m really looking forward to, however, is that I had the new contract specially drafted to allow me to work on commercial side projects in my spare time. I already have one project lined up. Watch this space.

All in all – this is year four of living in California for me. Aside from the perma-sunshine and living ten minutes away from the ocean, my daily commute is basically me wandering downstairs to my PC in my dressing gown, every morning.

Living the dream.


So – I’ve just discovered/ rediscovered CodePen.

To celebrate – (and mostly to test out the CodePen WordPress plugin) – I threw this together:

See the Pen Matrix-style text rain by Steven Cowles (@tiggs) on CodePen.0

Because who doesn’t want some Matrix-style rain on a loading page somewhere, right?

The best thing about CodePen is that you can just jump in and start editing the code. You should totally go and make it green.

Flash Fiction – Lost Post

For Chuck Wendig’s 100 word Flash Fiction challenge, here:

Mary jumped through the mirror, just as the shadow hounds found her. She landed in an unfamiliar bedroom, with faded pink walls.

Twelve mirrors and still no sign of Silverwood. That was decidedly bad luck. She checked the markings etched into the bottom right of the mirror.

A West Country mirror leading to another West Country mirror. She must have found her way into some local family circuit.

The sinister growling from behind the bed moved her legs into action, and she dived through the nearby wardrobe’s mirror door with her precious cargo, the message to Ryley, still gripped tightly.

A computational hack for double factorials


In computing, multiplication is fairly expensive in terms of processing time.

This is a hack to reduce the amount of multiplication required to calculate a double factorial.

A double factorial is basically the product of a series of consecutive odd or even numbers. So 1 x 3 x 5 x 7 or 2 x 4 x 6 x 8 etc.

Pretty simple concept, strange name. Welcome to Math.

As you can see, for large series, there’s a lot of multiplication involved. Once for every term.

For multiplying any 4 numbers in this series, starting with n, you’d normally compute:

n * n+2 * n+4 * n+6

Which is three multiplications and three additions

To reduce that to two multiplications, two additions and one subtraction, use:

((n * n+6) + 4)2 – 16

Mathematical proof follows:

n * n+2 * n+4 * n+6
= (n2 + 2n) * (n2 + 10n + 24)
= n4 + 12n3 + 44n2 + 48n

((n * n+6) + 4)2
= (n2 + 6n + 4)2
= n4 + 12n3 + 44n2 + 48n + 16

Therefore, ((n * n+6) + 4)2 – 16 = n4 + 12n3 + 44n2 + 48n