Post Reply 
HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares
04-15-2018, 06:54 PM (This post was last modified: 04-15-2018 06:55 PM by Thomas Ritschel.)
Post: #14
RE: HP 50g Programming Competition: How Many Partitions of an Integer in 4 Squares
(04-15-2018 04:38 PM)Gerald H Wrote:  Your programme returns

?

for input

1.

Well, by "any natural number" (quoting your initial post) I assumed positive integers (e.g. without a decimal dot).

By putting a R\->I in front of my program, it also works for numbers like 1. or 2.

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
\<< R\->I 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 06:54 PM



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