Code archives/Algorithms/Factor Calculator

This code has been declared by its author to be Public Domain code.

Download source code

Factor Calculator by schilcote
(Posted 18 years ago)
This function calculates the factors of any number you pass to it. It then stores the numbers in a memory bank (I think, I've had it so long I've forgotten how to use it) whick you peekint (is that in B+?) or equivalent to retrive.
Global FCBnk
Function factor (Num)
DebugLog"Factor calculating function called"
FCBnk=CreateBank (1024)
Fact2=1
Repeat
Rep=Rep+1
Fact=Fact+1
;Detect need for change in second number
If Fact=num Then
Fact2=Fact2+1
Fact=1
EndIf
DebugLog "Checking For Factor, "+Fact+" * "+Fact2
;Detect factor
Test=Fact*Fact2
If Test=Num Then 
PokeInt FCBnk,Ofst,Fact
DebugLog "Factor Calculated,"+Fact
ofst=ofst+3
EndIf
Until (Test=Num And Fact=1)
DebugLog"Factor of 1 reached, end computation."
End Function

Comments

Dabhand
(Posted 18 years ago)
Nice... I'll give this 10/10 since the author stated 'I think, but I've forgotten' in the description! ;)

Never seen that one before! :D

Dabz

schilcote
(Posted 18 years ago)
Really? It took me 30 seconds to make. The factor calculator program is alot better. I updated that one a few times, and never really paid attention to this. If anyone asks I can throw the program at them. Maybe it's engine can be used for something else. Like a function.

Code Archives Forum