Re: Just for fun: Countdown numbers game solver

2008-02-17 Thread wolfram . hinderer
On 22 Jan., 23:56, [EMAIL PROTECTED] wrote: > So anyone got an answer to which set of numbers gives the most targets > from 100 onwards say (or from 0 onwards)? IsPythonupto the task? It's (5, 8, 9, 50, 75, 100): 47561 targets altogether (including negative ones), 25814 targets >= 100. (BTW, 1226

Re: Just for fun: Countdown numbers game solver

2008-01-29 Thread Arnaud Delobelle
On Jan 29, 9:02 am, [EMAIL PROTECTED] wrote: Oops I sent too quickly... > If you've found an efficient way to walk through the possible > solutions only once, then > -  I expect that yours will be faster > -  and well done! > > I guess I should try to understand your code... My code is quite nai

Re: Just for fun: Countdown numbers game solver

2008-01-29 Thread Arnaud Delobelle
On Jan 29, 9:02 am, [EMAIL PROTECTED] wrote: > If you've found an efficient way to walk through the possible > solutions only once As discussed earlier in this thread, the definition of 'only once' is not as clear cut as one would first think (see Terry's thoughts on this). -- Arnaud -- http://

Re: Just for fun: Countdown numbers game solver

2008-01-29 Thread david . hotham
On Jan 28, 10:11 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > My strategy was to walk through each solution "only once" (for a > certain definition of "only once :), thus I was hoping not to need a > hashtable. Yes, that seems like it should be preferable (and indeed necessary for a more gene

Re: Just for fun: Countdown numbers game solver

2008-01-28 Thread Arnaud Delobelle
On Jan 28, 9:31 pm, [EMAIL PROTECTED] wrote: > I also had a go at this problem for a bit of python practice, about 6 > months ago. I tried a few optimizations and my experience was that > with only 6 seeds, a hash table was very effective. So effective, in > fact, that it made all other optimizat

Re: Just for fun: Countdown numbers game solver

2008-01-28 Thread david . hotham
I see I don't have as many columns as I'd expected. Here's a reformatted listing. from time import time from bisect import insort from sys import argv #- # Hash table is a global variable #-

Re: Just for fun: Countdown numbers game solver

2008-01-28 Thread david . hotham
I also had a go at this problem for a bit of python practice, about 6 months ago. I tried a few optimizations and my experience was that with only 6 seeds, a hash table was very effective. So effective, in fact, that it made all other optimizations more or less pointless. Code below. Arguments

Re: Just for fun: Countdown numbers game solver

2008-01-26 Thread Arnaud Delobelle
Right, I've cleaned up my efforts a bit: * tried to improve the efficiency of the 'fold' technique that I posted earlier. * taken on Dan's email about equivalence of expressions * created a problem random generator * created a little function test to time and compare various things, and a 'ran

Re: Just for fun: Countdown numbers game solver

2008-01-25 Thread Terry Jones
My output looks better sorted. I.e., for s in sorted(solutions)... Giving the easier to read/compare: Target 234, numbers = (100, 9, 7, 6, 3, 1) (6, 1, 'add', 100, 'mul', 7, 'sub', 9, 'add', 3, 'div') (6, 9, 'sub', 7, 'mul', 1, 'sub', 100, 'add', 3, 'mul') (7, 3, 'mul', 6,

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Terry Jones
> "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: >> >> Ha - you can't have it both ways Arnaud! You don't want the computation to >> go negative... doesn't that (and my "proof") have something to do with the >> inverse nature of add and sub? :-) Arnaud> I think I can have it both wa

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Arnaud Delobelle
On Jan 23, 8:40 pm, Terry Jones <[EMAIL PROTECTED]> wrote: > > "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: > > Arnaud> FWIW, I have a clear idea of what the space of solutions is, and > Arnaud> which solutions I consider to be equivalent.  I'll explain it > Arnaud> below.  I'm not

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread dg . google . groups
Well I tried the NumPy array thing that I was talking about, to parallelise the problem, and there were some difficulties with it. Firstly, the pruning makes a really big difference to the speed, and you don't get that if you're trying to parallelise the problem because what is an equivalent calcul

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Terry Jones
> "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: Arnaud> FWIW, I have a clear idea of what the space of solutions is, and Arnaud> which solutions I consider to be equivalent. I'll explain it Arnaud> below. I'm not saying it's the right model, but it's the one Arnaud> within which I

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Arnaud Delobelle
On Jan 23, 3:45 pm, Terry Jones <[EMAIL PROTECTED]> wrote: > Hi Arnaud and Dan Hi Terry > > "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: > >> What was wrong with the very fast(?) code you sent earlier? > > Arnaud> I thought it was a bit convoluted, wanted to try something I > Arna

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Terry Jones
Hi Arnaud and Dan > "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: >> What was wrong with the very fast(?) code you sent earlier? Arnaud> I thought it was a bit convoluted, wanted to try something I Arnaud> thought had more potential. I think the problem with the second Arnaud> one

Re: Just for fun: Countdown numbers game solver

2008-01-22 Thread Arnaud Delobelle
On Jan 22, 10:56 pm, [EMAIL PROTECTED] wrote: > Arnaud and Terry, > > Great solutions both of you! Much nicer than mine. I particularly like > Arnaud's latest one based on folding because it's so neat and > conceptually simple. For me, it's the closest so far to my goal of the > most elegant soluti

Re: Just for fun: Countdown numbers game solver

2008-01-22 Thread Arnaud Delobelle
On Jan 22, 9:05 am, Terry Jones <[EMAIL PROTECTED]> wrote: > Hi Arnaud > > > I've tried a completely different approach, that I imagine as 'folding'.  I > > thought it would improve performance over my previous effort but extremely > > limited and crude benchmarking seems to indicate disappointingl

Re: Just for fun: Countdown numbers game solver

2008-01-22 Thread dg . google . groups
Arnaud and Terry, Great solutions both of you! Much nicer than mine. I particularly like Arnaud's latest one based on folding because it's so neat and conceptually simple. For me, it's the closest so far to my goal of the most elegant solution. So anyone got an answer to which set of numbers give

Re: Just for fun: Countdown numbers game solver

2008-01-22 Thread Terry Jones
Hi Arnaud > I've tried a completely different approach, that I imagine as 'folding'. I > thought it would improve performance over my previous effort but extremely > limited and crude benchmarking seems to indicate disappointingly comparable > performance... I wrote a stack-based version yesterd

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Arnaud Delobelle
On Jan 20, 5:41 pm, [EMAIL PROTECTED] wrote: > Ever since I learnt to program I've always loved writing solvers for > the Countdown numbers game problem in different languages, and so now > I'm wondering what the most elegant solution in Python is. I've tried a completely different approach, that

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Arnaud Delobelle
On Jan 21, 9:01 am, [EMAIL PROTECTED] wrote: > Arnaud: I haven't had time to play with your solution yet - how quick > does it run? Ok I've done some quick timings, it's faster than I remembered it: numbers = [2, 4, 5, 8, 25] target = 758 Average time to find (1) best solution (in terms of leng

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
> "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: Arnaud> Sorry I gave an incorrect example to illustrate my question last Arnaud> night (I blame this on baby-induced sleep deprivation ;), so I'll Arnaud> have another go: Arnaud> Say I have 2, 3, 4, 100 and I want to make 406. AFAIC

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
> "cokofreedom" == cokofreedom <[EMAIL PROTECTED]> writes: cokofreedom> Terry, your technique is efficient and pretty readable! All cokofreedom> that could be added now is a way to output the data in a more cokofreedom> user-friendly print. Yes, and a fix for the bug Arnaud just pointed out

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Arnaud Delobelle
On Jan 21, 9:12 am, Terry Jones <[EMAIL PROTECTED]> wrote: [...] > Hi Arnaud. Hi Terry [...] > WRT to the missing solution, note that my code only allowed multiplication > by 1 if it was the last thing done. That was because you can multiply by 1 > at any time, and I didn't want to see those triv

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread cokofreedom
On Jan 21, 11:29 am, Terry Jones <[EMAIL PROTECTED]> wrote: > > "dg" == dg google groups <[EMAIL PROTECTED]> writes: > > dg> It's great how many different sorts of solutions (or almost solutions) > dg> this puzzle has generated. Speedwise, for reference my solution posted > dg> above takes abou

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Arnaud Delobelle
On Jan 21, 9:01 am, [EMAIL PROTECTED] wrote: > Hi all, > > It's great how many different sorts of solutions (or almost solutions) > this puzzle has generated. Speedwise, for reference my solution posted > above takes about 40 seconds on my 1.8GHz laptop, and the less elegant > version (on my webpag

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
> "dg" == dg google groups <[EMAIL PROTECTED]> writes: dg> It's great how many different sorts of solutions (or almost solutions) dg> this puzzle has generated. Speedwise, for reference my solution posted dg> above takes about 40 seconds on my 1.8GHz laptop, and the less elegant dg> version (o

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Steven D'Aprano
On Mon, 21 Jan 2008 01:15:50 -0800, dg.google.groups wrote: > Decided I may as well post my other solution while I'm at it. The neat > trick here is redefining the add, mul, etc. functions so that they raise > exceptions for example if x>y then add(x,y) raises an exception which is > handled by th

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread dg . google . groups
Decided I may as well post my other solution while I'm at it. The neat trick here is redefining the add, mul, etc. functions so that they raise exceptions for example if x>y then add(x,y) raises an exception which is handled by the search algorithm to mean don't continue that computation - this sto

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
> "Paul" == Paul Rubin <"http://phr.cx"@NOSPAM.invalid> writes: Hi Paul Paul> Here's my latest, which I think is exhaustive, but it is very slow. Paul> It prints a progress message now and then just to give the user some Paul> sign of life. It should print a total of 256-8 = 248 of those Pau

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
> "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes: Arnaud> In countdown you are not required to use all numbers to reach the Arnaud> target. This means you are missing solutions, e.g. (1, 3, 6, Arnaud> 'mul', 'add', 7 , 'add', 9, 'mul') Hi Arnaud. Thanks, I didn't know that. The fix

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread dg . google . groups
Hi all, It's great how many different sorts of solutions (or almost solutions) this puzzle has generated. Speedwise, for reference my solution posted above takes about 40 seconds on my 1.8GHz laptop, and the less elegant version (on my webpage linked to in the original post) takes about 15 seconds

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Paul Rubin
Arnaud Delobelle <[EMAIL PROTECTED]> writes: > Update: 2, 4, 5, 8, 9, 25 can reach any target between 100 and 999. Are you sure? What expression do you get for target = 758? -- http://mail.python.org/mailman/listinfo/python-list

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Paul Rubin
Arnaud Delobelle <[EMAIL PROTECTED]> writes: > After a quick glance at your code it seems to me that you can only > have solutions of the type: > (num, num, op, num, op, num, op, num, op, num, op) > this omits many possible solutions (see the one above). Here's my latest, which I think is

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Arnaud Delobelle
On Jan 21, 3:19 am, Terry Jones <[EMAIL PROTECTED]> wrote: > Here's a solution that doesn't use any copying of lists in for recursion. > It also eliminates a bunch of trivially equivalent solutions. The countdown > function is 37 lines of non-comment code.  Sample (RPN) output below. > > Terry [sn

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Paul Rubin
Terry Jones <[EMAIL PROTECTED]> writes: > Here's a solution that doesn't use any copying of lists in for recursion. > It also eliminates a bunch of trivially equivalent solutions. The countdown > function is 37 lines of non-comment code. Sample (RPN) output below. Nice, I realized after I posted

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Terry Jones
Here's a solution that doesn't use any copying of lists in for recursion. It also eliminates a bunch of trivially equivalent solutions. The countdown function is 37 lines of non-comment code. Sample (RPN) output below. Terry from operator import * def countdown(target, nums, numsAvail, value,

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Arnaud Delobelle
On Jan 21, 1:07 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Jan 20, 5:41 pm, [EMAIL PROTECTED] wrote: > > > Ever since I learnt to program I've always loved writing solvers for > > the Countdown numbers game problem in different languages > > Ok so here's a challenge I just thought of: > >

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Arnaud Delobelle
On Jan 20, 5:41 pm, [EMAIL PROTECTED] wrote: > Ever since I learnt to program I've always loved writing solvers for > the Countdown numbers game problem in different languages Ok so here's a challenge I just thought of: What is (or are) the set of 6 starting numbers which are such that the smalle

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Unfortunately I realise I stated the problem imprecisely. You're only > allowed to use each number once (otherwise there's a trivial solution > for every problem, i.e. x/x + x/x + x/x + ... + x/x repeated y times > for target y given any source number x). Trying your pro

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Mel
[EMAIL PROTECTED] wrote: > Ever since I learnt to program I've always loved writing solvers for > the Countdown numbers game problem in different languages, and so now > I'm wondering what the most elegant solution in Python is. > > If you don't know the game, it's simple: you're given six randoml

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Arnaud Delobelle
On Jan 20, 5:41 pm, [EMAIL PROTECTED] wrote: > Ever since I learnt to program I've always loved writing solvers for > the Countdown numbers game problem in different languages, and so now > I'm wondering what the most elegant solution in Python is. > > If you don't know the game, it's simple: you'r

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Unfortunately I realise I stated the problem imprecisely. You're only > allowed to use each number once (otherwise there's a trivial solution > for every problem, i.e. x/x + x/x + x/x + ... + x/x repeated y times > for target y given any source number x). Trying your pro

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread dg . google . groups
Hi Marek, That's a really nice solution (and ultrafast). Unfortunately I realise I stated the problem imprecisely. You're only allowed to use each number once (otherwise there's a trivial solution for every problem, i.e. x/x + x/x + x/x + ... + x/x repeated y times for target y given any source n

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Gabriel Genellina
En Sun, 20 Jan 2008 18:06:57 -0200, <[EMAIL PROTECTED]> escribi�: > Nice challenge! I came up with something like this: A nice solution too! -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread marek . rocki
Nice challenge! I came up with something like this: def find_repr(target, numbers): org_reprs = dict((number, str(number)) for number in numbers) curr_reprs = org_reprs while target not in curr_reprs: old_reprs, curr_reprs = curr_reprs, {} fo

Just for fun: Countdown numbers game solver

2008-01-20 Thread dg . google . groups
Ever since I learnt to program I've always loved writing solvers for the Countdown numbers game problem in different languages, and so now I'm wondering what the most elegant solution in Python is. If you don't know the game, it's simple: you're given six randomly chosen positive integers, and a t