|
| 03 May 2016 09:20 PM |
So lets say I have a number/value, which is 36 for example. How would I find the number of ways it could be partitioned on Roblox?
Thanks!
Profit pls. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 09:23 PM |
Am I stupid because I don't understand you? Well, obviously no, but it's a contributing factor. What do you mean? |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 09:29 PM |
So I want to find the number of ways which a number can be split up into
for example the number 3 has a total of 2 non redundant integers it can be made up of
1+1+1 1+2
How would I find the number of partitions for any set of values. I don't want a full script, but I'd like to have some links to some useful wiki pages which could help me. And the different things I'd need to know, in order to start doing it myself.
I have almost no knowledge, but I'd like to get started somewhere.
Profit pls. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 03 May 2016 09:35 PM |
local function eulerPartition(n, domain) assert(domain > 0 and select(math.modf(domain), 2) == 0, "Domain must be a positive integer.") local sum = 0 for i = -domain, domain, 1 do sum = sum + ( ((-1)^domain) * n^(domain * ( (3 * domain) + 1)/2))) end return sum end
print(eulerPartition(5, 1000)) |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 03 May 2016 09:45 PM |
Sorry, that was lazy of me. Errors an not even correct. Here is a circle method that is an approximation. Computing partitions if very... tasking:
local e = 2.71828182845904
local function eulerPartition(n, domain) assert(n > 0 and select(2,math.modf(n)) == 0, "Must be positive integer") return (e^( math.pi * math.sqrt((2*n)/3)))/ (4 * n * math.sqrt(3)) end
print(eulerPartition(20))
|
|
|
| Report Abuse |
|
|
|
| 03 May 2016 09:53 PM |
I've tried but I keep getting the same error. Could you give an example number of 5 in the code. I have no idea what I'm doing. But thanks for helping.
Profit pls. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 10:02 PM |
Okay so I think I figured it out
local e = 2.71828182845904
local function eulerPartition(n, domain) assert(n > 0 and select(2,math.modf(n)) == 0, "Must be positive integer") n = 100 return (e^( math.pi * math.sqrt((2*n)/3)))/ (4 * n * math.sqrt(3)) end
print(eulerPartition(20))
also I think e is too high(not too exact), so I'll start working on making it more exact. But thanks for helping me with doing this, everything seems to work, at least to my limited knowledge.
Profit pls. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 10:11 PM |
e= 2.71354905651 Should be almost exact.
Profit pls. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 03 May 2016 10:11 PM |
| Yeah, like I said, partitions are very.... hard to figure out in code accurately. You can use a Euler recurrence formula, but in coding it's best just to have a table with the numbers. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 03 May 2016 10:16 PM |
This function should be a better version of my second one:
local function asymptoticPartition(n) return (1/(4 * n * math.sqrt(3))) * math.exp(math.pi * math.sqrt((2*n)/3)) end
print(asymptoticPartition(5))
-> 8.9
Will always be 1.415% higher than the true value. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 10:19 PM |
You know.. although not very efficient. You could have a different number for e depending on n value. So if the n value is >50 for example use this e value etc. I'll have a look at the new way you did it also.
Profit pls. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 03 May 2016 10:20 PM |
| I get what you're saying, but read up on the Partition_(number_theory) page on Wikipedia. The only way to get an EXACT partition (like get 7 for 5) is to use a converging summation formula. Which would be VERY slow in programming. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 03 May 2016 10:30 PM |
Here's a... bad way to do it. But it is EXACT:
local function partition(sum, largestNum) if (largestNum == 0) then return 0 end if (sum == 0) then return 1 elseif (sum < 0) then return 0 end return partition(sum, largestNum- 1) + partition(sum - largestNum, largestNum) end
print(partition(5, 99))
-> 7 |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 11:11 PM |
That's pretty cool. I guess you could feed it all the ways to do it, and depending on the number itself, it would pick one to calculate it with. You could also add more variables into some of the older methods which you showed me to make it more accurate, for example the variable e would be smaller depending on variable n size, the smaller the n size the smaller the e size vice versa, at least to a certain extent.
Profit pls. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 11:15 PM |
Pretty neat stuff. I'll probably save everything, for later use in high school.
Profit pls. |
|
|
| Report Abuse |
|
|