LBL "PIDTW"
CLX
STO 03
STO 08
100
STO 11
STO 04
ST* 04						'a=10000'
11
"NR.D=?"
PROMPT
STO 00
20								'divided by 40 minus 1 and then divided by 2; or divided by 20 minus 2'
/
"14142020202020"	'lookup nr of records for decimals 440-800'
>"242825"
X<Y?
"02040405070710"	'lookup nr of records for decimals 40-400'
X<Y?
>"101214"
2
-
AROT
ATOX
48
-
10
*
ATOX
48
-
+
STO 01						'nr records'
RCL 00						'nr decimals'
3,5
*
STO 06						'nr loops'
2
*
RCL 01
/
STO 02						'nr bytes/record'
LASTX
*
1
+
7
/
0,49
+
XEQ 04
FIX 0
CF 29
RND								'nr registers'
EMROOM
X<>Y
X>Y?
GTO 04
CRFLAS
RCL 01
STO 05						'records value, initialise f[b]'
2000
SF 00
CLA
XEQ 05						'encode 2000 in 2 bytes'
LBL 00
RCL 02
2
/
STO 07						'byte/record value'
INSREC
DSE 07
LBL 01
APPCHR
DSE 07						'sets 07 to 0 at the end'
GTO 01
DSE 05
GTO 00
LBL 02
RCL 06						'get loop value c'
STO 05						'b=c'
2
*
STO 10						'g=c*2'
X<=0?
GTO 04
ISG 03
LBL 03
RCL 05						'b' to determine file pointer f[b]'
1
-
STO Y
RCL 02						'bytes/record'
2
/
ST/ Z
MOD
500								'2 bytes per number; chr to be divided by 1000 makes it divided by 500'
/
X<>Y
INT
+
STO 09						'store pointer'
XEQ 06						'get f[b] from file'
RCL 04						'10000'
*									'f[b]*a'
RCL 05						'b'
RCL 07						'd'
*									'd*b'
+									'd*b + f(b)*a'
STO 07						'd'
1
ST- 10						'g=g-1'
RCL 07
RCL 10
MOD
XEQ 05						'store f(b)'
RCL 07						'd'
RCL 10						'g'
/
INT								'd=d/g'
STO 07
1
ST- 10						'g=g-1'
DSE 05						'b=b-1'
GTO 03
RCL 07						'd'
RCL 04						'a' 
/
RCL 08						'e'
+
INT
"D"
ARCL 03						'start by showing decimal number'
>"="
RCL 11
X>Y?
>"0"
10
*
X>Y?
>"0"
ARCL Y						'fill leading zeros'
PROMPT
3
ST+ 03
RCL 07						'd'
RCL 04						'a' 
MOD
STO 08						'e'
14
ST- 06						'c=c-14'
GTO 02
LBL 05						'store 4 digit number in alpha using 2 bytes, for example 1234'
FC? 00						'do not set text file pointer when initialising f[b]=2000'
XEQ 07						'set file pointer'
RCL 11
/									'in this example becomes 12.34'
INT								'12'
LASTX							'12.34'
FRC								'0.34'
RCL 11
*									'34'
1
+									'prevent NULL value, stores as 35'
XTOA
X<>Y
RCL 11
+									'prevent NULL value, stores as 112'
XTOA
FS?C 00						'stop here during initialisation of f[b]=2000'
RTN
2
DELCHR						'replace 2 bytes by deleting them first'
RDN
INSCHR						'insert 2 new bytes on same position'
RTN
LBL 06						'retrieve 4 digit number from alpha using 2 bytes'
XEQ 07						'set file pointer'
GETREC						'get bytes although only interested in the first 2'
ATOX							'in same example, returns 35'
1
-									'back correction to allow 0 value returns 34'
ATOX
RCL 11
-									'back correction to allow 0 value, 112-100=12'
LASTX							
*									'12*100=1200'
+									'1200+34=34'
RTN
LBL 07						'set pointer'
CLA
RCL 09
SEEKPTA
X<>Y
RTN
LBL 04						'remove file at start and at exit'
FIX 5
SF 29
SF 25
"PIF"
PURFL
CF 25
END