Math problem

Recommended Videos

Geoffrey42

New member
Aug 22, 2006
862
0
0
Wickedshot said:
Geoffrey42, are you saying 6!*217=6*5*4*3*2*217=720*217=5040+7200+144000=156,240?
156,240 is more than i guessed but is within the range of 2100 and 1 million, interesting.
That was actually my first inclination, but no. What I'm trying to point out is that if we were dealing with combinations of 6 integers >=1 but <=10 which add to 30, where each does not repeat, the number of combinations should be multipled by 6! to find the number of permutations. BUT, this is not the case. 5,5,5,5,5,5 does not have 6! permutations, it has 1. 10,8,6,3,2,1 has 6! combinations.

[a href=http://mdm4u1.wetpaint.com/page/4.3+Permutations+with+Some+Identical+Elements?t=anon]This is what I ended up using. (See example C)[/a] Based on the 217 combinations that I found, there are 50,877 permutations total. If someone could come up with a better programmatic/mathematical method for finding out what the possible combinations are, I now know how to get you the exact number of permutations. So, my 217 is still ~, but the step from ~217 to ~50,877 I'm absolutely sure of.

That number at least seems to line up both with sawyer776's and The_root_of_all_evil's.
 

Wickedshot

New member
Jul 11, 2006
45
0
0
51,740
59,049
50,877
Three estimates all in the same general range, and all within a 1% section of my original 2,100-1,000,000 range, that's a pretty good so far. I'm almost at the point where my laziness is being overcome by my need to know via a brute force programming solution, so if someone doesn't beat me to it we should have a set answer to help determine a formula.
 

Wickedshot

New member
Jul 11, 2006
45
0
0
Alright, I spliced some code into the python code for Civ4 to test it out, I used the following code and it yielded the following result:

iCount = 0
for iA in range(1, 10, 1):
for iB in range(1, 10, 1):
for iC in range(1, 10, 1):
for iD in range(1, 10, 1):
for iE in range(1, 10, 1):
for iF in range(1, 10, 1):
if ((iA + iB + iC + iD + iE + iF) == 30):
iCount = iCount + 1

CyInterface().addImmediateMessage("Total that add to 30: " + str(iCount),"")
Total that add to 30: 32661
So unless my code is faulty (which is conceivable, my python coding is far from perfect heh, but what I have looks correct to me), it would seem there are 32,661 possibilities that add to 30.
 

sawyer776

New member
Nov 2, 2008
4
0
0
The correct, exact answer is 50877. I won't go into the excruciating repetitive steps I took to find that, but I assure you it is correct.
 

sawyer776

New member
Nov 2, 2008
4
0
0
Wickedshot: does python do for loops inclusive or exclusive? If it is exclusive, that might explain your low result.
 

Geoffrey42

New member
Aug 22, 2006
862
0
0
I feel more awesome now. And silly, because this was MUCH faster. I don't have Visual Studio installed anymore, but I always forget how easy it is to just throw together a VB script.

Dim a, b, c, d, e, f, count

count = 0
For a = 1 To 10
For b = 1 To 10
For c = 1 To 10
For d = 1 To 10
For e = 1 To 10
For f = 1 To 10
If a + b + c + d + e + f = 30 Then
count = count + 1
End If
Next f
Next e
Next d
Next c
Next b
Next a

Sheets("Sheet1").Cells(1, 1).Value = count
My result? 50877. I can take the ~ off my 217 now.

It would appear, from my rudimentary search of Python syntax for for loops, that when you put for _ in (1, 10), it will only go from 1 through and including 9. If you up your code to (1,11,1) I think you might get the same result.
 

Wickedshot

New member
Jul 11, 2006
45
0
0
Ya, I felt mine was low and I'm pretty sure I should've started them at 0 or ended at 11 to get the proper range but I was tired when I wrote it (plus I didn't have a real compiler and just spliced it into my Civilization 4 code lol). Good to see we got 2 others who did it with equal results heh.

50,877 is higher than I expected in a result that is ideally highest (more variation of choices is good for customization).

Haven't been able to figure a tidy formula for the answer, but atleast some really short programs for it.