Post Reply 
Vietnamese snake puzzle - Closed
05-20-2015, 09:37 AM (This post was last modified: 05-20-2015 12:58 PM by Gerald H.)
Post: #1
Vietnamese snake puzzle - Closed
Order of operations argument or find a solution?

http://www.theguardian.com/science/alexs...d-teachers
Find all posts by this user
Quote this message in a reply
05-20-2015, 11:27 AM
Post: #2
RE: Vietnamese snake puzzle
(05-20-2015 09:37 AM)Gerald H Wrote:  Order of operations argument or find a solution?

http://www.theguardian.com/science/alexs...d-teachers


Quote:multiply first, then division

Let's go with argument first, that's more important than solutions.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-20-2015, 11:33 AM (This post was last modified: 05-20-2015 11:34 AM by Gerald H.)
Post: #3
RE: Vietnamese snake puzzle
Pedantic - me?

Order of operations sort of defined in Guardian text.

Two types of action - quibble or solve.
Find all posts by this user
Quote this message in a reply
05-20-2015, 12:58 PM
Post: #4
RE: Vietnamese snake puzzle
Solvers win - answer found. Quibblers remain confounded.
Find all posts by this user
Quote this message in a reply
05-20-2015, 01:24 PM
Post: #5
RE: Vietnamese snake puzzle - Closed
Let's assume the 10 variables are named A through I, and that we're doing the standard order of operations here (multiplication and division together from left to right, then addition and subtraction together from left to right).

If we assume that non-integer intermediate results are allowable (e.g. G * H / I can be 1 * 4 / 8), then there are 120 valid solutions (verified via brute force with Heap's algorithm in C# - no, I'm not going to generate 362,880 permutations with a 9-level recursive algorithm on my 48*).

If we stipulate that 13 * B / C and G * H / I must have integer results, then there are 20 valid solutions.


*Although, there is a 3-day weekend coming up...
Visit this user's website Find all posts by this user
Quote this message in a reply
05-20-2015, 01:30 PM
Post: #6
RE: Vietnamese snake puzzle - Closed
Pedantic - me?

A to I traditionally 9 letters & same number of variables.
Find all posts by this user
Quote this message in a reply
05-20-2015, 01:35 PM
Post: #7
RE: Vietnamese snake puzzle - Closed
(05-20-2015 01:30 PM)Gerald H Wrote:  Pedantic - me?

A to I traditionally 9 letters & same number of variables.

Er, yeah, 9 variables, not 10. Us CS guys and our off-by-one errors...
Visit this user's website Find all posts by this user
Quote this message in a reply
05-20-2015, 09:01 PM (This post was last modified: 05-20-2015 09:08 PM by Gilles.)
Post: #8
RE: Vietnamese snake puzzle - Closed
I wrote a UserRPL program (HP50G) for this.
With the emulator the first solution is found in few minutes. Non-integer intermediate results are allowed.

Program still running. 22 solutions found for now.
Find all posts by this user
Quote this message in a reply
05-21-2015, 04:04 AM
Post: #9
RE: Vietnamese snake puzzle - Closed
I've found one solution using paper and pencil only, but I'm not pleased with my work. I assumed all intermediate results are integer. This implies c = 1, because 13 is prime. I didn't figure out any other way than atributing values to three variables (i, b and e) and changing them sequentially as they proved to be impossible. It took no more than an hour and a sheet of paper to find the solution, but that would be too much during an examination though.

No spoiler:

a.b.d.e = 120
f.g.h.i = 3024
Find all posts by this user
Quote this message in a reply
05-21-2015, 05:30 AM
Post: #10
RE: Vietnamese snake puzzle - Closed
(05-21-2015 04:04 AM)Gerson W. Barbosa Wrote:  I've found one solution using paper and pencil only, but I'm not pleased with my work. I assumed all intermediate results are integer. This implies c = 1, because 13 is prime. I didn't figure out any other way than atributing values to three variables (i, b and e) and changing them sequentially as they proved to be impossible. It took no more than an hour and a sheet of paper to find the solution, but that would be too much during an examination though.

No spoiler:

a.b.d.e = 120
f.g.h.i = 3024

Factors check out as a possibly good solution.
Find all posts by this user
Quote this message in a reply
05-21-2015, 08:12 AM (This post was last modified: 05-21-2015 08:13 AM by Tugdual.)
Post: #11
RE: Vietnamese snake puzzle - Closed
Since I'm in Haskell at the moment, I gave it a go, it is quite a simple exercise.
For what it matters, I found 128 solutions instantly... wow.
Haskell code
Code:
import Data.List
[x | x <- permutations [1..9], (x!!0+13*x!!1/x!!2+x!!3+12*x!!4-x!!5-11+x!!6*x!!7/x!!8-10)==66]

Solutions
Code:

126478539
426178539
126478359
426178359
296351478
396251478
132956478
932156478
714965328
914765328
734165928
734165298
134765928
134765298
314279568
214379568
796152438
196752438
912567438
512967438
714965238
914765238
236179458
136279458
314279658
214379658
296351748
236179548
136279548
396251748
132956748
932156748
796152348
196752348
912567348
512967348
948567132
948567312
548967132
548967312
496158732
196458732
764859132
764859312
864759132
864759312
364958172
364958712
964358172
964358712
196458372
496158372
286941753
986241753
286941573
986241573
139478256
139478526
324851976
324851796
132458976
132458796
248179356
148279356
439178256
439178526
824351976
824351796
432158976
432158796
248179536
148279536
941527836
941527386
321547986
321547896
352148976
352148796
152348976
152348796
521347986
521347896
153942876
953142876
153942786
953142786
752849136
752849316
852749136
852749316
852147936
852147396
152847936
152847396
541927836
541927386
328651974
328651794
931625874
931625784
628351974
628351794
631925874
631925784
693521874
693521784
928765134
928765314
728965134
728965314
732859164
732859614
731526984
731526894
832759164
832759614
892315764
392815764
892315674
392815674
872539164
872539614
572839164
572839614
531726984
531726894
593621874
593621784
Find all posts by this user
Quote this message in a reply
05-21-2015, 08:41 AM
Post: #12
RE: Vietnamese snake puzzle - Closed
Do you, Tugdual, claim your list of solutions is exhaustive?
Find all posts by this user
Quote this message in a reply
05-21-2015, 10:51 AM
Post: #13
RE: Vietnamese snake puzzle - Closed
(05-21-2015 08:41 AM)Gerald H Wrote:  Do you, Tugdual, claim your list of solutions is exhaustive?
Yes I would think so unless my Haskell code is wrong but I checked a few combinations and they look good.
Find all posts by this user
Quote this message in a reply
05-21-2015, 11:21 AM
Post: #14
RE: Vietnamese snake puzzle - Closed
(05-21-2015 10:51 AM)Tugdual Wrote:  
(05-21-2015 08:41 AM)Gerald H Wrote:  Do you, Tugdual, claim your list of solutions is exhaustive?
Yes I would think so unless my Haskell code is wrong but I checked a few combinations and they look good.

I only see 127 solutions?
Find all posts by this user
Quote this message in a reply
05-21-2015, 11:53 AM
Post: #15
RE: Vietnamese snake puzzle - Closed
(05-21-2015 11:21 AM)Gerald H Wrote:  
(05-21-2015 10:51 AM)Tugdual Wrote:  Yes I would think so unless my Haskell code is wrong but I checked a few combinations and they look good.

I only see 127 solutions?
I think there are 128 in my list and this is what Haskell returned.
Do you expect more?
Find all posts by this user
Quote this message in a reply
05-21-2015, 12:02 PM
Post: #16
RE: Vietnamese snake puzzle - Closed
I beg your pardon, Tugdual, I miscounted.

I only expected one solution & was happy when I found one.

Bravo on your quick research.
Find all posts by this user
Quote this message in a reply
05-21-2015, 12:19 PM
Post: #17
RE: Vietnamese snake puzzle - Closed
(05-21-2015 05:30 AM)Gerald H Wrote:  
(05-21-2015 04:04 AM)Gerson W. Barbosa Wrote:  a.b.d.e = 120
f.g.h.i = 3024

Factors check out as a possibly good solution.

321547986 and all valid commutations thereof.
Find all posts by this user
Quote this message in a reply
05-21-2015, 12:29 PM
Post: #18
RE: Vietnamese snake puzzle - Closed
(05-21-2015 12:02 PM)Gerald H Wrote:  I beg your pardon, Tugdual, I miscounted.

I only expected one solution & was happy when I found one.

Bravo on your quick research.
Thanks but no glory, Haskell is quite amazing for that sort of brute force...
Now I guess the real fun to stick on the forum topic would be to find a clever solution to do that with a simple calculator.
Find all posts by this user
Quote this message in a reply
05-21-2015, 01:14 PM
Post: #19
RE: Vietnamese snake puzzle - Closed
(05-21-2015 12:29 PM)Tugdual Wrote:  Thanks but no glory, Haskell is quite amazing for that sort of brute force...
Now I guess the real fun to stick on the forum topic would be to find a clever solution to do that with a simple calculator.

Or maybe somebody brings Haskell to the HP 50g?

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
05-21-2015, 01:18 PM (This post was last modified: 05-21-2015 01:23 PM by fhub.)
Post: #20
RE: Vietnamese snake puzzle - Closed
(05-21-2015 11:53 AM)Tugdual Wrote:  I think there are 128 in my list and this is what Haskell returned.
Do you expect more?
Yes, I do expect more. Wink

Your list is missing 8 additional solutions (due to rounding errors), there are 136 solutions in total - here the missing 8:
183745269
183745629
269851473
269851743
783145269
783145629
869251473
869251743

If you rewrite your equation (avoiding the 2 divisions by multiplying with the 2 denominators), then your program will give you all 136 solutions.
Edit: Or change the test to something like abs(expr-66)<1e-3 ...

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)