A small math prog…
Here’s a small program that will find all whole factors of a number. The bigger the number, the longer it takes, though…
:ClrHome
:Repeat Z and Z≤999 not(fPart(Z
:Input "Number? ",Z
:End
:ClrHome
:Output(8,1,"Calculating...
elVar L1Z→dim(L1
elVar L2Ans→dim(L2
:For(θ,1,Z
:Z/θ
:If not(fPart(Ans
:Then
:Ans→L1(θ
:θ→L2(θ
:End
:End
:If not(max(L1
:Then
:ClrHome
isp "It's prime!
:Stop
:End
:Output(1,1,Z
:Output(2,1,"divided by
:Output(4,1,"is
:For(θ,1,Z
:"
:Output(3,1,Ans
:Output(5,1,Ans
:Output(8,1,"Calculating
:If L2(θ
:Then
:Output(3,1,L2(θ
:Output(5,1,L1(θ
:Output(8,1,"Press Enter
ause
:End
:End
:ClrHome
elVar L1DelVar L2Output(1,1,"
Obviously there are some optimizations, but seeing as how the program is less than 500 bytes anyways…
Just stick in the number and away you go! Note that some factors it gives you are simply reciprocals of an earlier one. i.e. You entered 60. An early factor was 3*20. Later you get 20*3.
Preventing this would add some 200 bytes to the prog, something I’m not willing to do.
I’ve found this extremely useful when factoring quadratic equations.
Loading...
>>Preventing this would add some 200 bytes to the prog, something I’m not willing to do.
alexrudd - January 17, 2007 at 2:00 pm
I think the following would be equally useful…
Input X
For(A,1,√(X
If not(fPart(X/A
Then
ClrDraw
Text(0,0,X,”/”,A,”=”,X/A
Pause
End
End
Disp
Weregoose - January 20, 2007 at 5:55 am
You don’t have to show the reciprocals.
Just stop looking for factors once you reach the halfway mark.
For example, if you use 20: 2*10,4*5,5*4…halfway…Done!
nitacku - January 29, 2007 at 4:08 am
Hi!,
name - September 1, 2008 at 5:58 am