Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread Dan Goodman
MRAB wrote: Here's my solution (I haven't bothered with making it efficient, BTW): import operator def solve(n): best_len = n best_expr = "" for x in range(1, n - 2): for y in range(x, n): for op, name in operator_list: # Does this pair with this

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread geremy condra
Use 1 and 2 and treat them as equivalent to boolean true and false. -- http://mail.python.org/mailman/listinfo/python-list

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread MRAB
Trip Technician wrote: anyone interested in looking at the following problem. we are trying to express numbers as minimal expressions using only the digits one two and three, with conventional arithmetic. so for instance 33 = 2^(3+2)+1 = 3^3+(3*2) are both minimal, using 4 digits but 33 = ((3

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread Rhodri James
On Thu, 26 Feb 2009 23:10:20 -, Jonathan Gardner wrote: [snip] For each iteration, you take each surviving walker and spawn a new walker that takes a step in each possible direction. Then you check if any of those walkers found the value you are looking for. If so, you've found the answe

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread Jonathan Gardner
On Feb 20, 6:31 am, Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both min

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-23 Thread Sambit Samal
test On Sat, Feb 21, 2009 at 3:31 AM, Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Dan Goodman
This sounds kind of similar to a problem I posted to this list last year, you might find that thread gives you some ideas: http://mail.python.org/pipermail/python-list/2008-January/474071.html Dan -- http://mail.python.org/mailman/listinfo/python-list

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread andrew cooke
from subsequent posts i think you were looking for something "smarter" than my streams, but i was interested in the idea, so i wrote an implementation. hope this is ok - if you don't want to see a worked solution, read no further... i have been using generators a lot recently; now that i understa

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Tim Wintle
On Fri, 2009-02-20 at 16:38 +, Nigel Rantor wrote: > Luke Dunn wrote: That was my initial thought when I read this too - but I'm not certain that is guaranteed to find a solution (i.e. a solution that's optimal). I'd welcome a proof that it will though, a few minutes thought hasn't found a

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Nigel Rantor
Trip Technician wrote: yes n^n^n would be fine. agree it is connected to factorisation. building a tree of possible expressions is my next angle. I think building trees of the possible expressions as a couple of other people have suggested is simply a more structured way of doing what you're

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Nigel Rantor
Luke Dunn wrote: yes power towers are allowed right, okay, without coding it here's my thought. factorise the numbers you have but only allowing primes that exist in your digit set. then take that factorisation and turn any repeated runs of digits multiplied by themselves into power-towers

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Trip Technician
On 20 Feb, 15:39, Nigel Rantor wrote: > Trip Technician wrote: > > anyone interested in looking at the following problem. > > if you can give me a good reason why this is not homework I'd love to > hear it...I just don't see how this is a real problem. > > > > > > > we are trying to express number

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Trip Technician
On 20 Feb, 16:02, Paul Rubin wrote: > Trip Technician writes: > > I have a dim intuition that it could be done with a very clever bit of > > recursion, but the exact form so far eludes me. > > This sounds a little like a homework assignment, or maybe a challenge > yo

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread andrew cooke
this is a neat problem. here is what i would do: use generators that extend an input. a stream approach. the initial input would be the numbers themselves. [('1', 1),('2', 2),('3', 3)] those are (expression, value) pairs then an initial attempt at the next function would be to extend that li

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Nigel Rantor
Trip Technician wrote: anyone interested in looking at the following problem. if you can give me a good reason why this is not homework I'd love to hear it...I just don't see how this is a real problem. we are trying to express numbers as minimal expressions using only the digits one two an

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Luke Dunn
yes power towers are allowed exponentiation, multiplication, division, addition and subtraction. Brackets when necessary but length is sorted on number of digits not number of operators plus digits. I always try my homework myself first. in 38 years of life I've learned only to do what i want, if

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Luke Dunn
I am teaching myself coding. No university or school, so i guess its homework if you like. i am interested in algorithms generally, after doing some of Project Euler. Of course my own learning process is best served by just getting on with it but sometimes you will do that while other times you mig

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Vincent Davis
Having looked long at this how does the prime factorization play into this. I would consider an approach similar to factoring a number. Of course the issue with prime factoring is your ned to know the primes. I assume this would be a similar problem you may need to know the solutions to the factors

code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Trip Technician
anyone interested in looking at the following problem. we are trying to express numbers as minimal expressions using only the digits one two and three, with conventional arithmetic. so for instance 33 = 2^(3+2)+1 = 3^3+(3*2) are both minimal, using 4 digits but 33 = ((3+2)*2+1)*3 using 5 is no