Re: My own accounting python euler problem

2009-11-11 Thread Raymond Hettinger
[vsoler] > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > payment corresponds to. > > For

Re: My own accounting python euler problem

2009-11-11 Thread John Machin
On Nov 8, 8:39 am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > paymen

Re: My own accounting python euler problem

2009-11-11 Thread Steven D'Aprano
On Tue, 10 Nov 2009 14:59:13 -0800, John Machin wrote: > On Nov 8, 8:39 am, vsoler wrote: >> In the accounting department I am working for we are from time to time >> confronted to the following problem: > [snip] > >> My second question is: >> 2. this time there are also credit notes outstanding

Re: My own accounting python euler problem

2009-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2009 14:46:49 -0800, John Machin wrote: > The problems that you mention are only a SUBSET of the total problem. > Example: oustanding invoices are for 300, 200, and 100 and the cheque is > for 450 -- in general the total of the cheque amounts does not equal the > total of any possib

Re: My own accounting python euler problem

2009-11-10 Thread John Machin
On Nov 8, 8:39 am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > My second question is: > 2. this time there are also credit notes outstanding, that is, > invoices with negative amounts. For example,  I=[500,

Re: My own accounting python euler problem

2009-11-10 Thread Mel
Gerry wrote: > On Nov 8, 2:42 pm, Ozz wrote: >> vsoler schreef: >> > And, of course, you'd want to take a look a this: http://xkcd.com/287/ :) I remember that. mwil...@tecumseth:~/sandbox$ python xkcd_complete.py [1, 0, 0, 2, 0, 1] 1505 [7] 1505 Mel. -- http://mail.python.org/mailma

Re: My own accounting python euler problem

2009-11-10 Thread MRAB
Gerry wrote: On Nov 8, 2:42 pm, Ozz wrote: vsoler schreef: And, of course, you'd want to take a look a this: http://xkcd.com/287/ I've found 2 solutions. (And I really should get back to what I was doing...) Gerry Instead of subsets, do you mean permutations/combinations? Since 2 invo

Re: My own accounting python euler problem

2009-11-10 Thread geremy condra
On Tue, Nov 10, 2009 at 8:59 AM, Steven D'Aprano wrote: > On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote: > >> What you're describing is the powerset operation. Here's the example >> from the python docs: > [...] >> What I find interesting is that running it through timeit, it is much >>

Re: My own accounting python euler problem

2009-11-10 Thread Steven D'Aprano
On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote: > What you're describing is the powerset operation. Here's the example > from the python docs: [...] > What I find interesting is that running it through timeit, it is much > slower than the code suggested by Dan Bishop. Your test doesn't s

Re: My own accounting python euler problem

2009-11-10 Thread Gerry
On Nov 8, 2:42 pm, Ozz wrote: > vsoler schreef: > And, of course, you'd want to take a look a this: http://xkcd.com/287/ Gerry > > > Instead of subsets, do you mean permutations/combinations?  Since 2 > > invoices can have the same amount perhaps the terms permutation is > > better. > > As some

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
vsoler schreef: Instead of subsets, do you mean permutations/combinations? Since 2 invoices can have the same amount perhaps the terms permutation is better. As some other poster already suggested 'powerset' ( http://en.wikipedia.org/wiki/Power_set ) may be a better name, except for those

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
Dan Bishop schreef: You can avoid the S list my making it a generator: def subsets(L): if L: for s in subsets(L[1:]): yield s yield s + [L[0]] else: yield [] Nice one. Thanks! Ozz -- http://mail.python.org/mailman/listinfo/python-list

Re: My own accounting python euler problem

2009-11-08 Thread geremy condra
On Sun, Nov 8, 2009 at 12:31 PM, geremy condra wrote: > On Sun, Nov 8, 2009 at 11:52 AM, Dan Bishop wrote: >> On Nov 8, 4:43 am, Ozz wrote: >>> Hi, >>> >>> > My first question is: >>> > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >>> > check Ch=600 >>> > how can I print al

Re: My own accounting python euler problem

2009-11-08 Thread geremy condra
On Sun, Nov 8, 2009 at 11:52 AM, Dan Bishop wrote: > On Nov 8, 4:43 am, Ozz wrote: >> Hi, >> >> > My first question is: >> > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >> > check Ch=600 >> > how can I print all the different combinations of invoices that the >> > check is

Re: My own accounting python euler problem

2009-11-08 Thread MRAB
Ozz wrote: Hi, My first question is: 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a check Ch=600 how can I print all the different combinations of invoices that the check is possibly cancelling Incidentally, I'm currently learning python myself, and was working on more

Re: My own accounting python euler problem

2009-11-08 Thread vsoler
On Nov 8, 1:27 pm, Ozz wrote: > Robert P. J. Day schreef: > > >   does your solution allow for the possibility of different invoices > > of equal amounts?  i would be reluctant to use the word "subset" in a > > context where you can have more than one element with the same value. > > I think it ha

Re: My own accounting python euler problem

2009-11-08 Thread Dan Bishop
On Nov 8, 4:43 am, Ozz wrote: > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learning

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
Robert P. J. Day schreef: does your solution allow for the possibility of different invoices of equal amounts? i would be reluctant to use the word "subset" in a context where you can have more than one element with the same value. I think it handles different invoices of equal amounts corre

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
Oops, For listing all different subsets of a list (This is what I came up with. Can it be implemented shorter, btw?): def subsets(L): S = [] if (len(L) == 1): return [L, []] better to check for the empty set too, thus; if (len(L) == 0): retur

Re: My own accounting python euler problem

2009-11-08 Thread Robert P. J. Day
On Sun, 8 Nov 2009, Ozz wrote: > > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learni

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
Hi, My first question is: 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a check Ch=600 how can I print all the different combinations of invoices that the check is possibly cancelling Incidentally, I'm currently learning python myself, and was working on more or less the

Re: My own accounting python euler problem

2009-11-07 Thread Martin P. Hellwig
vsoler wrote: As mentioned in the other answers, your problem is best solved by a long overdue organisational decision instead of a technical one. Most popular solutions are: - All invoices are essential a single credit amount, money coming in is taken of from the big pile. - Invoices are spli

Re: My own accounting python euler problem

2009-11-07 Thread Robert P. J. Day
On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payme

Re: My own accounting python euler problem

2009-11-07 Thread Robert P. J. Day
On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payme

Re: My own accounting python euler problem

2009-11-07 Thread Jack Diederich
On Sat, Nov 7, 2009 at 4:39 PM, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > For example, say that the customer has the following outstanding > invoices:  $300, $200, $50; and say that the check is for $250.

My own accounting python euler problem

2009-11-07 Thread vsoler
In the accounting department I am working for we are from time to time confronted to the following problem: A customer sends us a check for a given amount, but without specifying what invoices it cancels. It is up to us to find out which ones the payment corresponds to. For example, say that the