Post Reply 
Challenge: sum of squares. Let's break 299
01-21-2018, 10:44 PM (This post was last modified: 01-21-2018 11:32 PM by Gilles59.)
Post: #21
RE: Challenge: sum of squares. Let's break 299
NewRpl (recursive (and naive) approach) :

Code:
Bk299 :
«
  → L a 
  « 1 L SIZE FOR 'n' 
      L n GET 'b' LSTO 
      IF a b + √ FP NOT a NOT OR THEN
       L 1 n 1 - SUB L n 1 + 299 SUB ADD 
       IF DUP SIZE THEN
        1 CF 
        b Bk299 
        IF 1 FS? THEN Sol b ADD 'Sol' STO EXIT END
       ELSE
        DROP Sol b ADD 'Sol' STO 1 SF 
       END
      END
    NEXT
  »
»

Search :
«
  →  lg 
  « 
    {}  'Sol' STO 
    1 Lg FOR 'n' n NEXT
    Lg →LIST 
    0 Bk299 
    Sol 
  »
»

Example :

15 Search
{ 9 7 2 14 11 5 4 12 13 3 6 10 15 1 8 }

Simulator : 0,012sec
Real Calc : (I 've a problem with the USB connexion... will try tomorrow

16 -> { 16 9 7 2 14 11 5 4 12 13 3 6 10 15 1 8 }

25 -> { 18 7 9 16 20 5 4 21 15 10 6 19 17 8 1 3 22 14 11 25 24 12 13 23 2 }

Simulator : 0.282 s
Real calc : ?

Could be easily improved by changing the square root with a table of of all the square numbers and a POS command... But i ve to go at bed now ;D And for a 299 search we need another way...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Challenge: sum of squares. Let's break 299 - Gilles59 - 01-21-2018 10:44 PM



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