Andrew Aitken - Blog

Instant insanity solver

I was visiting my sister for Christmas and they had a puzzle for us to play with. It’s called the Instant Insanity puzzle, or at least it was a variation of it with old comic book covers instead of plain colours like the one on Wikipedia.

Pretty much everyone had a shot but nobody could quite get all 4 cubes to have different sides. Like a true geek I decided to write some code to solve it for me.

I put a little sticker with an arrow on each cube so I could identify them and what direction was “north”. This allowed me to map the cubes in code and also reverse the map when the code found a solution.

You can find the code here: GitHub

As it says in the Readme, it definitely needs refactored but it got the job done. It ran pretty much instantly and found 4 solutions (you can turn the stack 90 degrees and still have the same solution). It also finds 65,532 non solutions but I have to assume there are four of each one, making there 16,383 invalid solutions. A lot less than claimed on the box…

Read more →

Comma separated lists

While working on a site recently I had to output the name property from a list of objects that had been selected by the user.

I wrote a handy little method that let me pass in the objects and a Func to select the property to be used in the list.

private string ToCommaSeperatedString<T>(IEnumerable<T> items, Func<T, string> property)
{
    if (items != null && items.Count() > 0)
    {
        List<string> values = new List<string>();

        foreach (T item in items)
        {
            values.Add(property.Invoke(item));
        }

        if (values.Count > 0)
        {
            return String.Join(", ", values);
        }
    }

    return String.Empty;
}

Embedding code is still something of a work in progress. Just noticed it had deleted part of the method declaration.

Read more →

Another small update

I think I’ve been to BadgerBadgerBadger more times than I’ve written blog posts. I keep thinking something I’ve done would be interesting to blog about but when it comes down to it I can never think of what to write.

For now though, I’ve just converted my blog over to Umbraco, only took me a couple of evenings. I’m hoping the nicer backend than my custom site with it’s out the box asp.net styles will encourage me to write more.

I will have a few things to blog about in the near future too. I am currently building a remote control rover robot based on a QWERK control board. I’ve hit a bit of a snag trying to step down my 7.5v battery to 3v for the motors but hopefully I’ll get that sussed out soon then I can crack on and focus on the wireless part of the project.

Read more →