On Primality In Packsizes

Benny George, our precocious two-year-old, is quite the fan of Mister Maker, and enjoys spending time doing arty crafty stuff with his mum. Now, the great thing about the BBC is that they tend to suggest projects which can be created using bits and bobs that you’re likely to have around the home – old cereal boxes and the like. But occasionally some specialist resources have to be procured in the name of Ben’s art, and so it was that Joce today spent £1.99 on a pack of the “googly eyes” so beloved of Maker. ...

23 October 2009

Spot The Misleading Graph

Fifty-three years since Darrell Huff published the seminal How to Lie with Statistics, and still we have newspapers as august as The Times pulling the oldest trick in the book: At first glance it all looks very impressive, but closer inspection of the comparison with sales of the Torygraph reveal a mere 8.7% sales lead, not more than double as suggested by the graphic.Not fooled. Another favourite book of mine that covers the still-relevant topic of graphical integrity is Edward Tufte’s The Visual Display of Quantitative Information. It’s one of those timeless works that I look forward to sharing with the next generation. ...

19 February 2007

Big Integer

As I mentioned last summer, I do enjoy whiling away a few hours attempting to solve the maths / progamming challenges set on Project Euler. My language of choice for most puzzles is C#, but this hampered me on some of the questions as there is no in-built support for really big integers. However, a little bit of Googling and I came across this excellent BigInteger class on Code Project which does everything I need and more – and it seems bloody fast, too. Thanks to this class, I’ve been able to knock off several more problems this weekend, and now have a rating of “11% Genius” – still some way to go, then… ...

17 July 2006

Rounding Up The Result of Integer Division

Here’s a damn useful piece of information which should be in the armoury of every modern codemonkey: In Java, if it is required to round up the result of dividing m by n (where m and n are integers), one should compute (m+n-1)/n Source: Number Conversion, Roland Backhouse, 2001 I’ve used this deliciously elegant result in production J2EE code in the past, but it’s equally valid in C#, as long as you can make the additional assertion that m/n is positive. This is because whilst Java treats integer division by rounding to zero, C# merely truncates the result (in an unchecked context). In my experience, the most frequentuse for this result is the deft answering of questions such as “if I have x items in my dataset and I display y per page, how many pages do I have in total?”, where it is obviously safe to make the assertion of a positive result. ...

6 September 2005

Project Euler

If you like maths problems, and you like programming (and hey, who doesn’t?), then you’ll love Project Euler.

22 August 2005