-
Notifications
You must be signed in to change notification settings - Fork 1
/
1000!.ps
85 lines (71 loc) · 2.27 KB
/
1000!.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
%!PS-Adobe-2.0
%%Title: N-factorial
%%BoundingBox: 0 0 592 792
%%EndComments
% -- N --
/N 1000 def
% -------------- Consts ---------------
/LM 72 def % right margin
/RM 216 def % left margin
/MAXARRAY % num of decimal quartets, Stirling approx
.5 N add N ln mul .918938 add N sub abs 10 ln div
floor 1 add 4 div 1 add cvi def
/LH 370 MAXARRAY sqrt div dup 19 gt {pop 19} if def
% -------------- Vars ---------------
/Tempstr 8 string def
/ypos 720 def %current y-position
/numbers MAXARRAY array def
% ------------- Procs ---------------
/crlf { % move to next line
ypos LH sub % decrease ypos
/ypos exch def % ...& save new value
LM ypos moveto % move to next line
} def
/counter 0 def
/c2 0 def % pointer of 'number' in array 'numbers';
% needed for adding of 'overflow' to the next cell
/number 0 def % current number from array 'numbers'
/cprint 0 def % necessary for printing: to not print some 'zeroes'
% before factorial
% multiplication of array 'numbers' by 'counter'
/mult {
0 1 MAXARRAY -1 add {
dup numbers exch get counter mul numbers 3 1 roll put
} for
} def
% Checks for 'overflow', when the number in 'numbers' is greater
% then 9999, then one should add an 'overflow' to the next cell.
% Doing this after multiplication of each cells of 'numbers' by
% 'counter'.
/overflow {
0 1 MAXARRAY -2 add {
/c2 exch def numbers c2 get /number exch def
numbers c2 number 10000 mod put
numbers c2 1 add numbers c2 1 add get
number 10000 idiv add put
} for
} def
% pads nums left to 0000
/pad {10000 add 7 string cvs 1 4 getinterval} def
% showing an array 'numbers' in a good format
/showar {
MAXARRAY -1 add -1 0 {
currentpoint pop 500 gt {crlf} if
numbers exch get dup 0 ne {
/cprint 1 def pad Tempstr cvs show} {
cprint 0 ne {pad Tempstr cvs show} {pop} ifelse
} ifelse
} for
} def
% ------------- Render --------------
LM ypos moveto
/Times-Bold findfont 14 scalefont setfont
N Tempstr cvs show (!=) show
/LM 106 def
/Times-Roman findfont LH scalefont setfont
0 1 MAXARRAY -1 add {numbers exch 0 put} for
numbers 0 1 put
1 1 N {/counter exch def mult overflow /cprint 0 def} for
showar
showpage
%%EOF