Programming for fun
Dec 2, 04:36 PM by Eric Allen
I must admit I’m a bit of a Risk addict. When somebody had the idea of making it a Facebook app, I jumped on it. So, I’ve been playing a lot of Risk lately, but I’ve been plagued by a question: if you’ve two equally sized hordes against each other, is it better to attack or defend? The defender wins ties, but the attacker gets to roll more dice. I probably could have figured this out mathematically, but I’m a programmer. I chose Ruby because it’s fun and easy to use and whipped up a little program to calculate the odds by facing off two very large armies (100,000 in my version) and seeing who loses more. I was pleasantly surprised (yet again) at the clarity and simplicity of Ruby. I’ve made the source code available online. The project took me maybe half an hour, and it has answered the question conclusively: on average, the attacker will lose only 85 armies for every 100 the defender loses. Therefore it’s better to attack while you have the chance instead of waiting to be attacked if you ignore all other factors.