A Conversation for The H2G2 Programmers' Corner
Myth 42 needs your help!
26199 Posted Oct 17, 2002
Got one for ya...
(2^0-3+9)*06=42
Found by my program again... it's doing quite well
(are we allowed to use zeros like that, though?)
Myth 42 needs your help!
Captain_SpankMunki [Keeper & Former ACE] Thanking <Diety of choice> for the joy of Goo. Posted Oct 17, 2002
If you use 0 + 6 then yes.
Liam.
Myth 42 needs your help!
Captain_SpankMunki [Keeper & Former ACE] Thanking <Diety of choice> for the joy of Goo. Posted Oct 17, 2002
Aww come on 26199 it's all addition once you get down to processor level.
Liam.
Myth 42 needs your help!
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Oct 17, 2002
Myth 42 needs your help!
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Oct 17, 2002
Myth 42 needs your help!
26199 Posted Oct 17, 2002
Shiesh, leave some for my poor program to do
Although - if you have any suggestions for 26199... ... I haven't tried myself, but my poor program's been at it for ages and hasn't found anything...
Myth 42 needs your help!
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Oct 17, 2002
Myth 42 needs your help!
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Oct 17, 2002
Myth 42 needs your help!
26199 Posted Oct 17, 2002
Adding to the list of ones my program's come up with:
(((4-(5/1))+7)*7)=42
I suppose I should add all those other random unary functions...
Myth 42 needs your help!
Potholer Posted Oct 21, 2002
I just finished version 0.1 of my attempt
It's possible to select which operators to try, so you can start off trying to get a 'clean' formula, then add in other operators if you have no luck (it's also possible to set limits on the *number* of unary operators like -,!,sqrt)
Currently there are a few bodges to try and keep the maths vaguely integer-ish, and in a reasonable range, but most of my time so far was taken trying to make the program terminate.
It seems to be quite fast - on my 1.3GHz Duron, when it wasn't terminating it seemed to be running about the 100,000/million formulas per second kind of range, and it took a blink to try out 10171 formulas and find (for 26199)
'Results for 26199 ->
2 6 bang 1 9 mul 9 add divide add
2 6 bang 1 mul 9 9 add divide add
2 6 bang 1 divide 9 9 add divide add
2 6 bang 1 power 9 9 add divide add'
ie. 2+(6!/((1*9)+9) -> 2 + (720/18) -> 42
With the essentially similar
2 + ((6!*1)/(9+9))
2 + ((6!^1)/(9+9))
2 + ((6!/1)/(9+9))
A nice use of a large factorial, if I do say so myself
For my number, it found 46 formulae just using +-*/!^ , and unary minus
I rather liked
9 2 sub bang 5 8 0 mul bang power bang divide
((9-2)!)/((5^(8*0)!)!) -> (7!)/((5^(0!)!) -> (7!)/(5!) -> 42
Are there any awkward numbers to try (excluding the really small <3 digit ones)
Myth 42 needs your help!
Potholer Posted Oct 21, 2002
Actually, that should have said >=5 digit numbers - I have already found quite a few 3 and 4 digit ones that I can't solve at present - I'll have to try and get some trig functions into my code.
It'd be really nice to help real researchers (5+6 digit) find their own formulae.
Myth 42 needs your help!
MaW Posted Oct 21, 2002
This looks like something that's easiest solved using Prolog or Haskell... I'll have to have a think about it.
Myth 42 needs your help!
Potholer Posted Oct 21, 2002
Prolog? *coughs*
Still, I suppose it's a *little8 quicker now than it was when I was at Uni
no (more) answers
Myth 42 needs your help!
26199 Posted Oct 21, 2002
My rather hastily hacked together Java works pretty well (I'm afraid it's stripped the indenting, as per usual):
A855029
Any real optimisations would have to involve intelligent searching... I'd be interested in playing with that, but I don't have the time.
Myth 42 needs your help!
Potholer Posted Oct 21, 2002
It is difficult to read without the indenting (and I don't know Java anyway, tho' I suppose my C/C++ would be near enough if the code was formatted).
I saw a random seed in there - just what is it you're doing randomly - making up formulas from a list of operators, or something else?
Eventually, I settled on trying an exhaustive search of all possible formulas based on a given number, with code to kill illegal operations (division by zero), useless ones (like factorial 1 or 2), and dodgy ones (largish powers of largish numbers. My code's a little dirty at present, but I'll try and clean it up and post it somewhere (plus offsite in a more formatted state)
What I'd really like are some real 5 or 6 digit numbers that have so far failed solution - looking through the 'Myth of 42' conversation backlog, I haven't seen any so far.
Key: Complain about this post
Myth 42 needs your help!
- 41: 26199 (Oct 17, 2002)
- 42: Captain_SpankMunki [Keeper & Former ACE] Thanking <Diety of choice> for the joy of Goo. (Oct 17, 2002)
- 43: 26199 (Oct 17, 2002)
- 44: Captain_SpankMunki [Keeper & Former ACE] Thanking <Diety of choice> for the joy of Goo. (Oct 17, 2002)
- 45: 26199 (Oct 17, 2002)
- 46: Pastey (Oct 17, 2002)
- 47: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Oct 17, 2002)
- 48: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Oct 17, 2002)
- 49: 26199 (Oct 17, 2002)
- 50: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Oct 17, 2002)
- 51: 26199 (Oct 17, 2002)
- 52: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Oct 17, 2002)
- 53: 26199 (Oct 17, 2002)
- 54: Potholer (Oct 21, 2002)
- 55: Potholer (Oct 21, 2002)
- 56: MaW (Oct 21, 2002)
- 57: Potholer (Oct 21, 2002)
- 58: 26199 (Oct 21, 2002)
- 59: Potholer (Oct 21, 2002)
- 60: Potholer (Oct 21, 2002)
More Conversations for The H2G2 Programmers' Corner
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."