Monday, June 4, 2012

Another tech question

Given a set of weighted values what combination(s) equal 10?

I coded this latest challenge here. It's fairly concise and it implements the challenge fairly cleanly with a few loose ends. For example I do not like the use of a global counter '$i'. I'm also bugged by tokens with a value of 0 (zero). But it's a start.

[Update 2012-06-04] Just to be clear my concern with the code I presented was that the reduce() function had external side effects. And that's just yukky code.  I've updated the code with this and I like it because it eliminates the side effects entirely but it meant having to install List::MoreUtils.

[Update 2012-06-05] I forgot to mention that I had initially tried to code the sample in python, however, I was not able to get a BigInt-like class installed. I did not try very hard but hard enough. Perl's was there by default or simple install and while I did not implement the code in Ruby; it [Ruby] has a BigNum implementation so a direct translation should not be too difficult.

[Update 2012-06-05] This is the latest version. In this version I replaced the xdump() calls with Data::Dumper(). I've used this class before and I thought of using it... but as I moved farther away from the initial discussion some details mean less than they did initially. Data::Dumper() is a good tool and I should have used it from the beginning. I'm not sure what the performance benefit is but I changed sprint("%d", $n) to "$n".

No comments:

Post a Comment

static site generators

Static site generators are pretty cool. Granted they are an oversimplification of the java/json/xml/xslt site manifestation from the olden d...