Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 5, 2014 21:44:40 GMT
Using Excel you could list all the invoices amounts in a column and then create multiple columns to the right to add markers for every sum combination of the list (just Y and N), and then use SUMIF to add the invoices based on the markers. The SUMIF result that equals the amount paid (or potentially more than one) will give you the answer. If you have more than one match you need to identify if one of the unique invoices in the combination that matches is being paid or not.
Lawrence
|
|
|
Post by MartinT on Jul 6, 2014 15:08:16 GMT
It's mathematical combinations.
n = no. of invoices k = no. of invoices a payment covers
So, for 20 invoices (n=20), 5 invoices paid (k=5)
Combinations = (205) = 20! / (5! x 15!) = 15,504 (someone please check my maths)
So it's a non-trivial exercise. Did anyone check my maths?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 6, 2014 16:01:18 GMT
It's mathematical combinations.
n = no. of invoices k = no. of invoices a payment covers
So, for 20 invoices (n=20), 5 invoices paid (k=5)
Combinations = (205) = 20! / (5! x 15!) = 15,504 (someone please check my maths)
So it's a non-trivial exercise. Did anyone check my maths? I didn't check your maths but I have some code now and I'm pretty certain that the complexity is 2^n - 1 which means for 15 unpaid invoices there are 32767 combinations to check i.e 32767 combinations of unpaid invoices to check against the value just paid by the unhelpful customer. like I said previously if you have 1 bit for every unpaid invoice e.g 5 unpaid invoices gives a number with 5 bits then counting from 1 to this number will give you every combination of bit patterns for that number of bits...well 5 invoices gives 5 bits which is 2^5 which is 32, subtract 1 to get the number with 5 bits and discount 0.....so you end up with the number 31(5 bits set) from 1 to 31 each iteration gives you a bit pattern which corresponds to the invoice index in the list of invoices. just go through and check every combination against the amount paid, and you will find the combination that adds up to the payment... this is trivial IMO, and certainly from an O(order of complexity position) edit: I tried it with 6 as well so it passes proof by induction... @martin I just edited out my comment about your equation....I'm still creeping up on the logic... are you saying thats the order of complexity if the value just received related to 5 invoices in the list?
|
|
|
Post by MartinT on Jul 6, 2014 16:36:07 GMT
Hmm, I used the formula for mathematical combinations but your process seems good, too.
Combinations = (xy) = x! / (y! * (x-y)!)
For 15 invoices, 5 payments, I get 3003 combinations.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 6, 2014 16:43:10 GMT
Hmm, I used the formula for mathematical combinations but your process seems good, too.
Combinations = (xy) = x! / (y! * (x-y)!)
For 15 invoices, 5 payments, I get 3003 combinations. My edited response originall said I think your equation relates to combinations where every position might be filled, e.g you have the list abcd so every combination of those 4 entries being present. I was thinking it may not consider if only one, or two, or three of the entries was present. I thought your factorial equation looked similar to the wiki equation, which does only consider combinations where every item in the list is present. still pondering... If Mike is serious about this and tells me what format his list is in then he can have the code/app. edit: the other thing that I thought about was.......there is no mention of how many invoices the received payment relates to. I was making no assumptions about this so the method I outlined covers any amount of invoices being included in the payment, with the addition that it will find any duplicate combinations that add up to the payment... it's deffo a good question.
|
|
|
Post by MartinT on Jul 6, 2014 16:49:05 GMT
Yes, Ed, you're right. It doesn't allow for fewer invoices than 5 filling the criteria.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 6, 2014 17:05:17 GMT
42
|
|
|
Post by MartinT on Jul 6, 2014 17:17:44 GMT
Was that from Deep Thought or the Pondermatic?
|
|
|
Post by MikeMusic on Jul 7, 2014 10:33:16 GMT
Thanks Ed, much appreciated.
These are now in the past, but may have a similar problem in the future.
It is possible invoice values could be the same, but quite unlikely.
5 total to check out is easy. I can look and find or cut and paste into Excel and twiddle.
Problem comes when we have a few o/s from Month 1, 50 from Month 2 and 60 from Month 3. There may even be a month 4.
They could be paying up some or all of the old ones with and/or some current ones. They are a law to themselves.
When reaching a halt in programming I find a trip to the loo nearly always works wonders I work in the wonderful FoxPro, can export easily into Excel Think I could programme this into Fox given time, which I don't have - unless I go to the loo more often !
|
|
|
Post by MikeMusic on Jul 7, 2014 10:43:35 GMT
Using Excel you could list all the invoices amounts in a column and then create multiple columns to the right to add markers for every sum combination of the list (just Y and N), and then use SUMIF to add the invoices based on the markers. The SUMIF result that equals the amount paid (or potentially more than one) will give you the answer. If you have more than one match you need to identify if one of the unique invoices in the combination that matches is being paid or not. Lawrence Thanks Beginning to see how I might do that. Could use Fox in a browse. Only use Excel as a great calculator plus a bit, not familiar with programming terms , so SUMIF is not one I know, even though I might have moused it and not known. Google not helping me enough. SUMIF may or may not do it for me
|
|
|
Post by MikeMusic on Jul 7, 2014 10:48:33 GMT
Ed and Martin
I'm serious and so is my accountant as he has the same problem X times over. If there were only 15 to choose a selection of say 5 I can do that fairly easily. Knocking out the big ones that exceed the payment reduces that 15. The bigger ones, if when added to the smallest exceed the total can also be knocked out.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 8, 2014 11:58:08 GMT
eureka, I've found it, it's known as the subset sum problem: en.wikipedia.org/wiki/Subset_sum_problemI now realise why my solution O(2^n - 1) was taking such a long time for a large list... it should be O(2^n/2), much more civilised.... mikemy code was good for n<33 (less than 33 unpaid invoices) but upwards of 60 is a problem because it's not possible to use an unsigned 64 bit integer as a loop counter....It needed further time consuming mods. I'm looking at the new wiki algorithm, what kind of saddo am I that views this as a challenge? If you're still interested I will let you have a revised app. edit: better still, here is the complete answer: www.geeksforgeeks.org/dynamic-programming-subset-sum-problem/
|
|
|
Post by MikeMusic on Jul 8, 2014 13:12:54 GMT
Wow Thanks Ed.
You like sums ! Numbers have a fascination and you/we can read more into them. To manipulate them is even cooler. I still like programming in FoxPro and database twiddling.
We were keen at school on Maths. Had such a good teacher a bundle of us made Grade 1 Maths O level at 15.
What is this code plugged into, and how do I use it ?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 8, 2014 14:46:40 GMT
I was originally going to send you an app, such as the one following. This one is written in pascal/delphi/lazarus but the examples in the link I posted are in C++. I don't know much about Foxpro but have a feeling the programming language might baulk at this code....my present method requires bit manipulation and/or recursion and the C++ requires recursion, which means great control of the stack space...this might upset foxpro, but as I say I'm not sure...Try it and see, but the examples shown do not indicate the the list entries that qualify so they will need a bit of amending. this app requires a list of unpaid invoices in a text file, one per line/record, which I'm sure foxpro can supply. Enter the paid value and press the find button and it highlights the found entries in the list in red.
|
|
|
Post by MikeMusic on Jul 8, 2014 14:54:57 GMT
Thanks again
I'm about the only punter in the world who doesn't have a mobile Can I plug this code into something on the pc ?
(Programming in FoxPro is about all I am competent to do BTW)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 8, 2014 15:05:13 GMT
the simple answer is no.
You could plug the C++ example into a compiler if you had one but it still wouldn't show you the relevant invoices without a bit of adjustment to the code.
I'm quite happy to send you a windows app(32 or 64 bit) like the example above, If you're willing to wait a couple of days. Providing I conquer the problem that is.
Mike wrote: I'm about the only punter in the world who doesn't have a mobile
no! there are 2 of us
cor this quote function takes a bit of getting used to.
|
|
|
Post by MikeMusic on Jul 9, 2014 8:52:30 GMT
the simple answer is no. You could plug the C++ example into a compiler if you had one but it still wouldn't show you the relevant invoices without a bit of adjustment to the code. I'm quite happy to send you a windows app(32 or 64 bit) like the example above, If you're willing to wait a couple of days. Providing I conquer the problem that is. Mike wrote: I'm about the only punter in the world who doesn't have a mobileno! there are 2 of us cor this quote function takes a bit of getting used to. Thanks Ed. I can happily wait a couple of days We have an exclusive non phone club of 2 ! Swap to BB code for easier or use Reply in the white box. If I back space in Quote I go into the original and can't get out. Have to cancel and try again
|
|
|
Post by MartinT on Jul 10, 2014 6:42:10 GMT
If I back space in Quote I go into the original and can't get out. Have to cancel and try again Next time, switch to BBCode, add an Enter after the [ /quote] tag, switch back to Preview and you're good to go.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 11, 2014 12:36:34 GMT
Hi Mike there has been a delay with this, life has conspired to get in the way..... I now have an initial working version(see below). A couple of things to note: a) its all too easy to get multiple solutions(this version doesn't address this situation) b) the problem complexity is exponential, depending on muber of unpaid invoices. The following maximum times show the issue: examples: n = 20 takes 0.19 seconds n = 25 takes 6.05 seconds n = 32 takes 945.9 seconds be aware that these are amaximum times, if a solution exists then it will usually be found well under the maximum time. the current version only has 2 threads running. This could be increased to halve the problem space. The current version only allows for 32 unpaid invoices. Increasing this would necessitate adding extra threads otherwise the elapsed times wouldn't be practical. Extra threads takes development time which I will do if you are still interested, but it won't happen for a while. If you want to play with this version I will send a link to the zip in a message. This one is 32 bit windows tested on win7.
|
|
|
Post by MikeMusic on Jul 11, 2014 13:25:36 GMT
Hi Ed
Thanks I'd like to give it a go. Can test on real data
Just one thing. Can someone of limited abilities, me, make this work ok ?
|
|