Project Euler

Project Euler is a set of mathmatically-oriented open challenges for developers.  I started working my way through these the other day with a bent of using C# and LINQ as much as possible.
http://projecteuler.net

I’ve shared my source on my public GitHub
http://github.com/stephbu/projecteuler

For example: Problem #4 “Find the largest palindrome made from the product of two 3-digit numbers.”
http://projecteuler.net/index.php?section=problems&id=4

Use of LINQ to express the cartesian join between the sets of 3 digit numbers dramatically simplifies the amount of code written.  While the code is somewhat inefficient – I don’t dedupe reflexive pairs of numbers between sets – it is quite elegant.

https://github.com/stephbu/ProjectEuler/blob/0653d45c8e6a489057692410b3d409711b202f1c/ProjectEuler/Problem4.cs

Posted in Uncategorized | Leave a comment

ITunesSync

Finally got around to putting my ITunesSync command-line utility out on my GitHub.com repository.

It fixes ITunes bloody irritating inability to “watch a folder”, keeping a folder full of music in sync with ITunes – something that Media Player and other “watcher” based systems seem to manage so easily. Find out more here:

https://stephbu.wordpress.com/ITunesSync

Posted in Uncategorized | Leave a comment

Enumerables, Yield and Fibonacci

I’ve been reading Vazirani’s Algorithms last night – quite an entertaining book considering the dry subject and similar books on the topic.  Vazirani’s website has a draft of the book as PDF too.

While the book is very much language-agnostic, I thought I’d have a crack at some of the algorithms using much newer semantics of C# and the yield keyword.

The Fibonacci sequence is especially interesting because it can be a  O(N2) recursive, or a O(N) linear performer depending on implementation.

I took a stab at the linear implementation, the results are surprisingly clean and simple.  In the first cut, I did the traditional loop thing with a conditional guard for iteration 0 and 1.  Second cut is much more elegant, removing the conditional guards all together and replacing them with a sequence of yields :

        foreach(UInt64 fibNumber in FibonacciSequence())
        {
            Console.WriteLine(fibNumber);
        }

        public static IEnumerable<UInt64> FibonacciSequence() 
        {
            UInt64 nminus1 = 1;
            UInt64 nminus2 = 0;
            UInt64 current = 1;

            yield return 0;
            yield return 1;
            while(true)
            {
                yield return current;
                nminus2 = nminus1;
                nminus1 = current;
                current = nminus2 + nminus1;
            }     
        }
Posted in Development | Leave a comment

Goodies From The Company Store

Took a cruise to the Microsoft Company Store to get Win7 for a family member.  The place is full of tech-goodies – very hard to come out with only the items you intended. 

I originally went in to get Win7-Ultimate but Win7-Pro was cheaper by $10 – no significant feature differences.  It was quite a novel experience for this millenium at least – the last time I held a boxed OS product was Windows NT 4.0.

With an extra $10 burning a hole in my pocket I stopped at the mice rack.  We’ve lived with a Notebook Mouse on our desktop since the wireless mouse died.  I picked up a Microsoft Comfort Mouse 4500 for a little over that tenner – nice and comfortable to hold without being too flashy.  Tried it on Win7 and OS/X – worked right of the bat – no drivers etc needed.

On the way out I stopped to browse the the Xbox games stand and grabbed another copy of Halo Reach.  Lauren’s been talking smack for ages about how good she is at multiplayer, but she only played splitscreen.  We’ve got two Xboxes, and tonight I, as every parent should, mercilessly slaughtered her – headshots, beatdowns, and obligatory corpse desicration.

Posted in Uncategorized | Leave a comment

Win7 Installation – 2011 Welcomes Careful Drivers

Finally reinstalled my office desktop and upgraded it to Windows 7.  Unlike previous quantum leaps, I started from scratch – new 1 terabyte drive, new 23″ monitor to place the pre-millenial 17″ LCD, fresh OS install etc.

This is also the first time I’ve installed Windows from a USB key, to create your own:

Took around 20mins in total – pretty quick and smooth.  Plug-n-Play just did its thing, everything worked immediately display, printer, scanner, webcam, mouse, keyboard, even the UPnP gateway all discovered and controllable.

My original reluctancy to pave the machine stems from the level of investment in time spent with Windows application installations.  Over the last decade, I’ve been from Windows 2000, through beta versions of Windows XP all the way to Vista SP2 all with upgrade installs.  However of course this includes a lot of baggage.

This time around things are a little different, beyond being Print/ITunes/Backup/File Server and general office document workhorse, we’re spending more and more of our time in the browser –

  • I have far fewer applications installed, Visual Studio, and some games easily installed on demand from Steam. 
  • My wife only uses Office and some hokey-but-necessary Swim-team management software, otherwise preference is iPad or iPhone.
  • Kids don’t have any games installed anymore, preferring their web/flash and Apple iOS games, along with burning hours on Skype and Facebook chatting with their friends.

However all is not so rosey.  I can move documents and reinstall applications (200gb of Music and Video for example).  However I’m increasingly dependent on complicated applications like ITunes.  However it is far from a one-folder deployment, also the Apple documentation on moving that library is dire.

However the result is a machine that runs much faster in 64bit mode.  And has much less junk installed on it.


Posted in Uncategorized | Leave a comment

Book Price Gouging?

If electronic books are more resource efficient than paper, and confer less rights like resale and unlimited loaning, then why are Kindle editions of books *more* expensive than paperback equivalents?

Given that there are multiple e-readers on the market, all I see is price-fixing.

Posted in Digital Media | Leave a comment

Riak Core And Decentralized Node Management

Been reading a lot of code in the riak core framework.  Powerful stuff.

Fits lots of questions about managing big distributed systems in Erlang – answered a question up on StackOverflow about just such a scenario:

Posted in Erlang | Leave a comment

Great Erlang Secrets : Inheritance (1 of ?)

A little discussed capability of Erlang is module inheritance:

Example:

-module(basemod).
-export([foo/0]).
foo() -> ok.

The module can be subclassed by the using the attribute “-extends(atom())” as follows.

-module(submod,[]).
-extends(basemod).
-export([bar/0]).
foo() -> fail.
bar() -> BASE:foo().

As a result, submod exports foo/0 and bar/0.  Moreover submod overrides function foo, the compiler follows a predictable search path from child to parent etc when binding functions.   This strategy is made even more useful by declaring a parameterized module:

  1. to get access to ancestor declared functions, subclasses must be declared as parameterized modules – even if no parameters are bound.  e.g. -module(mymodule,[]).
  2. By parameterizing the module, two hidden parameters are bound to all subclass functions declared:
    1. BASE : a reference to the base module implementation.
    2. THIS : a reference to the current module’s implementation

Here’s a few links for further reading:

Posted in Erlang | Leave a comment

Erlang Activities

Tonight I’ve been thinking about a couple of different Erlang problems.

The first was injecting a supervisor to manage session processes.  Pretty straight-forward just needed a little more reading on my part.

Second was a broader, more tricky question – how do Erlang nodes find each other and discover what role they play?

There are a few different schools of thought on discovery:

  • Broadcast announcement – use a connectionless channel like UDP
  • Announcement via well-known node – requires configuration of a well-known name, and possible single point of failure.

And a couple of different ways of enlisting nodes in behaviours:

  • Physical map of node -> role assignment
  • Automatic enlistment of nodes into a homogenous system

Currently read riak_core written by Basho.  While reading the code I became interested in net_kernel:monitor_nodes This lead me to a really great presentation by Erlang Factory on real world experiences using Erlang in live operations

More Tomorrow…

Posted in Erlang | Leave a comment

Blog Migration and Service Sunset

The recent announcement of pending possible doom for Del.icio.us reminded me that I should move my somewhat dormant blog away from Spaces before it went boom too.

It seems so easy to assume that the digital landfill will exist for ever.  However, unless your bits are observed by Archive.org – like my first recorded missives for msn.co.uk – their lifetime may well be considerably less.

Posted in Uncategorized | 2 Comments