bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-apl] Best way to solve my daughter's maths problem


From: Elias Mårtenson
Subject: [Bug-apl] Best way to solve my daughter's maths problem
Date: Tue, 24 Jan 2017 23:47:10 +0800

My daughter had this maths problem, and quote it from memory:

Given five 4's, separated by the mathematical functions +, -, × and ÷ form the number 7. The problem also allowed her to use parentheses.

I decided to write an APL _expression_ to solve this, and this is what I came up with:

    d ← {⍵÷⍺}
    (↑¨ 7 = ⍎¨ v) / v ← {"4 " , ↑,/ {{⍵," 4 "}¨⍵} ⍵}¨ ,↑∘.,/4 ⍴ ⊂'+-×d'

Now, this program finds two solutions, which is good enough for me. However, my program doesn't find solutions that require parentheses.

Problem 1: Can anyone simplify my program?
Problem 2: Can anyone come up with a solution that also checks for parentheses?

Regards,
Elias

reply via email to

[Prev in Thread] Current Thread [Next in Thread]