Category: <span>Algorithms</span>

Inspired by an amazingly concise implementation of John Conway’s game of Life that I saw written in APL, I decided to see if I could write Life in a single Linq expression.

This (rather long and rambling) post documents my attempts, my eventual success and the result that it made me want to learn APL!

As a (somewhat lapsed but still interested) mathematician, I like to play around with interesting numbers. Well, I guess we all have our little foibles eh?

I decided to have a go at generating pairs of amicable numbers using Linq. This post explains what they are, and how I went about it.

A few weeks ago, I blogged about some code I was writing to simulate buses arriving at bus stops and picking up passengers.

I mentioned at the end that the code shown there had three major shortcomings. Having nothing better to do with an hour this afternoon (meaning: not being bothered to do what I was supposed to be doing and preferring to have a play instead), I decided to address those shortcomings.

This blog post explains the changes, and how they led to a very pretty, but probably wrong simulation!

The answer to the age-old question of why do buses come in threes is that they don’t. Well, not often.

I decided to write a simple simulation to see how buses might behave, and whether or not they really do arrive in threes.

I was browsing the latest C# questions on StackOverflow, and came across one that caught my eye. Sadly, it was quickly closed by people who, in my opinion, didn’t read it properly. The question was…

I am trying to write a program to find the factor of a number with minimum difference. For Ex: for 20 it should be 4×5 or vice versa. How can this be achieved for a really BIG number. lets say 989287498274928743928174192847219347123984723498. Please guide

Ignoring the usual SO rules about showing some effort or research, the question is not simply “How do I find the factors of n?”, which is what all the linked answers were about. This question was how to find the two closest factors. Sure you can do that by finding them all, then sorting them by their difference, but for a big number, that’s hugely inefficient. There are ways of solving this specific question much more efficiently, which is what I decided to do.

Debunking the Internet myth that this year December (or whatever month is chosen) will have 5 Saturdays, 5 Sundays and 5 Mondays, and how this only happens once every 823 years.

It’s junk, and I proved it using Linq. Afterwards, I realised that I could prove it without Linq, had I only thought about the question first. Still, it was an interesting exercise, both in Linq and in thinking.