Post Reply 
HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares
04-15-2018, 03:34 PM (This post was last modified: 04-15-2018 03:35 PM by Thomas Ritschel.)
Post: #12
RE: HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares
(04-15-2018 03:09 PM)Gerald H Wrote:  Programme returns wrong values for input 0 & 1.

For input 1 it returns 8, which should be correct (= 2*4 possibilities).
But you're right, for 0 it should return 1 (not 8).

The following version of the program also treats 0 correctly:

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
\<< DUP
  IF 0 ==
  THEN DROP 1
  ELSE FACTORS DUP SIZE
    IF 0 >
    THEN R\->I OBJ\-> 1 SWAP 1. SWAP 2. /
      START PICK3 DUP
        IF 2 ==
        THEN ROT DROP 1 UNROT
        END ROT 1 + ^ 1 - ROT 1 - / *
      NEXT
    ELSE DROP 1
    END 8 *
  END
\>>
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 03:34 PM



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