"One could not be a successful scientist without realizing that, in contrast to the popular conception supported by newspapers and mothers of scientists, a goodly number of scientists are not only narrow-minded and dull, but also just stupid." -- J. D. Watson
This is a project that stemmed from a favourite website of mine, h2g2 -- the Hitchhiker's Guide to the Galaxy.
Users of h2g2 have taken to finding ways that their user numbers can be manipulated to make 42 -- that being the answer to Life, the Universe and Everything.
Someone asked whether a program could be found to sort out the problem of making 42... and various people stepped forward to take up the challenge. Here are two of my attempts...
The first, GFortyTwo, is goal-based. This means it splits the digits into two halves recursively, and 'asks' for a useful number from each half. This approach is quite different from just enumerating all the possibilities; it also seems to be reasonably fast. You can try it online in applet form here.
An interesting case is that GFortyTwo operates increasingly quickly when you give it longer sequences of digits, whereas a brute-force approach would soon become too slow.
My second attempt, MFortyTwo, uses what is effectively a brute-force approach: it supports arithmetic operations on 'MultiNumber' objects, which can represent multiple possible numbers and how each could be obtained. This approach removes some of the repetition of the obvious brute-force method. However, it cannot currently concatenate digits...
Command Line Parameters: a sequence of digits separated by spaces