Curse of the Azure Bonds – build 1.0.12

Installer 1.0.12 is now available.

Issues fixed in this build:

  • Fixed the Fear spell, so it is removed when combat is ended
  • The icon designer now reverts to your original colours when you ‘Exit’ a sub-menu instead of keeping the changes
  • Fixed the price text when buying healing from a Temple
  • Fixed crash when removing cursed items

Enjoy.

Cedric’s Coding challenge – An Erlang solution

So after the verbosity of my C# Solution I was wanting a neat solution, and was hoping that Erlang would deliver:

-module(challenge).
-export([main/0]).

main() ->
    [worker(X, 0, [], [1,2,3,4,5,6,7,8,9]) || X <- [1,10,100,1000,10000,100000,1000000,10000000,100000000]],
    true.

worker(Mod, Number, Used, ToUse) ->
    if
        Mod == 1 ->
            [Number+X || X <- ToUse];
        true ->
            [worker(Mod div 10, Number+(X*Mod), [X]++Used, ([0,1,2,3,4,5,6,7,8,9]--Used)--[X]) || X <- ToUse]
    end.

I feel this is pretty good. To get the results just remove the “true.” statement from main().

Unfortunately it is not as fast as I would like, taking 5 seconds to run, but I’m not sure I’m using lists in the smartest way..

Nothing left to read

This is a first, I have nothing to read in FeedDemon:

Nothing to read

I prefer to think that the Internet is broken, and that’s why I have nothing to read, or the authors of most of the blog’s I read are sick.

But what I do know, is that it has nothing to-do with how mind numbing my current work is….. honest.

Actually it’s more likely because I have not gone swimming for the last three weeks and have been at my desk most lunchtimes and therefore keeping up with my feeds.

Cedric’s Coding challenge

I noticed Cedric’s Coding challenge while reading Robert Fisher’s blog.

Here is an interesting coding challenge: write a counter function that counts from 1 to max but only returns numbers whose digits don’t repeat.

For example, part of the output would be:

  • 8, 9, 10, 12 (11 is not valid)
  • 98, 102, 103 (99, 100 and 101 are not valid)
  • 5432, 5436, 5437 (5433, 5434 and 5435 are not valid)

Also:

  • Display the biggest jump (in the sequences above, it’s 4: 98 -> 102)
  • Display the total count of numbers
  • Give these two values for max=10000

Because I love coding problems, I whipped up a C# 2.0 solution which is not as succinct as some of the functional solutions, but it works on a ‘fast enough for me’ time scale.

using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ConsoleApplication1
{
    class Program
    {
        static bool[] used = new bool[10];
        static int value = 0;

        static void Main(string[] args)
        {
            int gap = 0;
            int last = 0;
            int count = 0;
            Stopwatch timer = new Stopwatch();

            timer.Start();
            int mag = 1;
            for (int i = 1; i < 10; i++)
            {
                foreach (int x in Step(1, mag))
                {
                    gap = Math.Max(gap, x - last);
                    last = x;
                    count++;
                }

                mag *= 10;
            }
            timer.Stop();
            Console.WriteLine("Count: {0}", count);
            Console.WriteLine("Gap: {0}", gap);
            Console.WriteLine("Time: {0}", timer.Elapsed);
            Console.ReadKey();
        }

        static IEnumerable<int> Step(int start, int mag)
        {
            for (int i = start; i < 10; i++)
            {
                if (used[i] == false)
                {
                    if (mag == 1)
                    {
                        yield return value + i;
                    }
                    else
                    {
                       used[i] = true;
                       value += mag * i;

                       foreach (int x in Step(0, mag / 10))
                       {
                           yield return x;
                       }

                       used[i] = false;
                       value -= mag * i;
                   }
               }
           }
       }
    }
}

Giving the following output (for 1 – MaxIn, as compared to 1-10,000 in the original challenge)

Count: 5611770
Gap: 10469135
Time: 00:00:02.8350765