CLEAR Y # loop times
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
INCREASE Y
PRINT X
REPEAT Y TIMES
(
CLEAR A # will be used as a temp variable for decrease
CLEAR B # will be x-1
REPEAT X TIMES
(
CLEAR B
REPEAT A TIMES
(
INCREASE B
)
INCREASE A
)
CLEAR A # temp decrease
CLEAR C # will be X-1-1
CLEAR D
INCREASE D
INCREASE D # amount of decreases for C (2)
CLEAR E # temp variable to store the first x-1
REPEAT X TIMES
(
INCREASE E
)
REPEAT D TIMES # repeat 2 times
(
CLEAR A # clearing temp variable
REPEAT E TIMES
(
CLEAR C
REPEAT A TIMES
(
INCREASE C
)
INCREASE A
)
CLEAR E # clearing E
REPEAT C TIMES
(
INCREASE E # making E x-1
)
)
# now B is x-1 and C is x-2
# lets decrease B C times:
CLEAR A # temp decrease
CLEAR D
REPEAT C TIMES
(
INCREASE D # amount of decreases for B
)
CLEAR E # temp variable to store decreased value
REPEAT B TIMES
(
INCREASE E
)
REPEAT D TIMES # repeat D times
(
CLEAR A # clearing temp variable
REPEAT E TIMES
(
CLEAR B
REPEAT A TIMES
(
INCREASE B
)
INCREASE A
)
CLEAR E # clearing E
REPEAT B TIMES
(
INCREASE E # making E x-1
)
)
# now B is 0 if X = 1 and in other cases its 1
REPEAT B TIMES
(
# now lets put the current number through alogrithm
# since it was not 1
# PARILLINEN CHECK:
CLEAR A # A = X before modification
CLEAR B # temp variable
REPEAT X TIMES
(
INCREASE A # Set a to X
INCREASE B # set B to X as well
)
# Sitten käytetään jakofunktiota A:han ja tallennetaan vastaus C:hen
CLEAR C # temp
CLEAR D # temp
REPEAT A TIMES
(
REPEAT B TIMES
(
INCREASE C # increase C first with B, then B-2, then B-4 etc
)
# decrease B by 1:
CLEAR T # temp variable
REPEAT B TIMES
(
CLEAR B
REPEAT T TIMES
(
INCREASE B
)
INCREASE T
)
REPEAT B TIMES
(
INCREASE D # increase D first with B-1, then B-3, then B-5 etc
)
# decrease B by 1:
CLEAR T # temp variable
REPEAT B TIMES
(
CLEAR B
REPEAT T TIMES
(
INCREASE B
)
INCREASE T
)
)
# then lets decrease C by D to get X divided by 2
CLEAR E # this will be the divided number
CLEAR T # temp variable
REPEAT C TIMES
(
INCREASE E # set E to C so we can reduce it by D
)
REPEAT D TIMES # reduce 1 D times
(
CLEAR A # clearing temp variable
REPEAT E TIMES # repeat always reduced amount of times
(
CLEAR T
REPEAT A TIMES
(
INCREASE T
)
INCREASE A
)
CLEAR E # clearing E
REPEAT T TIMES
(
INCREASE E # making E E-1
)
)
# Nyt kun käsittelynumero on jaettu ja laitettu variableen E
# voidaan tehdä uusi variable joka on E - 1:
CLEAR A # will be used as a temp variable for decrease
CLEAR B # will be x-1
REPEAT E TIMES
(
CLEAR B
REPEAT A TIMES
(
INCREASE B
)
INCREASE A
)
# now B is E-1
# now lets decrease B and E from X and store vastaus in V
CLEAR V # will be the vastaus
REPEAT X TIMES
(
INCREASE V # Increase V to X in case it will be reduced by 0
# and the loop wont add anything to V
)
CLEAR D # will be amount of decreases
REPEAT B TIMES
(
INCREASE D # amount of decreases for V
)
CLEAR T # temp variable to store decreased value
REPEAT X TIMES
(
INCREASE T # T should be the starting amount
)
REPEAT D TIMES # amount of decreases
(
CLEAR A # clearing temp variable
REPEAT T TIMES
(
CLEAR V
REPEAT A TIMES
(
INCREASE V
)
INCREASE A
)
CLEAR T # clearing T
REPEAT V TIMES
(
INCREASE T # making T V-1
)
)
# now we have done X - B and stored to V. Lets do V - E to complete.
CLEAR D # will be amount of decreases
REPEAT E TIMES
(
INCREASE D # amount of decreases for V
)
CLEAR T # temp variable to store decreased value
REPEAT V TIMES
(
INCREASE T # T should be the starting amount
)
REPEAT D TIMES # amount of decreases
(
CLEAR A # clearing temp variable
REPEAT T TIMES
(
CLEAR V
REPEAT A TIMES
(
INCREASE V
)
INCREASE A
)
CLEAR T # clearing T
REPEAT V TIMES
(
INCREASE T # making T V-1
)
)
# now V is 1 if its parillinen and 0 if its pariton!
REPEAT V TIMES # PARILLISEN LUVUN KÄSITTELY
(
# this happens only if X is parillinen
# tehdään jakolasku X / 2
# JAKOLASKU ALKAA
# Sitten käytetään jakofunktiota A:han ja tallennetaan vastaus C:hen
CLEAR A # A = X before modification
CLEAR B # temp variable
REPEAT X TIMES
(
INCREASE A # Set a to X
INCREASE B # set B to X as well
)
CLEAR C # temp
CLEAR D # temp
REPEAT X TIMES
(
REPEAT A TIMES
(
INCREASE C # increase C first with B, then B-2, then B-4 etc
)
# decrease A by 1:
CLEAR T # temp variable
REPEAT A TIMES
(
CLEAR A
REPEAT T TIMES
(
INCREASE A
)
INCREASE T
)
REPEAT A TIMES
(
INCREASE D # increase D first with B-1, then B-3, then B-5 etc
)
# decrease A by 1:
CLEAR T # temp variable
REPEAT A TIMES
(
CLEAR A
REPEAT T TIMES
(
INCREASE A
)
INCREASE T
)
)
# then lets decrease C by D to get X divided by 2
CLEAR E # this will be the divided number
CLEAR T # temp variable
REPEAT C TIMES
(
INCREASE E # set E to C so we can reduce it by D
)
REPEAT D TIMES # reduce D times
(
CLEAR A # clearing temp variable
REPEAT E TIMES # repeat always reduced amount of times
(
CLEAR T
REPEAT A TIMES
(
INCREASE T
)
INCREASE A
)
CLEAR E # clearing E
REPEAT T TIMES
(
INCREASE E # making E E-1
)
)
# JAKOLASKU LOPPUU ja lasku tallennettu E:hen
CLEAR M
REPEAT E TIMES
(
INCREASE M # Tallennetaan X / 2 M:ään
)
)
# Now lets check if the luku X is pariton:
# PARITTOMAN LUVUN CHECK
# Parittoman luvun check on täysin sama kuin parillisen
# mutta tehdään vain sama funktio X+1 :dellä
# Eli katsotaan onko X+1 parillinen :D
# PARILLINEN CHECK:
CLEAR A # A = X before modification
CLEAR B # temp variable
CLEAR P # This will be X+1 due to this being pariton check
REPEAT X TIMES
(
INCREASE P
)
INCREASE P # Nyt P on X+1
REPEAT P TIMES
(
INCREASE A # Set a to P
INCREASE B # set B to P as well
)
# Sitten käytetään jakofunktiota A:han ja tallennetaan vastaus C:hen
CLEAR C # temp
CLEAR D # temp
REPEAT A TIMES
(
REPEAT B TIMES
(
INCREASE C # increase C first with B, then B-2, then B-4 etc
)
# decrease B by 1:
CLEAR T # temp variable
REPEAT B TIMES
(
CLEAR B
REPEAT T TIMES
(
INCREASE B
)
INCREASE T
)
REPEAT B TIMES
(
INCREASE D # increase D first with B-1, then B-3, then B-5 etc
)
# decrease B by 1:
CLEAR T # temp variable
REPEAT B TIMES
(
CLEAR B
REPEAT T TIMES
(
INCREASE B
)
INCREASE T
)
)
# then lets decrease C by D to get X divided by 2
CLEAR E # this will be the divided number
CLEAR T # temp variable
REPEAT C TIMES
(
INCREASE E # set E to C so we can reduce it by D
)
REPEAT D TIMES # reduce 1 D times
(
CLEAR A # clearing temp variable
REPEAT E TIMES # repeat always reduced amount of times
(
CLEAR T
REPEAT A TIMES
(
INCREASE T
)
INCREASE A
)
CLEAR E # clearing E
REPEAT T TIMES
(
INCREASE E # making E E-1
)
)
# Nyt kun käsittelynumero on jaettu ja laitettu variableen E
# voidaan tehdä uusi variable joka on E - 1:
CLEAR A # will be used as a temp variable for decrease
CLEAR B # will be x-1
REPEAT E TIMES
(
CLEAR B
REPEAT A TIMES
(
INCREASE B
)
INCREASE A
)
# now B is E-1
# now lets decrease B and E from X and store vastaus in V
CLEAR V # will be the vastaus
REPEAT P TIMES
(
INCREASE V # Increase V to X in case it will be reduced by 0
# and the loop wont add anything to V
)
CLEAR D # will be amount of decreases
REPEAT B TIMES
(
INCREASE D # amount of decreases for V
)
CLEAR T # temp variable to store decreased value
REPEAT P TIMES
(
INCREASE T # T should be the starting amount
)
REPEAT D TIMES # amount of decreases
(
CLEAR A # clearing temp variable
REPEAT T TIMES
(
CLEAR V
REPEAT A TIMES
(
INCREASE V
)
INCREASE A
)
CLEAR T # clearing T
REPEAT V TIMES
(
INCREASE T # making T V-1
)
)
# now we have done X - B and stored to V. Lets do V - E to complete.
CLEAR D # will be amount of decreases
REPEAT E TIMES
(
INCREASE D # amount of decreases for V
)
CLEAR T # temp variable to store decreased value
REPEAT V TIMES
(
INCREASE T # T should be the starting amount
)
REPEAT D TIMES # amount of decreases
(
CLEAR A # clearing temp variable
REPEAT T TIMES
(
CLEAR V
REPEAT A TIMES
(
INCREASE V
)
INCREASE A
)
CLEAR T # clearing T
REPEAT V TIMES
(
INCREASE T # making T V-1
)
)
# now V is 1 if X is pariton and 0 if X is parillinen!
REPEAT V TIMES # PARITTOMAN LUVUN KÄSITTELY
(
# eli kerro kolmella ja lisää yksi
CLEAR T # temp to be X
REPEAT X TIMES
(
INCREASE T # set T to X
)
CLEAR M # clearataan M jotta se voidaan asettaa
CLEAR K # temp variable to be 3
INCREASE K
INCREASE K
INCREASE K # set K to 3
REPEAT T TIMES
(
REPEAT K TIMES
(
INCREASE M
)
)
INCREASE M # last increase
)
# viimeisenä asetetaan X M:ään
CLEAR X
REPEAT M TIMES
(
INCREASE X
)
PRINT X #print
)
)