Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#26 2014-12-10 03:56:09

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

It has to be that you are only using 6 for your permutation.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#27 2014-12-10 04:05:41

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

I think I did it that way because I couldn't code it in M in one go initially and just did one part like I usually do with alphametics, and then handed the other part that I couldn't do over to Excel.

If I'd done it all in M from scratch my code might have been quite different, and maybe slower.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#28 2014-12-10 04:07:51

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

Mine uses the permutations of 1 to 9 in groups of 9. That means 360 000 of them are generated. Yours uses about 60000.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#29 2014-12-10 04:11:14

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Yes, I see. But maybe your code is better in other ways (easier to understand?), even though it's slower.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#30 2014-12-10 04:15:22

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

The basic engine uses a Select just like yours does.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#31 2014-12-10 04:15:30

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Would you like to give me a look at your code?


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#32 2014-12-10 04:17:12

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

Hold please:


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#33 2014-12-10 04:17:44

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

I reckon you put me onto Select waaaay back.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#34 2014-12-10 04:20:20

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

s1 = Permutations[Range[9], {9}];

s2=Select[s1,(100#[[1]]+10#[[2]]+ #[[3]]+100#[[4]]+10#[[5]]+#[[6]]==100#[[7]]+10#[[8]]+ #[[9]])&& (100#[[4]]+10#[[2]]+#[[1]]+100#[[7]]+10#[[8]]+#[[9]]==100#[[3]]+10#[[6]]+#[[5]])&]

{{4, 3, 8, 2, 1, 9, 6, 5, 7}}

make[l_,t_]:=Module[{},Thread[l[[t]]]]
ans=make[#,{1,2,3,4,5,6,7,8,9}]&/@s2

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#35 2014-12-10 04:27:06

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

That took AbsoluteTiming 2.622522 seconds.

I haven't looked at it yet to see what it does. I remember, though, that Thread was one option I looked at early on, but I let it go for some reason.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#36 2014-12-10 04:30:23

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

It has the convenience that it spits out the answer, you do not have to convert the numbers.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#37 2014-12-10 04:36:27

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

True.

Why have you got {{4, 3, 8, 2, 1, 9, 6, 5, 7}} and the stuff below it in the code? It runs from just the first couple of lines of code.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#38 2014-12-10 04:41:25

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

That is the convenience, it is the actual answer.


438 + 219 = 657


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#39 2014-12-10 04:47:42

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Oh.

I prefer your code, cos it's much simpler than mine and follows exactly the way we do alphametics.

I just hadn't seen that I could use the && and then got bogged down in trying that alternative method. However, the speed boost was nice and of interest, although it was purely a fluke.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#40 2014-12-10 04:49:54

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

Well not exactly the answer here because it is for a single equation.

Have you seen rasher's code?


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#41 2014-12-10 04:55:18

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

No, I haven't. What is it, and what's it for?

I'll have to look at that later, though, because I must go to bed. This puzzle was interesting, and thanks for your input.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#42 2014-12-10 04:56:27

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

Okay, see you later. We can continue with his code which solves lots of them when you are in here next.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#43 2014-12-10 12:24:33

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Hi Bobby,

I had a look at some of rasher's posts to see if one fitted this puzzle, but nothing leapt out at me (not that I knew what to look for).

Is it something to do with this, or maybe Cases[string,{_,_,x_/;x>100}]? Both from rasher.

I tried to replace Select with them but couldn't do it...wrong choices, I suppose.

Last edited by phrontister (2014-12-12 21:23:43)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#44 2014-12-12 22:53:35

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Hi Bobby,

I'm struggling to put the two equations into rasher's code, which only has the one equation. I've tried a few things, but no success...


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#45 2014-12-12 22:55:51

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

I do not think that his code can be applied to this particular problem. I only mentioned it because it is useful for the other type problems.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#46 2014-12-12 23:04:55

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Oh, I see. I may as well stop trying to adapt it as I'm only getting masses of error notifications anyway, which hasn't been terribly encouraging.

I'll stick with your code for this one and try rasher's on single equations.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#47 2014-12-12 23:08:52

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

Use your code, it worked fine.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#48 2014-12-12 23:26:38

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

I'll try it on the next multiple-equation problem.

I haven't tried it on problems that have more than 2 equations (in fact, the one on this thread is the first I've seen), but maybe I can adapt it to work.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

#49 2014-12-12 23:29:02

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: help me please and fast

I have done a lot of these alphametics and it is the first that has asked for a simultaneous equation to be solved.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#50 2014-12-13 14:21:29

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: help me please and fast

Hi Bobby,

I have two lists of lists, with each sublist comprising 9 distinct elements, each sublist being distinct from others within the same main list, and the number of sublists in list1 and list2 not necessarily equal. eg,

list1={{a,b,c,d,e,f,g,h,i},{b,a,c,e,d,f,g,h,i},{a,b,c,d,e,f,g,h,i},{c,a,d,b,e,f,g,h,i}}
list2={{d,a,c,d,e,f,g,h,i},{c,a,d,b,e,f,g,h,i},{b,c,a,d,e,f,g,h,i}}

Would you be able to show me how I can compare list1 and list2 and print out any sublists that appear in both those lists?

In this case, I'm looking for answer {c,a,d,b,e,f,g,h,i}, which is the only matching sublist.

I'd thought it would be easy to do! sad And it probably is...

Last edited by phrontister (2014-12-13 14:35:38)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Online

Board footer

Powered by FluxBB