[Tutor] making math problems mmmm fun

Alan Gauld alan.gauld at btinternet.com
Tue Sep 11 09:37:35 CEST 2007


"max baseman" <dos.fool at gmail.com> wrote

> basically the problem is to find a bunch of ways to put 1,2,3,4,5
> into different math problems to that equal 1-25, i haven't spent to
> much time thinking about how to do this but i cant think of a way to
> do it it without writing making the program rather long

This is quite a difficult problem to program (cue someone with
a really short solution! :-)

Its similar in concept to decyphering codes, there are lots
of possible permutations but only a few are viable. There
are lots of rules too. The normal approach is to search for
inconsistencies but because its math and operators can
cancel each other out it will be hard to define consistency
rules. If you only had the 4 operators or you weren't allowed
to use parentheses it would be fairly doable but by adding
parentheses and operators like factorials and finally
juxtaposition I'm not sure I'd like to try coding it!

I suspect this might be the kind of pattern spotting problem
better suited to the human brain! Computers are best with
large quantities of data composed in finite ways, brains
are best at small data sets combined in many combinations.

Alan G.


> page from the book for the rules i will be working on this for the
> next week or so thanks for any help :)
>
>  . you may use any of the four basic arithmetic operations-
> addition, subtraction, multiplication, and division (according to 
> the
> order of operations rules). for example, 2+1x3-4 is a 1-2-3-4
> expression for the number 1.
>
> . you may use exponents. for example, 2² - 4 - 1 is a 1234 
> expression
> for the number 3
>
> . you may use radicals for EX: √4x2+1 is equal to 3 so 3+√4x2+1 is
> a 1234 expression for 6
>
> . you may use factorials for EX: 4! means 4x3x2x1 so 3+4!+1-2 is a
> 1234 expression for the number 26
>
>
> . you  may juxtapose two or more digits (that is put them next to
> each other) to form a number such as 12. for example 43-12 is a 1234
> expression for 31
>
> . you may use parentheses and brackets to change the meaning of a
> expression for example according to the rules of order of operations 
> 1
> +4x3² is a 1234 expression for 37. you can add parentheses and
> brackets to get [(1+4)x3]² which is a 1234 expression for 225
>
> . must use 1,2,3,4 exactly once
>
>
>
> thanks for the help ill post if i find anything
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list