Post Reply 
HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares
04-15-2018, 11:42 AM (This post was last modified: 04-15-2018 11:44 AM by Thomas Ritschel.)
Post: #9
RE: HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares
Here is an improved version of my earlier program.
It is still using the idea from Joe's \Gs routine, but omits the even divisors:

Code:
%%HP: T(3)A(R)F(.);
@ Jacobi, by Thomas Ritschel
@ number of representations
@ Jacobi's four-square theorem
@ idea based on Joe Horn's \Gs
\<< EVAL DUP 2 MOD 1 == 8 24 IFTE SWAP FACTORS DUP SIZE
  IF 0 >
  THEN R\->I OBJ\-> PICK3
    IF 2 ==
    THEN UNROT DROP2 2. -
    END 1 SWAP 1. SWAP 2. / DUP
    IF 0 >
    THEN
      START PICK3 ROT 1 + ^ 1 - ROT 1 - / *
      NEXT *
    ELSE DROP2 DROP
    END
  ELSE DROP
  END
\>>

Now it properly treats trivial inputs like 1 or 4 and works for algebraic inputs (like '720^20') as well.

The runtime has also improved:

0.66 sec for 720^20 entered as 1401683395356260729391818575873415577600000000000000000000
0.69 sec for 720^20 entered as '720^20'
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares - Thomas Ritschel - 04-15-2018 11:42 AM



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