Re: combinatorics via __future__ generators

2009-12-01 Thread John Yeung
On Dec 1, 5:55 pm, Phlip wrote: > Awesome thanks - but: > > > from itertools import imap,product > > Do we have a version for Python2.5? I have to support an older server > here; can't install a newer python on it... If you can get by with the performance of pure Python, a solution is right in th

Re: combinatorics via __future__ generators

2009-12-01 Thread Phlip
Awesome thanks - but: > from itertools import imap,product Do we have a version for Python2.5? I have to support an older server here; can't install a newer python on it... -- http://mail.python.org/mailman/listinfo/python-list

Re: combinatorics via __future__ generators

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 4:58 PM, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > >

Re: combinatorics via __future__ generators

2009-11-18 Thread Phlip
On Nov 18, 4:58 pm, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > >

combinatorics via __future__ generators

2009-11-18 Thread Phlip
Python: I have a quaint combinatorics problem. Before I solve it, or find a solution among "generators", I thought y'all might like to show off any solutions. Given an array like this... [0, 4, 3] Produce an array like this: [ [0, 0, 0], [0, 1, 0], [0, 2, 0

Re: Combinatorics

2008-02-13 Thread Paul Hankin
On Feb 12, 7:52 am, Michael Robertson <[EMAIL PROTECTED]> wrote: > Where is the python equivalent of: > > http://search.cpan.org/~fxn/Algorithm-Combinatorics-0.16/Combinatoric... > > combinations (with and without repetition) > variations (with and without repetition) >

Re: Combinatorics

2008-02-13 Thread Thorsten Kampe
* Michael Robertson (Mon, 11 Feb 2008 23:52:31 -0800) > Where is the python equivalent of: > > http://search.cpan.org/~fxn/Algorithm-Combinatorics-0.16/Combinatorics.pm > > combinations (with and without repetition) > variations (with and without repetition) > permutations

Re: Combinatorics

2008-02-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: >Cameron Laird: >> It does occur to me, though, that even more widely applicable >> than the combinatorics module of Mathematica (if only because of >> its licensing) might be such resources as > &g

Re: Combinatorics

2008-02-12 Thread Raymond Hettinger
On Feb 11, 11:52 pm, Michael Robertson <[EMAIL PROTECTED]> wrote: > Where is the python equivalent of: > > http://search.cpan.org/~fxn/Algorithm-Combinatorics-0.16/Combinatoric... > > combinations (with and without repetition) > variations (with and without repetition) >

Re: Combinatorics

2008-02-12 Thread Jaap Spies
Robert Dodier wrote: > Cameron Laird wrote: > >> Should combinatorics be part of the standard library? That's >> an aesthetic-pragmatic question I don't feel competent to >> answer; I look to timbot and Guido and so on for judgment there. >> It does oc

Re: Combinatorics

2008-02-12 Thread [EMAIL PROTECTED]
On Feb 12, 1:52 am, Michael Robertson <[EMAIL PROTECTED]> wrote: > Where is the python equivalent of: > > http://search.cpan.org/~fxn/Algorithm-Combinatorics-0.16/Combinatoric... > > combinations (with and without repetition) > variations (with and without repetition) >

Re: Combinatorics

2008-02-12 Thread bearophileHUGS
Cameron Laird: > It does occur to me, though, that even more widely applicable > than the combinatorics module of Mathematica (if only because of > its licensing) might be such resources as What I was trying to say is that that Mathematica combinatorics module contains lots and lots an

Re: Combinatorics

2008-02-12 Thread Robert Dodier
Cameron Laird wrote: > Should combinatorics be part of the standard library? That's > an aesthetic-pragmatic question I don't feel competent to > answer; I look to timbot and Guido and so on for judgment there. > It does occur to me, though, that even more widely

Re: Combinatorics

2008-02-12 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: >Michael Robertson: >> I'm guessing sage has this, but shouldn't something like this be part of >> the standard library (perhaps in C)? > >My answer is positive. As a reference point y

Re: Combinatorics

2008-02-12 Thread Steven D'Aprano
int > > The problem seems to be that although python supports arbitrary long > integers, all the internal loop counters still use limited size > integers. I'm curious what you think this has to do with the Original Poster's question, which was about combinatorics (as the su

Re: Combinatorics

2008-02-12 Thread pataphor
On Mon, 11 Feb 2008 23:52:31 -0800 Michael Robertson <[EMAIL PROTECTED]> wrote: > Am I wishing on a star? for i in xrange(10**10): print i OverflowError: long int too large to convert to int The problem seems to be that although python supports arbitrary long integers, all the internal loop

Re: Combinatorics

2008-02-12 Thread bearophileHUGS
Michael Robertson: > I'm guessing sage has this, but shouldn't something like this be part of > the standard library (perhaps in C)? My answer is positive. As a reference point you can look at the combinatorics module of Mathematica. Bye, bearophile -- http://mail.python.org/

Combinatorics

2008-02-11 Thread Michael Robertson
Where is the python equivalent of: http://search.cpan.org/~fxn/Algorithm-Combinatorics-0.16/Combinatorics.pm combinations (with and without repetition) variations (with and without repetition) permutations partitions derangements etc I'm guessing sage has this, but shouldn't something

Re: Python and Combinatorics

2007-10-26 Thread Gerard Flanagan
On Oct 25, 12:20 am, none <""atavory\"@(none)"> wrote: > Hello, > > Is there some package to calculate combinatorical stuff like (n over > k), i.e., n!/(k!(n - k!) ? > > I know it can be written in about 3 lines of code, but still... > > Thanks, > > Ami http

Re: Python and Combinatorics

2007-10-25 Thread Alan Isaac
none wrote: > Is there some package to calculate combinatorical stuff like (n over > k), i.e., n!/(k!(n - k!) ? Yes, in SciPy. Alan Isaac >>> from scipy.misc.common import comb >>> help(comb) Help on function comb in module scipy.misc.common: comb(N, k, exact=0) Combinations of N thin

Re: Python and Combinatorics

2007-10-24 Thread none
[EMAIL PROTECTED] wrote: > On Oct 24, 5:20 pm, none <""atavory\"@(none)"> wrote: >> Hello, >> >> Is there some package to calculate combinatorical stuff like (n over >> k), i.e., n!/(k!(n - k!) ? > > Sure, the gmpy module. > Excellent, many thanks! -- http://mail.python.org/mail

Re: Python and Combinatorics

2007-10-24 Thread [EMAIL PROTECTED]
On Oct 24, 5:20 pm, none <""atavory\"@(none)"> wrote: > Hello, > > Is there some package to calculate combinatorical stuff like (n over > k), i.e., n!/(k!(n - k!) ? Sure, the gmpy module. >>> import gmpy >>> for m in xrange(10): for n in xrange(m+1): print

Python and Combinatorics

2007-10-24 Thread none
Hello, Is there some package to calculate combinatorical stuff like (n over k), i.e., n!/(k!(n - k!) ? I know it can be written in about 3 lines of code, but still... Thanks, Ami -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Combinatorics

2006-05-16 Thread Peter Otten
Nic wrote: > In my example I've chosen the number 3. > How should I change the Python code in order to select another number > (e.g. 7)? Here is a parameterized render(). def render(w, h, suffixes="ab"): pairs = list(unique(range(1, h+1), 2)) for item in unique(pairs, w): for suf

Re: Python and Combinatorics

2006-05-16 Thread Nic
Thanks a bunch. Both the codes are fine. Only one question, if you allow. In my example I've chosen the number 3. How should I change the Python code in order to select another number (e.g. 7)? Thanks. Nic -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Combinatorics

2006-05-16 Thread Gerard Flanagan
Nic wrote: > Hello, > I've a problem in defining a good Python code useful to articulate the > following algorithm. > Can you help me please? > Thanks a bunch, > Nic > > 1. Insert a number "n". > Example: 3 > > 2. List all the numbers < or = to n. > Example: 1,2,3. > > 3. Combine the listed number

Re: Python and Combinatorics

2006-05-16 Thread Peter Otten
Nic wrote: >> PS: Please don't top-post. You probably overlooked that :-) Here's a naive implementation: from itertools import izip def unique(items, N): assert N > 0 if N == 1: for item in items: yield item, else: for index, item in enumerate(items):

Re: Python and Combinatorics

2006-05-16 Thread Nic
I forgot them. Sorry. They should be included. Nic "Peter Otten" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Nic wrote: > > [Algorithm that I may have misunderstood] > >> 12a 13a 23a >> 12a 13b 23a >> 12a 13b 23b >> 12b 13a 23a >> 12b 13b 23a >> 12b 13b 23b > > What abou

Re: Python and Combinatorics

2006-05-16 Thread Peter Otten
Nic wrote: [Algorithm that I may have misunderstood] > 12a 13a 23a > 12a 13b 23a > 12a 13b 23b > 12b 13a 23a > 12b 13b 23a > 12b 13b 23b What about 12a 13a 23b and 12b 13a 23b? Peter PS: Please don't top-post. -- http://mail.python.org/mailman/listinfo/python-list

Python and Combinatorics

2006-05-16 Thread Nic
Hello, I've a problem in defining a good Python code useful to articulate the following algorithm. Can you help me please? Thanks a bunch, Nic 1. Insert a number "n". Example: 3 2. List all the numbers < or = to n. Example: 1,2,3. 3. Combine the listed numbers each other. Example: 12 13 23 4.

Re: [perl-python] combinatorics fun

2005-02-11 Thread bruno modulix
YYUsenet wrote: Xah Lee wrote: (snip insanities) Why are you posting this to comp.lang.python? This obviously has nothing to do with python at all. If you are trying to teach people python, claiming that "...let's do a python version. I'll post my version later today." Isn't really the proper

Re: [perl-python] combinatorics fun

2005-02-10 Thread Xah Lee
David Eppstein's code is very nice. Here's the python version of the perl code: ©# -*- coding: utf-8 -*- ©# Python © ©def combo (n): ©'''returns all possible (unordered) pairs out of n numbers 1 to n. © ©Returns a dictionary. The keys are of the form "n,m", ©and their values are tuple

Re: [perl-python] combinatorics fun

2005-02-10 Thread Haibao Tang
I am no longer resisting. As time goes, the nausea when I first saw Mr. Lee's smelly "technical posts" is starting to fade. The discussion group should have a high tolerance towards polymorphic people these days. -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] combinatorics fun

2005-02-10 Thread YYUsenet
Xah Lee wrote: a year ago i wrote this perl program as part of a larger program. as a exercise of fun, let's do a python version. I'll post my version later today. [code snipped] This is Perl-Python a-day. To subscribe, see http://xahlee.org/perl-python/python.html Xah [EMAIL PROTECTED] http://xah

Re: [perl-python] combinatorics fun

2005-02-10 Thread axel
In comp.lang.perl.misc Xah Lee <[EMAIL PROTECTED]> wrote: > a year ago i wrote this perl program as part of a larger program. > sub combo ($) { >my $max=$_[0]; >my %hh=(); >for (my $j=1; $j < $max; ++$j) { >for (my $i=1; $i <= $max; ++$i) { >my $m = (($i+$j)-1)%$ma

Re: [perl-python] combinatorics fun

2005-02-10 Thread Jack Diederich
On Thu, Feb 10, 2005 at 02:51:24PM -0800, Xah Lee wrote: > a year ago i wrote this perl program as part of a larger program. > > as a exercise of fun, let's do a python version. I'll post my version > later today. from probstat import Combination There is something deeply wrong about plugging yo

Re: [perl-python] combinatorics fun

2005-02-10 Thread David Eppstein
In article <[EMAIL PROTECTED]>, "Xah Lee" <[EMAIL PROTECTED]> wrote: > combo(n) returns a collection with elements of pairs that is all > possible combinations of 2 things from n. For example, combo(4) > returns {'3,4' => ['3',4],'1,2' => [1,2],'1,3' => [1,3],'1,4' => > [1,4],'2,3' => ['2',3],'2,

[perl-python] combinatorics fun

2005-02-10 Thread Xah Lee
a year ago i wrote this perl program as part of a larger program. as a exercise of fun, let's do a python version. I'll post my version later today. =pod combo(n) returns a collection with elements of pairs that is all possible combinations of 2 things from n. For example, combo(4) returns {'3,4