Re: Idiomatic backtracking in Python

2015-02-03 Thread Chris Angelico
On Wed, Feb 4, 2015 at 8:16 AM, Dave Angel wrote: >> Obviously you have to define the branch somehow, but there are plenty >> of times when you might want to break out of "everything up to here". >> How do you define that? How do you return lots of levels all at once? >> I remember facing this exa

Re: Idiomatic backtracking in Python

2015-02-03 Thread Dave Angel
On 01/25/2015 08:45 PM, Chris Angelico wrote: On Mon, Jan 26, 2015 at 12:31 PM, Marko Rauhamaa wrote: Backtracking means the part of depth-first traversal where you retreat to the parent node. If you implement your traversal with a recursive function, backtracking means — more or less — a retur

Re: Idiomatic backtracking in Python

2015-01-27 Thread sjmsoft
On Sunday, January 25, 2015 at 4:15:58 PM UTC-4, Johannes Bauer wrote: > Hi folks, > > I have a problem at hand that needs code for backtracking as a solution. > And I have no problem coding it, but I can't get rid of the feeling that > I'm always solving backtracking problems in a non-Pythonic >

Re: Idiomatic backtracking in Python

2015-01-26 Thread Mark Lawrence
On 26/01/2015 00:32, Ben Finney wrote: Johannes Bauer writes: So, I would like to ask if you have a Pythonic approach to backtracking problems? If so, I'd love to hear your solutions! I'm not aware of what the problem is. “Back-tracking” doesn't have a general meaning I recognise beyond rand

Re: Idiomatic backtracking in Python

2015-01-25 Thread Rustom Mody
On Monday, January 26, 2015 at 12:52:04 PM UTC+5:30, Jussi Piitulainen wrote: > Rustom Mody writes: > > > To add to Ian: > > > > The classic way of doing it in a functional framework is called: > > "Replace failure by list of successes" > > > > https://rkrishnan.org/files/wadler-1985.pdf > > >

Re: Idiomatic backtracking in Python

2015-01-25 Thread Jussi Piitulainen
Rustom Mody writes: > To add to Ian: > > The classic way of doing it in a functional framework is called: > "Replace failure by list of successes" > > https://rkrishnan.org/files/wadler-1985.pdf > > The things that have to go into it are > 1. Extensive use of list comprehensions > 2. Lazy lists

Re: Idiomatic backtracking in Python

2015-01-25 Thread Rustom Mody
On Monday, January 26, 2015 at 2:21:34 AM UTC+5:30, Ian Foote wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi, > > I think a very idiomatic way to implement backtracking is using a > recursive generator (python 3): > > def backtrack_solver(data=None): > if data is None: >

Re: Idiomatic backtracking in Python

2015-01-25 Thread Chris Angelico
On Mon, Jan 26, 2015 at 12:31 PM, Marko Rauhamaa wrote: > Backtracking means the part of depth-first traversal where you retreat > to the parent node. If you implement your traversal with a recursive > function, backtracking means — more or less — a return from the > function. But possibly you ne

Re: Idiomatic backtracking in Python

2015-01-25 Thread Marko Rauhamaa
Ben Finney : > “Back-tracking” doesn't have a general meaning I recognise beyond > random access into a data structure. Backtracking means the part of depth-first traversal where you retreat to the parent node. If you implement your traversal with a recursive function, backtracking means — more o

Re: Idiomatic backtracking in Python

2015-01-25 Thread MRAB
On 2015-01-26 00:32, Ben Finney wrote: Johannes Bauer writes: So, I would like to ask if you have a Pythonic approach to backtracking problems? If so, I'd love to hear your solutions! I'm not aware of what the problem is. “Back-tracking” doesn't have a general meaning I recognise beyond rand

Re: Idiomatic backtracking in Python

2015-01-25 Thread Ben Finney
Johannes Bauer writes: > So, I would like to ask if you have a Pythonic approach to > backtracking problems? If so, I'd love to hear your solutions! I'm not aware of what the problem is. “Back-tracking” doesn't have a general meaning I recognise beyond random access into a data structure. So a P

Re: Idiomatic backtracking in Python

2015-01-25 Thread Ian Foote
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I think a very idiomatic way to implement backtracking is using a recursive generator (python 3): def backtrack_solver(data=None): if data is None: yield from backtrack_solver(data=initial_data) if cannot_be_valid(data):

Idiomatic backtracking in Python

2015-01-25 Thread Johannes Bauer
Hi folks, I have a problem at hand that needs code for backtracking as a solution. And I have no problem coding it, but I can't get rid of the feeling that I'm always solving backtracking problems in a non-Pythonic (non-idiomatic) way. So, I would like to ask if you have a Pythonic approach to bac