A Conversation for The H2G2 Programmers' Corner

Myth 42 needs your help!

Post 41

26199

Got one for ya...

(2^0-3+9)*06=42

Found by my program again... it's doing quite well smiley - biggrin

(are we allowed to use zeros like that, though?)


Myth 42 needs your help!

Post 42

Captain_SpankMunki [Keeper & Former ACE] Thanking <Diety of choice> for the joy of Goo.

If you use 0 + 6 then yes.

Liam.


Myth 42 needs your help!

Post 43

26199

Ah, good point smiley - smiley

I'm a programmer, not a mathematician smiley - winkeye


Myth 42 needs your help!

Post 44

Captain_SpankMunki [Keeper & Former ACE] Thanking <Diety of choice> for the joy of Goo.

Aww come on 26199 it's all addition once you get down to processor level.

Liam.


Myth 42 needs your help!

Post 45

26199

Yes, but the point about programming is you don't have to think about all that stuff smiley - biggrin


Myth 42 needs your help!

Post 46

Pastey

Well, I'm not a mathmatition and haven't been able to get my U# down to 42. You're welcome to try.

smiley - rose


Myth 42 needs your help!

Post 47

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Pastey, (-(4-5+1)!+7)*7 smiley - ok


Myth 42 needs your help!

Post 48

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Actually, that could benefit from an extra pair of parenthesis for clarity...

(-((4-5+1)!)+7)*7 smiley - biggrin


Myth 42 needs your help!

Post 49

26199

Shiesh, leave some for my poor program to do smiley - winkeye

Although - if you have any suggestions for 26199... smiley - smiley... 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!

Post 50

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

2-6+ATN(1)+(9/9) smiley - tongueout


Myth 42 needs your help!

Post 51

26199

Unfortunately I've been brought up too well for that - I work in radians smiley - cool

Nice try though smiley - winkeye


Myth 42 needs your help!

Post 52

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Radians? How irrational... smiley - silly


Myth 42 needs your help!

Post 53

26199

smiley - biggrin

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!

Post 54

Potholer

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 smiley - smiley

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!

Post 55

Potholer

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!

Post 56

MaW

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!

Post 57

Potholer

Prolog? *coughs*

Still, I suppose it's a *little8 quicker now than it was when I was at Uni

no (more) answers smiley - smiley


Myth 42 needs your help!

Post 58

26199

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!

Post 59

Potholer

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.


Myth 42 needs your help!

Post 60

Potholer

PS
Found any answers for 26199 with your Java yet? smiley - winkeye


Key: Complain about this post

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."

Write an entry
Read more