• The stupid quiz question:

    * Shadwhawk/#ppg takes a break for now and goes back to his take-home quiz...you know, I don't think I've ever had to do 'insert
              parentheses in the expression to get the indicated result' problems before.
    <sig11> heh
    <Shadwhawk> I need to get '10 - 2 - 6 + 4 - 8' to equal 10.
    <Quickbeam> (10 - 2) - (6 + 4) -8
    <Znoop> That's -10.
    <donut> That's a stupid quiz.
    <Znoop> That's also true.
    <Shadwhawk> A nastier one is 3 * 5 - 3 + 2 + 8 * 2 - 6 / 4 ^ 2
    <Znoop> 10 - (2-6) + (4-8)
    <Shadwhawk> Oh, that one results to 6.
    
  • The prog:

    parenthesizer.py
  • The answers (int division):

    >>> parenthesizer.foobar("3 * 5 - 3 + 2 + 8 * 2 - 6 / 4 ^ 2", 6)
    3*5-3+2+8*((2-6)/4^2) = 6
    3*5-3+(2+8*((2-6)/4^2)) = 6
    3*5-((((3+2)+8*2)-6)/4)^2 = 6
    3*5-(((3+2)+(8*2-6))/4)^2 = 6
    3*5-((3+2)+((8*2-6)/4)^2) = 6
    3*5-((3+2)+(8*(2-6)/4))^2 = 6
    3*5-((3+2)+(8*((2-6)/4)))^2 = 6
    3*5-(((3+(2+8*2))-6)/4)^2 = 6
    3*5-((3+((2+8*2)-6))/4)^2 = 6
    3*5-((3+(2+(8*2-6)))/4)^2 = 6
    3*5-(3+(2+((8*2-6)/4)^2)) = 6
    3*5-(3+(2+(8*(2-6)/4)))^2 = 6
    3*5-(3+(2+(8*((2-6)/4))))^2 = 6
    3*(5-3)+2+8*(2-6)/4^2 = 6
    3*(5-3)+((2+8)*2-6)/4^2 = 6
    3*(5-3)+((2+8*2)-6)/4^2 = 6
    3*(5-3)+(2+(8*2-6))/4^2 = 6
    3*(5-3)+(2+8*(2-6)/4^2) = 6
    3*(((5-3)+2)+8*(2-6)/4^2) = 6
    3*((5-3)+((2+8)*2-6)/4^2) = 6
    3*((5-3)+((2+8*2)-6)/4^2) = 6
    3*((5-3)+(2+(8*2-6))/4^2) = 6
    3*((5-3)+(2+8*(2-6)/4^2)) = 6
    3*(5-((3+2)+8))*(2-6)/4^2 = 6
    3*((5-((3+2)+8))*(2-6))/4^2 = 6
    3*(((5-((3+2)+8))*(2-6))/4^2) = 6
    3*(5-((3+2)+8*(2-6)))/4^2 = 6
    3*((5-((3+2)+8*(2-6)))/4^2) = 6
    3*(5-((3+2)+8*(2-6)/4^2)) = 6
    3*(5-(3+(2+8)))*(2-6)/4^2 = 6
    3*((5-(3+(2+8)))*(2-6))/4^2 = 6
    3*(((5-(3+(2+8)))*(2-6))/4^2) = 6
    3*(5-(3+((2+8)*2-6)/4^2)) = 6
    3*((5-(3+(2+8)*(2-6)))/4^2) = 6
    3*(5-(3+((2+8*2)-6)/4^2)) = 6
    3*(5-(3+(2+(8*2-6))/4^2)) = 6
    3*(5-(3+(2+8*(2-6))))/4^2 = 6
    3*((5-(3+(2+8*(2-6))))/4^2) = 6
    3*(5-(3+(2+8*(2-6)/4^2))) = 6
    39 unique solutions(1103 total) out of 40320 possibilities
    
  • The answers (float division):

    3*5-((3+2)+(8*(2-6)/4))^2 = 6.0
    3*5-((3+2)+(8*((2-6)/4)))^2 = 6.0
    3*5-(3+(2+(8*(2-6)/4)))^2 = 6.0
    3*5-(3+(2+(8*((2-6)/4))))^2 = 6.0
    3*(5-3)+2+8*(2-6)/4^2 = 6.0
    3*(5-3)+2+8*((2-6)/4^2) = 6.0
    3*(5-3)+2+8*(2-(6/4)^2) = 6.0
    3*(5-3)+(2+8*(2-6)/4^2) = 6.0
    3*(5-3)+(2+8*((2-6)/4^2)) = 6.0
    3*(5-3)+(2+8*(2-(6/4)^2)) = 6.0
    3*(((5-3)+2)+8*(2-6)/4^2) = 6.0
    3*(((5-3)+2)+8*((2-6)/4^2)) = 6.0
    3*(((5-3)+2)+8*(2-(6/4)^2)) = 6.0
    3*((5-3)+(2+8*(2-6)/4^2)) = 6.0
    3*((5-3)+(2+8*((2-6)/4^2))) = 6.0
    3*((5-3)+(2+8*(2-(6/4)^2))) = 6.0
    3*((5-(3+2))+8)*(2-(6/4))^2 = 6.0
    3*(((5-(3+2))+8)*(2-(6/4))^2) = 6.0
    3*((5-(3+2))+8*(2-(6/4))^2) = 6.0
    3*(5-((3+2)+8))*(2-6)/4^2 = 6.0
    3*(5-((3+2)+8))*((2-6)/4^2) = 6.0
    3*(5-((3+2)+8))*(2-(6/4)^2) = 6.0
    3*((5-((3+2)+8))*(2-6))/4^2 = 6.0
    3*(((5-((3+2)+8))*(2-6))/4^2) = 6.0
    3*((5-((3+2)+8))*((2-6)/4^2)) = 6.0
    3*((5-((3+2)+8))*(2-(6/4)^2)) = 6.0
    3*(5-((3+2)+8*(2-6)))/4^2 = 6.0
    3*((5-((3+2)+8*(2-6)))/4^2) = 6.0
    3*(5-((3+2)+8*(2-6)/4^2)) = 6.0
    3*(5-((3+2)+8*((2-6)/4^2))) = 6.0
    3*(5-((3+2)+8*(2-(6/4)^2))) = 6.0
    3*(5-(3+(2+8)))*(2-6)/4^2 = 6.0
    3*(5-(3+(2+8)))*((2-6)/4^2) = 6.0
    3*(5-(3+(2+8)))*(2-(6/4)^2) = 6.0
    3*((5-(3+(2+8)))*(2-6))/4^2 = 6.0
    3*(((5-(3+(2+8)))*(2-6))/4^2) = 6.0
    3*((5-(3+(2+8)))*((2-6)/4^2)) = 6.0
    3*((5-(3+(2+8)))*(2-(6/4)^2)) = 6.0
    3*(5-(3+(2+8*(2-6))))/4^2 = 6.0
    3*((5-(3+(2+8*(2-6))))/4^2) = 6.0
    3*(5-(3+(2+8*(2-6)/4^2))) = 6.0
    3*(5-(3+(2+8*((2-6)/4^2)))) = 6.0
    3*(5-(3+(2+8*(2-(6/4)^2)))) = 6.0
    43 unique solutions(1194 total) out of 40320 possibilities