Solving a puzzle using "Solver"? Can already do by Iteration & functions.

J

JohnI in Brisbane

Hi everyone,

I'm trying to understand how the add-in "Solver" works.

I have a puzzle which I found in NewScientist magazine (24 Jan 2004) page 45
as follows:

===================
That great artist Pussicato has painted a picture containing antelopes,
bears, cats and dogs.
For aesthetic reasons he kept to the following conditions:

Writing "a" for the number of antelopes in the picture, "b" for the number
of bears and so on:

a + 6d = 2b + c + 20 unless a + 6d = 2b + c + 17;

a + d = b + 2c + 2 unless a + d = b + 2c + 1;

3a + 5d = 3b + 5c + 11 unless 3a + 5d = 3b + 5c + 12;

3b + 5c = 2a + 2d + 1 unless 3b + 5c = 2a + 2d + 3;

the total number of animals is odd unless it is divisible by 5.


How many of each animal are there in the picture.
===================================

Okay, I realised that this is a set of simultaneous equations so I solved it
using the MMULT & MINVERSE functions on the 16 possible combinations.
I'd read about these functions some time ago on these newsgroups, & so
decided to try them for the first time on my own - and they worked great!
:)

Then I tried Solver and could not get it to work.

Looked at the solution again, and realised iteration was easily possible -
so did that. Initially I thought that there may be an alternative solution,
but think now that there is only ONE solution with 4 variables & 4
simultaneous equations. (My maths IS getting a bit rusty.)

Okay, back to Solver. I'm thinking now that this is not a good problem for
"Solver" as it doesn't slowly move towards an Optimal Solution.

Am I correct in this assumption or am I doing something wrong?

Love to hear any suggestions.

regards,

JohnI
====================================================

PS if you love Math problems, take a look at
http://www.mkaz.com/math/google/
where the Marcus Kazmierczak describes how he solved the following problem:

{ the first 10-digit prime in consecutive digits of e }.com
 
B

Bernard Liengme

Are we to read this as:
a + 6d = 2b + c + 20 unless a + 6d = 2b + c + 17
in which case a + d = b + 2c + 2 unless a + d = b + 2c + 1
in which case 3a + 5d = 3b + 5c + 11 unless 3a + 5d = 3b + 5c + 12
in which case 3b + 5c = 2a + 2d + 1 unless 3b + 5c = 2a + 2d +
3
but then what?
 
J

JohnI in Brisbane

Bernard,

I took the description to mean that either of the equations on a line is the
correct one to use, but not both.

So for line 1, if: a + 6d = 2b + c + 20
then: a + 6d <> (does not equal) 2b + c + 17
and vice versa

if you look at the two equations on each line, the only difference is the
constant at the end of each one.

example: 20 & 17 on first line.

So this is two linked problems, (1) finding which equation to use, and (2)
the values of a,b,c,d.

But of course, by solving one you have solved the other at the same time.

'Here is my solution by iteration.

Sub FindSolution()
Dim bFound As Boolean
Dim iMax As Integer

Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer

bFound = False
iMax = 5

For a = 1 To iMax
For b = 1 To iMax
For c = 1 To iMax
For d = 1 To iMax
If ((a + 6 * d = 2 * b + c + 20) _
Or (a + 6 * d = 2 * b + c + 17)) _
And ((a + d = b + 2 * c + 2) _
Or (a + d = b + 2 * c + 1)) _
And ((3 * a + 5 * d = 3 * b + 5 * c + 11) _
Or (3 * a + 5 * d = 3 * b + 5 * c + 12)) _
And ((3 * b + 5 * c = 2 * a + 2 * d + 1) _
Or (3 * b + 5 * c = 2 * a + 2 * d + 3)) _
And (((a + b + c + d) Mod 2 = 1) _
Or (a + b + c + d) Mod 5 = 0) Then
Range("B2:E2").Value = Array(a, b, c, d)
bFound = True
Exit For
End If
DoEvents
Next
If bFound = True Then Exit For
Next
If bFound = True Then Exit For
Next
If bFound = True Then Exit For
Next

End Sub


regards,

JohnI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top