[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-apl] Best way to solve my daughter's maths problem
From: |
enztec |
Subject: |
Re: [Bug-apl] Best way to solve my daughter's maths problem |
Date: |
Wed, 25 Jan 2017 19:23:50 -0700 |
This is the full brute force method - basically a permutation of op chars
(luckily apl has ⍎)
∇top4
op←'-+×÷'
top←op[(1 1 1 1), 1+4 4 4 4⊤⍳255]
op1←256 1⍴top[1;]
op2←256 1⍴top[2;]
op3←256 1⍴top[3;]
op4←256 1⍴top[4;]
ttop←(256 4⍴'(((4'),op1,(256 2⍴'4)'),op2,(256 2⍴'4)'),op3,(256 2⍴'4)'),op4,'4'
aa←1
a: ' ' ◊ ⍞←aa,' ',⍎ttop[aa;]
⍝ ⍎(7 = ⍎ttop[aa;])/'⍞←'' '',yes'
⍎(7 = ⍎ttop[aa;])/'⍞←'' '',ttop[aa;]'
→(256aa←aa+1)/a
∇
On Wed, 25 Jan 2017 10:38:58 +0800
Elias Mårtenson <address@hidden> wrote:
> But that's what my solution did. The problem is that that solution doesn't
> evaluate things like (4+4)×(4+4)-4
>
> Regards,
> Elias
>
> On 25 January 2017 at 09:49, <address@hidden> wrote:
>
> >
> > op ← '+-x÷'
> >
> > i meant a brute force creating a HUGE matrix '(((4 op[⍳4] 4)
> > op[⍳4] 4) op[⍳4] 4) op[⍳4] 4'
> >
> >
> >
> >
> >
> > On Wed, 25 Jan 2017 08:49:37 +0800
> > Elias Mårtenson <address@hidden> wrote:
> >
> > > Thanks, but the code I included already gives me that solution, so that
> > was
> > > never the problem.
> > >
> > > The issue here is more one of trying to come up with a good APL
> > solution. I
> > > really don't like mine, it's too verbose.
> > >
> > > Regards,
> > > Elias
> > >
> > > On 25 Jan 2017 8:46 AM, <address@hidden> wrote:
> > >
> > > > since no one has responded yet this is my best guess without pure
> > random
> > > > code testing from array of chars following your rules
> > > >
> > > > the answer is : ⍎'(((4+4)x4)-4)÷4' ;)
> > > > i think the problem is from an episode of cartalk ??
> > > >
> > > >
> > > >
> > > > On Tue, 24 Jan 2017 23:47:10 +0800
> > > > Elias Mårtenson <address@hidden> wrote:
> > > >
> > > > > 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
> > > >
> > > >
> >
> >
Re: [Bug-apl] Best way to solve my daughter's maths problem, Jay Foad, 2017/01/25