Home » Archimedes archive » Acorn User » AU 1995-10.adf » !Direct » Director/!Director/Menus/System/Factor

Director/!Director/Menus/System/Factor

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1995-10.adf » !Direct
Filename: Director/!Director/Menus/System/Factor
Read OK:
File size: 0382 bytes
Load address: 0000
Exec address: 0000
Duplicates

There is 1 duplicate copy of this file in the archive:

File contents
    1REM >Director:Menus.System.Factor
    2
    3REM This factors the number supplied and displays the result in a menu
    4
    5ON ERROR: ON ERROR OFF: ERROR ERR,REPORT$+" at "+STR$ERL
    6SYS "OS_GetEnv" TO in$
    7SYS "OS_GetEnv" TO a$
    8n$=FNarg(in$,"-n","")
    9n%=VALn$
   10
   11*Set Director$Menu FactorSub
   12SYS "Director_Menu"," """" ""<Director$Menu>"" -temp"
   13
   14IF n%=0 THEN
   15 SYS "Director_Option","""Syntax error"""
   16ELSE
   17 i%=0
   18 REPEAT
   19  a%=FNfactor(n%)
   20  SYS "Director_Option",""""+STR$a%+""""
   21  n%=n% DIV a%
   22  i%+=1
   23 UNTIL n%=1
   24 IF i%=1 THEN SYS "Director_Option","""(Prime)"""
   25ENDIF
   26
   27SYS "Director_EndMenu"
   28
   29END
   30
   31REM This finds the first factor of the number supplied
   32
   33DEF FNfactor(a%)
   34LOCAL i%
   35IF (a% MOD2)=0 THEN =2
   36FOR i%=3 TO INT(SQR(a%)+1) STEP 2
   37  IF (a% MOD i%)=0 THEN =i%
   38NEXT i%
   39=a%
   40
   41DEF FNarg(str$,arg$,def$)
   42LOCAL i,j
   43i=INSTR(str$,arg$)
   44IF i=0 THEN =def$
   45i+=LENarg$+1
   46j=INSTR(str$+" <"," ",i)
   47=MID$(str$,i,j-i)
   48
#� >Director:Menus.System.Factor

H� This factors the number supplied and displays the result in a menu

 � �: � � �: � �,�$+" at "+Þ
ș "OS_GetEnv" � in$
ș "OS_GetEnv" � a$
n$=�arg(in$,"-n","")
	
n%=�n$


 *Set Director$Menu FactorSub
8ș "Director_Menu"," """" ""<Director$Menu>"" -temp"


� n%=0 �
, ș "Director_Option","""Syntax error"""
�
	 i%=0
 �
  a%=�factor(n%)
(  ș "Director_Option",""""+�a%+""""
  n%=n% � a%
  i%+=1
 � n%=1
0 � i%=1 � ș "Director_Option","""(Prime)"""
�

ș "Director_EndMenu"

�

8� This finds the first factor of the number supplied
 
!� �factor(a%)
"� i%
#� (a% �2)=0 � =2
$� i%=3 � �(�(a%)+1) � 2
%  � (a% � i%)=0 � =i%
&� i%
'=a%
(
)� �arg(str$,arg$,def$)
*	� i,j
+i=�str$,arg$)
,� i=0 � =def$
-i+=�arg$+1
.j=�str$+" <"," ",i)
/=�str$,i,j-i)
0
�
00000000  0d 00 01 23 f4 20 3e 44  69 72 65 63 74 6f 72 3a  |...#. >Director:|
00000010  4d 65 6e 75 73 2e 53 79  73 74 65 6d 2e 46 61 63  |Menus.System.Fac|
00000020  74 6f 72 0d 00 02 04 0d  00 03 48 f4 20 54 68 69  |tor.......H. Thi|
00000030  73 20 66 61 63 74 6f 72  73 20 74 68 65 20 6e 75  |s factors the nu|
00000040  6d 62 65 72 20 73 75 70  70 6c 69 65 64 20 61 6e  |mber supplied an|
00000050  64 20 64 69 73 70 6c 61  79 73 20 74 68 65 20 72  |d displays the r|
00000060  65 73 75 6c 74 20 69 6e  20 61 20 6d 65 6e 75 0d  |esult in a menu.|
00000070  00 04 04 0d 00 05 20 ee  20 85 3a 20 ee 20 85 20  |...... . .: . . |
00000080  87 3a 20 85 20 9f 2c f6  24 2b 22 20 61 74 20 22  |.: . .,.$+" at "|
00000090  2b c3 9e 0d 00 06 18 c8  99 20 22 4f 53 5f 47 65  |+........ "OS_Ge|
000000a0  74 45 6e 76 22 20 b8 20  69 6e 24 0d 00 07 17 c8  |tEnv" . in$.....|
000000b0  99 20 22 4f 53 5f 47 65  74 45 6e 76 22 20 b8 20  |. "OS_GetEnv" . |
000000c0  61 24 0d 00 08 18 6e 24  3d a4 61 72 67 28 69 6e  |a$....n$=.arg(in|
000000d0  24 2c 22 2d 6e 22 2c 22  22 29 0d 00 09 0a 6e 25  |$,"-n","")....n%|
000000e0  3d bb 6e 24 0d 00 0a 04  0d 00 0b 20 2a 53 65 74  |=.n$....... *Set|
000000f0  20 44 69 72 65 63 74 6f  72 24 4d 65 6e 75 20 46  | Director$Menu F|
00000100  61 63 74 6f 72 53 75 62  0d 00 0c 38 c8 99 20 22  |actorSub...8.. "|
00000110  44 69 72 65 63 74 6f 72  5f 4d 65 6e 75 22 2c 22  |Director_Menu","|
00000120  20 22 22 22 22 20 22 22  3c 44 69 72 65 63 74 6f  | """" ""<Directo|
00000130  72 24 4d 65 6e 75 3e 22  22 20 2d 74 65 6d 70 22  |r$Menu>"" -temp"|
00000140  0d 00 0d 04 0d 00 0e 0c  e7 20 6e 25 3d 30 20 8c  |......... n%=0 .|
00000150  0d 00 0f 2c 20 c8 99 20  22 44 69 72 65 63 74 6f  |..., .. "Directo|
00000160  72 5f 4f 70 74 69 6f 6e  22 2c 22 22 22 53 79 6e  |r_Option","""Syn|
00000170  74 61 78 20 65 72 72 6f  72 22 22 22 0d 00 10 05  |tax error"""....|
00000180  cc 0d 00 11 09 20 69 25  3d 30 0d 00 12 06 20 f5  |..... i%=0.... .|
00000190  0d 00 13 14 20 20 61 25  3d a4 66 61 63 74 6f 72  |....  a%=.factor|
000001a0  28 6e 25 29 0d 00 14 28  20 20 c8 99 20 22 44 69  |(n%)...(  .. "Di|
000001b0  72 65 63 74 6f 72 5f 4f  70 74 69 6f 6e 22 2c 22  |rector_Option","|
000001c0  22 22 22 2b c3 61 25 2b  22 22 22 22 0d 00 15 10  |"""+.a%+""""....|
000001d0  20 20 6e 25 3d 6e 25 20  81 20 61 25 0d 00 16 0b  |  n%=n% . a%....|
000001e0  20 20 69 25 2b 3d 31 0d  00 17 0b 20 fd 20 6e 25  |  i%+=1.... . n%|
000001f0  3d 31 0d 00 18 30 20 e7  20 69 25 3d 31 20 8c 20  |=1...0 . i%=1 . |
00000200  c8 99 20 22 44 69 72 65  63 74 6f 72 5f 4f 70 74  |.. "Director_Opt|
00000210  69 6f 6e 22 2c 22 22 22  28 50 72 69 6d 65 29 22  |ion","""(Prime)"|
00000220  22 22 0d 00 19 05 cd 0d  00 1a 04 0d 00 1b 19 c8  |""..............|
00000230  99 20 22 44 69 72 65 63  74 6f 72 5f 45 6e 64 4d  |. "Director_EndM|
00000240  65 6e 75 22 0d 00 1c 04  0d 00 1d 05 e0 0d 00 1e  |enu"............|
00000250  04 0d 00 1f 38 f4 20 54  68 69 73 20 66 69 6e 64  |....8. This find|
00000260  73 20 74 68 65 20 66 69  72 73 74 20 66 61 63 74  |s the first fact|
00000270  6f 72 20 6f 66 20 74 68  65 20 6e 75 6d 62 65 72  |or of the number|
00000280  20 73 75 70 70 6c 69 65  64 0d 00 20 04 0d 00 21  | supplied.. ...!|
00000290  11 dd 20 a4 66 61 63 74  6f 72 28 61 25 29 0d 00  |.. .factor(a%)..|
000002a0  22 08 ea 20 69 25 0d 00  23 14 e7 20 28 61 25 20  |".. i%..#.. (a% |
000002b0  83 32 29 3d 30 20 8c 20  3d 32 0d 00 24 1b e3 20  |.2)=0 . =2..$.. |
000002c0  69 25 3d 33 20 b8 20 a8  28 b6 28 61 25 29 2b 31  |i%=3 . .(.(a%)+1|
000002d0  29 20 88 20 32 0d 00 25  19 20 20 e7 20 28 61 25  |) . 2..%.  . (a%|
000002e0  20 83 20 69 25 29 3d 30  20 8c 20 3d 69 25 0d 00  | . i%)=0 . =i%..|
000002f0  26 08 ed 20 69 25 0d 00  27 07 3d 61 25 0d 00 28  |&.. i%..'.=a%..(|
00000300  04 0d 00 29 1a dd 20 a4  61 72 67 28 73 74 72 24  |...).. .arg(str$|
00000310  2c 61 72 67 24 2c 64 65  66 24 29 0d 00 2a 09 ea  |,arg$,def$)..*..|
00000320  20 69 2c 6a 0d 00 2b 11  69 3d a7 73 74 72 24 2c  | i,j..+.i=.str$,|
00000330  61 72 67 24 29 0d 00 2c  11 e7 20 69 3d 30 20 8c  |arg$)..,.. i=0 .|
00000340  20 3d 64 65 66 24 0d 00  2d 0e 69 2b 3d a9 61 72  | =def$..-.i+=.ar|
00000350  67 24 2b 31 0d 00 2e 17  6a 3d a7 73 74 72 24 2b  |g$+1....j=.str$+|
00000360  22 20 3c 22 2c 22 20 22  2c 69 29 0d 00 2f 11 3d  |" <"," ",i)../.=|
00000370  c1 73 74 72 24 2c 69 2c  6a 2d 69 29 0d 00 30 04  |.str$,i,j-i)..0.|
00000380  0d ff                                             |..|
00000382