You are not logged in.
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
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
Offline
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
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
Offline
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
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
Offline
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
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
Offline
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
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
Offline
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
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
Offline
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
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
Offline
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
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
Offline
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
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
Offline
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
Offline
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
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
Offline
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
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
Offline
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
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! 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
Offline