Re: Can this program be shortened? Measuring program-length?

2008-07-10 Thread r.e.s.
"r.e.s." <[EMAIL PROTECTED]> wrote ... > <[EMAIL PROTECTED]> wrote ... >> "r.e.s." <[EMAIL PROTECTED]> wrote: >>> Can the following program be shortened? ... >>> >>> def h(n,m): >>> E=n, >>> while (E!=(

Re: Can this program be shortened? Measuring program-length?

2008-07-10 Thread r.e.s.
<[EMAIL PROTECTED]> wrote ... > "r.e.s." <[EMAIL PROTECTED]> wrote: >> Can the following program be shortened? ... >> >> def h(n,m): >> E=n, >> while (E!=())*m>0:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n >> return n >>

Can this program be shortened? Measuring program-length?

2008-07-10 Thread r.e.s.
Can the following program be shortened? ... def h(n,m): E=n, while (E!=())*m>0:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n return n h(9,9) Note: Although it halts eventually in principle, this program can't be expected to terminate on any machine in the universe, as it computes a number lar

Re: number of different lines in a file

2006-05-18 Thread r.e.s.
"Tim Chase" <[EMAIL PROTECTED]> wrote ... > 2) use a python set: > > s = set() > for line in open("file.in"): > s.add(line.strip()) > return len(s) > > 3) compact #2: > > return len(set([line.strip() for line in file("file.in")])) > > or, if stripping the lines isn't a concern, it can just be

number of different lines in a file

2006-05-18 Thread r.e.s.
I have a million-line text file with 100 characters per line, and simply need to determine how many of the lines are distinct. On my PC, this little program just goes to never-never land: def number_distinct(fn): f = file(fn) x = f.readline().strip() L = [] while x<>'': if

Re: sudoku dictionary attack

2005-06-20 Thread r.e.s.
"Oliver Albrecht" <[EMAIL PROTECTED]> wrote ... > Has some one an sodoku-task-generator? Sudoku puzzles can be generated (and solved) online at http://act365.com/sudoku/ -- http://mail.python.org/mailman/listinfo/python-list