mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +00:00
fixed primes.p8
This commit is contained in:
parent
2f1249489b
commit
588133d418
@ -4,18 +4,14 @@
|
|||||||
~ main {
|
~ main {
|
||||||
|
|
||||||
ubyte[256] sieve
|
ubyte[256] sieve
|
||||||
ubyte candidate_prime = 2
|
ubyte candidate_prime = 2 ; is increased in the loop
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
memset(sieve, 256, false) ; clear the sieve
|
memset(sieve, 256, false) ; clear the sieve, to reset starting situation on subsequent runs
|
||||||
|
|
||||||
; calculate primes
|
; calculate primes
|
||||||
|
|
||||||
; @todo fix this, it misses some primes....
|
|
||||||
|
|
||||||
|
|
||||||
c64scr.print("prime numbers up to 255:\n\n")
|
c64scr.print("prime numbers up to 255:\n\n")
|
||||||
ubyte amount
|
ubyte amount=0
|
||||||
while true {
|
while true {
|
||||||
ubyte prime = find_next_prime()
|
ubyte prime = find_next_prime()
|
||||||
if prime==0
|
if prime==0
|
||||||
@ -25,13 +21,14 @@
|
|||||||
amount++
|
amount++
|
||||||
}
|
}
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
c64scr.print("amount of primes: ")
|
c64scr.print("number of primes (expected 54): ")
|
||||||
c64scr.print_ub(amount)
|
c64scr.print_ub(amount)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub find_next_prime() -> ubyte {
|
sub find_next_prime() -> ubyte {
|
||||||
|
|
||||||
while sieve[candidate_prime] {
|
while sieve[candidate_prime] {
|
||||||
candidate_prime++
|
candidate_prime++
|
||||||
if candidate_prime==0
|
if candidate_prime==0
|
||||||
@ -40,7 +37,7 @@
|
|||||||
|
|
||||||
; found next one, mark the multiples and return it.
|
; found next one, mark the multiples and return it.
|
||||||
sieve[candidate_prime] = true
|
sieve[candidate_prime] = true
|
||||||
uword multiple = candidate_prime**2
|
uword multiple = candidate_prime
|
||||||
while multiple < len(sieve) {
|
while multiple < len(sieve) {
|
||||||
sieve[lsb(multiple)] = true
|
sieve[lsb(multiple)] = true
|
||||||
multiple += candidate_prime
|
multiple += candidate_prime
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
const ubyte startYpos = boardOffsetY - 2
|
const ubyte startYpos = boardOffsetY - 2
|
||||||
|
|
||||||
ubyte lines = 0
|
ubyte lines = 0
|
||||||
ubyte score = 0
|
uword score = 0
|
||||||
ubyte xpos = startXpos
|
ubyte xpos = startXpos
|
||||||
ubyte ypos = startYpos
|
ubyte ypos = startYpos
|
||||||
ubyte nextBlock = rnd() % 7
|
ubyte nextBlock = rnd() % 7
|
||||||
|
@ -7,7 +7,12 @@
|
|||||||
|
|
||||||
; @todo see problem in looplabelproblem.p8
|
; @todo see problem in looplabelproblem.p8
|
||||||
|
|
||||||
; @todo fix primes.p8 (it misses some primes)
|
; @todo add docs for '@zp' tag in variable datatype declarations (including forloop loopvars)
|
||||||
|
|
||||||
|
; word ww2; byte bb; ww2 = bb * 55.w ; @todo why is this compiling, but resulting in a byte?
|
||||||
|
; uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
|
||||||
|
; uword ypos=4; ypos += 5000 ; @todo fix "cannot assign word to uword"
|
||||||
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
@ -21,8 +26,10 @@
|
|||||||
bb2 = bb*55
|
bb2 = bb*55
|
||||||
ww2 = ww*55
|
ww2 = ww*55
|
||||||
|
|
||||||
ww2 = bb * 55.w ; @todo why is this resulting in a byte?
|
;uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
|
||||||
ypos += 5000 ; @todo fix "cannot assign word to uword"
|
;ypos += 5000 ; @todo fix "cannot assign word to uword"
|
||||||
|
|
||||||
|
ww2 = bb * 55.w ; @todo why is this compiling, but resulting in a byte?
|
||||||
c64scr.print_w(ww2)
|
c64scr.print_w(ww2)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
ww2 = (bb as word)*55
|
ww2 = (bb as word)*55
|
||||||
|
Loading…
Reference in New Issue
Block a user