You have thirteen characters: the numbers 1-9 and the operators for Plus, Minus, Divide and Multiply. Arrange them in a string so they have the highest possible value, or write a program to do this for you. If a string cannot execute as a mathematical function, it scores zero.
Full list [1,2,3,4,5,6,7,8,9,+,-,*,/]
There are 13! possibilities. How many score more than 0 (are mathematically viable)? How many steps did you program take / candidates did it evaluate. How did you know when to stop?
Curse you, lack of edit. This place is waaaaaaay worse than UD!
grouping rules?
can you expand on that a bit?
Solve carefully…
25 – 55 + (85 + 65)
Believe it or not, this expression equal 5!
Bidmas / Bodmas. No parentheses were given.
It does equal 5!
does 3*4-5 =(3*4)-5 or 3*(4-5)
programming languages have default ways of deciding which operations to do first. Where the implied parentheses go.
Or maybe I’m just confused. Wouldn’t be the first time.
Richardthughes:
Spoiler.
Let’s go with this?
https://www.mathsisfun.com/operation-order-bodmas.html
3*4-5 = 7, not -3. I think.
Note to self – think you can also get negative values….?
Can we use regular expressions? I guess that would defeat the purpose of measuring the steps of a program
At like at 13! (6 billion ish) possibilities you could brute force it quite quickly using nested loops. I’d like to explore method evaluation as part of this, I think.
For once we agree on something. We used to be able to edit our OP’s until petrushka went and did the naughty and everyone else got punished for it. Talk about admins over-reacting. That would never happen at UD.
Mung,
Comments Closed.
Should we allow + and – to denote positive and negative? Should +9876*54/-321 be allowed? I’m thinking… not.
Using magic presuppositionalism I’d guess something like
975*864+3/1-2
I’m somewhat flummoxed as to how to solve it or how to write a GA to solve it.
petrushka,
Beaten by presuppositionalist =965*874+3/1-2 (I swapped 2 digits) 😉
MY GOD IS GREATER!!!!1111
Man, I had to read that OP a few times to make sense of it. I’m invoking the Harshman rule.
So we have to use all the digits and all the operators and we can only use each particular digit and each particular operator once, is that correct? Couldn’t you toss in a zero just to make it interesting?
So for my divide I’m going to want to divide by 1. And for my subtract I think I am going to want to subtract 2. Just thinking intuitively. And I am going to want to multiply the two highest numbers.
My question is, how do we know the correct answer?
Also, if there’s only one answer then you can’t use a GA to solve it.
Correct. I removed 0 to exclude infinity and Joe Gallien’s incorrect slobberings that would accompany it.
That’s some good thinking (I think).
We could run through all 6ish Billion. Not really that hard for a modern PC
What makes you say that?
Thanks for demonstrating that the fitness function has to be intelligently designed.
Stupid comments by ignorant people over in the turbines thread. Do you just have them on ignore? You should. For example, the Dawkins weasel program isn’t a GA because it has a single target. That kind of nonsense.
It was sarcasm.
Seriously, did you just miss all my posts in that thread asking just how many targets were needed before something could be a GA?
LOL. Go on then, We’ll see how you do.
I award that reply 3 Galliens.
Mung,
I think there’s some confused over how explicit a target should be and if local or global maximas are required. If evolution is a search, has it found it’s target?
Neat thing about the Ruby language is that you can evaluate strings as if they were code.
D:\projects>ruby -e ‘puts eval(“2+2”)’
4
But “7*/1” could be a problem.
Actually as AxB = BxA, I’m thinking there’s more than one answer.
I think we should all agree that this problem is beyond the capabilities of genetic algorithms. We should all presuppose that only an intelligent designer can intuitively see the quickest path to solution.
Evolution is dead.
catch that as an error and give it a zero. Good for you for coding!
petrushka,
Evolution by design is still evolution. Enough with the equivocation.
I can’t wait for Frankie’s version.
=NOT BLIND WATCHMAKER EVOLUTIONISMSM.
So in a program we’d want to create all possible combinations, I swear I wrote an algorithm just the other day to do that. =p
We’d want to do that so we could be certain we had the highest possible value.
Discard any string with a lower value than the current highest value. Store any strings with equal value so we could see if there is more than one solution.
A GA could not tell us that, though, not in a way that wee could be sure of. Do you agree?
Yes. It will raise an exception and on any exception we can just return a value of zero.
But the number of steps in the program is going to always be the same, wouldn’t you agree?
There’s no guarantee that a GA finds a global maxima. It becomes more likely with more time, but I believe you are correct (how many rolls to guarantee a 6) etc. That being said, we could test its efficacy over N trials vs. exhaustive enumeration, which guarantees us a maximum as it tests all possibilities,
Here’s what I came up with for the size of the sequence space:
302,875,106,592,253
Do you concur?
I absolutely agree with you about that. The order doesn’t matter there.
I think it’s 13! = 6,227,020,800. Are we collaborating, Mung? 😀
You are totally sciencing, Mung! Where’s KeithS? KeithS! Get in here!
I think I know where you’re coming from now Rich. This is utter brilliance. A GA should be the fastest way to get to the solution, but it would be impossible to know what that solution is until the entire search space is explored.
Or maybe I need to think about this a bit more…
dazz,
Thanks! 😉
This was also a good one: http://theskepticalzone.com/wp/creating-csi-with-ns/comment-page-10/
God Forbid! LoL.
Well, I was using (length of sequence) ^ (number of characters). In this case they are both equal. I admit this is a carry-over of a discussion of amino acid sequence space and I was using a program developed for that so it may not apply here. It might be interesting to explore the differences.
Real code:
ALPHABET = %w[1 2 3 4 5 6 7 8 9 * / + -]
NUMBER_OF_SYMBOLS = ALPHABET.length
LENGTH_OF_SEQUENCE = 13
SEQUENCE_SPACE = NUMBER_OF_SYMBOLS ** LENGTH_OF_SEQUENCE
Gawd. Did I just pull a Matzke?
Hmm. https://en.wikipedia.org/wiki/Permutation
Each character once and once only, remember.
And ALPHABET.length = LENGTH_OF_SEQUENCE = 13
sort of redundant stuff
http://stackoverflow.com/questions/19371442/how-to-create-a-nested-loop-with-ruby-the-right-way
No. You pulled a Mung.
keiths,
BE SUPPORTIVE KEITHS. Your dinner’s in the dog.
ALPHABET.each do |symbol|
beta = ALPHABET – [symbol]
# create all possible configurations of beta
# perhaps through a sequence of swaps/shifts
end
So now I have an array that contains all the other “letters” contained in the “alphabet” and I need to iterate over all possible unique arrangements of those remaining “letters.” Suggestions for an algorithm?
OOP would be to create a new type of object/class that accepts an array and which implements an each method which iterates over all possible configurations. Wonder if there’s something like that in the available libraries.
Mung,
Drop the OOP and try recursion.
Here’s how to go about calculating the number of “legal” sequences.
Assuming the operators are all binary, every legal sequence must look like this:
num0 op0 num1 op1 num2 op2 num3 op3 num4
Decompose that into two problems:
1. How many ways can the digits 1-9 be arranged into 5 distinct numbers?
2. How many distinct sequences can be formed from the operators +,-,x,/ ? (where a sequence is op0 op1 op2 op3)
Multiply the two answers and you’ll have the number of legal sequences.
dazz, the number of symbols is not typically the same as the length of the sequence. Imagine a world where all protein sequences are restricted to chains of 20 or fewer amino acids.