Post Reply 
challenge for programmable calculators
12-24-2013, 06:02 PM
Post: #34
RE: challenge for programmable calculators
(12-24-2013 04:52 PM)Gerson W. Barbosa Wrote:  
Code:
%%HP: T(3)A(D)F(.);
\<< 1. 7.
  FOR a 1. 9.
    FOR b a SQ b * a b SQ * + 1. - NEG DUP SQ a b * 4. * a 100. * b 10. * + * + \v/ + a b * 2. * / DUP FP NOT NOT { DROP } { DUP 10. < { a 100. * b 10. * + + } { DROP } IFTE } IFTE
    NEXT
  NEXT
\>>
TEVAL

3: 135.
2: 144.
1: s:2.2434 (Real hp 50g)

We can safely reduce the number of trials from 63 to 42:

Code:
%%HP: T(3)A(D)F(.);
\<< 1. 7.
  FOR a a 9.
    FOR b a SQ b * a b SQ * + 1. - NEG DUP SQ a b * 4. * a 100. * b 10. * + * + \v/ + a b * 2. * / DUP FP NOT NOT { DROP } { DUP 10. < { a 100. * b 10. * + + } { DROP } IFTE } IFTE
    NEXT
  NEXT
\>>
TEVAL

3: 135.
2: 144.
1: s:1.5228 (Real hp 50g)

This is now equivalent to reducing the number of trials from 729 down to 77 or 78 when compared to the plain brute-force solution, even considering the greater complexity of the innermost loop, at least for the real hp 50g.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: challenge for programmable calculators - Gerson W. Barbosa - 12-24-2013 06:02 PM
Proof using number theory - cruff - 12-24-2013, 05:43 PM
RE: challenge for programmable calculators - radwilliams - 12-24-2013, 05:57 PM



User(s) browsing this thread: 1 Guest(s)