Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Last active January 16, 2020 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuro-sys/375e6dc51a3099c99b9ef73fd73f8d96 to your computer and use it in GitHub Desktop.
Save neuro-sys/375e6dc51a3099c99b9ef73fd73f8d96 to your computer and use it in GitHub Desktop.
org &8100
result: ds 1
org &8000
jp start
buf: ds 7 ; Work area to sum rolls
db -1
input: db 2, 3, 5, 5, 6 ; Input yahtzee rolls
db -1
start: ld hl, buf
ld a, (hl)
ld de, buf+1
ld bc, 7
ldir ; Cleaar buffer area
call solve
exx
ld a, b
ld (result), a ; Store result from 'b&
exx
ret
; returns largest in 'b
solve: ld hl, input
exx
ld b, 0 ; max_sum
exx
loop: ld de, buf
ld a, (hl) ; a = *input
cp -1 ; if end, exit
ret z
ex de, hl
ld c, a
ld b, 0
add hl, bc
ld a, (hl) ; a = *(buf + c)
add a, c
exx
cp b ; a > max_sum
jr c, solve2
ld b, a ; max_sum = a
solve2: exx
ld (hl), a
ex de, hl
inc hl
jr loop
10 MEMORY &7FFF
20 DATA 2,3,5,5,6,-1
30 GOSUB 1000
40 DATA 1,1,1,1,3,-1
50 GOSUB 1000
60 DATA 1,1,1,3,3,-1
70 GOSUB 1000
80 DATA 1,2,3,4,5,-1
90 GOSUB 1000
100 DATA 6,6,6,6,6,-1
110 GOSUB 1000
120 END
1000 REM solve and print
1010 GOSUB 2000
1020 CALL &8000
1030 a%=PEEK(&8100)
1040 PRINT a%
1050 RETURN
2000 REM load data
2010 buf%=&800B
2020 READ a%
2030 WHILE a%<>-1
2040 PRINT a%;
2050 POKE buf%,a%
2060 buf%=buf%+1
2070 READ a%
2080 WEND
2090 PRINT "=>";
2100 RETURN
@neuro-sys
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment