Search

Showing posts tagged Algorithms.

Finding amicable numbers with Linq

Finding amicable numbers with Linq

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.

My buses don't come in threes!

My buses don't come in threes!

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!

Finding the two closest factors of an integer

Finding the two closest factors of an integer

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 4x5 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.

Using Linq to debunk the Feng Shui about the number of days in December

Using Linq to debunk the Feng Shui about the number of days in December

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.