Factors of an integer: Difference between revisions
Revised method of defining integers; noted changes in header.
ReeceGoding (talk | contribs) (→Filter solution: Overhaul.) |
(Revised method of defining integers; noted changes in header.) |
||
Line 1,933:
=={{header|EDSAC order code}}==
Input is limited to 10 decimal digits, which is as many as the EDSAC print subroutine P7 can handle. Factors are printed in pairs, such that the product of the factors in each pair equals the input number.
2021-10-10 Integers are now read from the tape in decimal format, instead of being defined by the awkward method of pseudo-orders. The factorization of 999,999,999 has been removed, as it took too long on the commonly-used EdsacPC simulator (14.6 million orders - over 6 hours on the original EDSAC).
<lang edsac>
[EDSAC program, Initial Orders 2.]
[The numbers to be factorized are read in by library subroutine R2
(Wilkes, Wheeler and Gill, 1951 edition, pp.96-97, 148).]
[The address of the integers is placed in location 46, so they can be
referred to by the N parameter (or we could have used 45 and H, etc.)]
[Subroutine R2]
GKT20FVDL8FA40DUDTFI40FA40FS39FG@S2FG23FA5@T5@E4@E13Z
T #N [pass address of integers to R2]
[List of integers to be factorized; edit ad lib. R2 requires 'F' after
each integer except the last, and '#' (pi) after the last.
This program uses 0 to mark the end of the list.]
42000F999999F0#
[Prints signed integer; up to 10 digits, left-justified.]
[Input
[54 locations. Load at even address. Workspace 4D.]
T 56 K
35-bit dividend and divisor (max 2^34 - 1)
returning quotient and remainder.
Input: dividend at 4D, divisor at 6D
Output: remainder at 4D, quotient at 6D.
37 locations; working locations 0D, 8D.]
T 110 K
[Subroutine to find and print factors of a positive integer.
Input: 0D = integer, maximum 10 decimal digits.
Load at even address.]
T 148 K
G K
A 3 F [form and plant link for return]
T 55 @
A D [load integer
T 56#@ [store
A 62#@ [load 1]
T 58#@ [possible factor := 1]
Line 1,978 ⟶ 1,997:
T 6 D [to 6F for division]
A 13 @ [for return from next]
G 110 F [
A 6 D [save quotient (
T 60#@
S 4 D [load negative of remainder]
G 44 @ [skip if remainder > 0]
[Here if m is a factor of n.]
T F [clear acc]
A 64 @ [test count of items per line]
Line 2,025 ⟶ 2,044:
O 70 @
O 71 @
T F [
[55] E F [return]
[--------]
[56]
[58]
[60]
T 62 Z [resume normal loading]
[62] PD PF [35-bit constant 1]
[64] P F [negative counter for items per line]
[65] P 4 F [items per line, in address field]
[66] ! F [space]
[67] K F [left parenthesis (in figures mode)]
[68] L F [right parenthesis (in figures mode)]
[69] N F [comma (in figures mode)]
[70] @ F [carriage return]
[71] & F [line feed]
T 400 K
G K
[0] #
[
[
[4] L 944 F V 2047 F [-420,000]▼
▲ [6] & 847 D P F [99,999]
▲ [12] # F [figure shift]
▲ [13] K 4096 F [null character]
[
A 2
[7] S
A 12 @ [call subroutine to find and print factors]
G 148 F
E 6 @ [always jump, since S = 12 > 0]
[--------]
[17] O 1 @ [done, print null to flush printer buffer]
Z F [stop]
▲ E 14 Z [define entry point]
P F [acc = 0 on entry]
</lang>
{{out}}
<pre>
(1,
(5,
(
(16,2625) (20,2100) (21,2000) (24,1750)
(25,1680) (28,1500) (30,1400) (35,1200)
(40,1050) (42,1000) (48,875) (50,840)
(56,750) (60,700) (70,600) (75,560)
(80,525) (84,500) (100,420) (105,400)
(112,375) (120,350) (125,336) (140,300)
(150,280) (168,250) (175,240) (200,210)
(1,
(
(33,30303) (37,27027) (39,25641) (63,15873)
(77,12987) (91,10989) (99,10101) (111,9009)
(117,8547) (143,6993) (189,5291) (231,4329)
(259,3861) (273,3663) (297,3367) (333,3003)
(351,2849) (407,2457) (429,2331) (481,2079)
(693,1443) (777,1287) (819,1221) (999,1001)
</pre>
|