Post Reply 
HHC 2016 RPN contest is now live
09-19-2016, 05:20 AM
Post: #8
RE: HHC 2016 RPN contest is now live
My algorithm calculates the number of numbers of the required length or shorter that digit sum to the correct amount and then subtracts the number of numbers of one less than the required length -- this was the quick way to handle leading zeros and still get a direct combinatorial solution.

I didn't figure out a combinatorial solution that dealt with leading zeros properly and I suspect I'm missing something really obvious. It wasn't a great weekend for me Sad

Code:
    LBL B
01:        [cplx]STO J
02:        DEC Y
03:        XEQ a
04:        [cplx]x[<>] J
05:        XEQ a
06:        RCL- J
07:        RTN

08:    a::    [cplx]STO 00
09:        # 010
10:        /
11:        IP
12:        MIN
13:        0
14:        x[<>] Y
15:        [Sigma] 00
16:        RTN

17:        LBL 00
18:        (-1)[^x]
19:        RCL 01
20:        RCL Z
21:        COMB
22:        *
23:        RCL 00
24:        RCL+ 01
25:        # 010
26:        RCL* T
27:        -
28:        DEC X
29:        RCL 01
30:        DEC X
31:        COMB
32:        *
    END

The END doesn't count (I hope), the initial LBL B can be omitted. Using the assembler, we can get relative subroutine calls which saves a step. Without this add LBL 01 between steps 7 and 8 and change the two BSR a to XEQ 01 and add one step. It uses four registers.

I suspect this can be further optimised, I really didn't spend a lot of time on this.


The program doesn't deal with out of range inputs since the clarification that they weren't allowed. It should scale up to larger input values too.


Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HHC 2016 RPN contest is now live - Gene - 09-17-2016, 01:36 PM
RE: HHC 2016 RPN contest is now live - Paul Dale - 09-19-2016 05:20 AM



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