Post Reply 
HHC 2015 RPN programming Contest is now open
10-03-2015, 03:54 PM (This post was last modified: 10-03-2015 04:16 PM by Egan Ford.)
Post: #86
RE: HHC 2015 RPN programming Contest is now open
(10-03-2015 01:19 AM)Allen Wrote:  To that end \(6x+1\) makes for an even shorter program. ( by checking 8645, 38285, and 108965). (maps to 7,13,19,5^2,31,37).

After I posted my prime-based solution I tried to create other prime and co-prime series, but it didn't get me close to 42 bytes. Dieter's optimization + your series still puts it 7 bytes short:

49 bytes (was 53 with x^2-x+11):

Code:

  1 LBL RR
  2 5           ; loop over 5 dice
  3 1
  4 LBL 00
  5 RCL IND Y   ; map to 6x+1
  6 6
  7 *
  8 1
  9 +
 10 *           ; multiply co-primes
 11 DSE Y
 12 GTO 00
 13 ENTER
 14 ENTER
 15 ENTER
 16 8645        ; check for 1,2,3,4
 17 MOD
 18 X<>Y
 19 38285       ; check for 2,3,4,5
 20 MOD
 21 *
 22 X<>Y
 23 108965      ; check for 3,4,5,6
 24 MOD
 25 *
 26 END

We can shave off a byte by only checking for 1,2,5,6 pairs, then checking 3,4:

48 bytes:

Code:

  1 LBL RR
  2 5           ; loop over 5 dice
  3 1
  4 LBL 00
  5 RCL IND Y   ; map to 6x+1
  6 6
  7 *
  8 1
  9 +
 10 *           ; multiply co-primes
 11 DSE Y
 12 GTO 00
 13 ENTER
 14 ENTER
 15 ENTER
 16 91          ; check for 1,2
 17 MOD
 18 X<>Y
 19 403         ; check for 2,5
 20 MOD
 21 *
 22 X<>Y
 23 1147        ; check for 5,6
 24 MOD
 25 *           ; if 0, then possible small straight
 26 X<>Y        
 27 95          ; check for 3,4
 28 MOD
 29 +           ; + not *
 30 END

Next possible optimization would be to pre compute series, store checks in registers, loop the checks. That's 3 loops and possibly a GSB.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HHC 2015 RPN programming Contest is now open - Egan Ford - 10-03-2015 03:54 PM



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