Re: Program for HP-16c... Message #3 Posted by Thomas Klemm on 3 June 2013, 1:23 p.m., in response to message #2 by Kiyoshi Akima
Or maybe:
- Subtract 1000
- Leave if it is between 0 and 1000
- Add 1000
- Subtract 100
- Leave if it is between 0 and 100
- Add 100
(...)
This is the program that illustrates the algorithm:
#!/usr/bin/python
def remove(n):
k = 1000
while k > 0:
n -= k
if 0 <= n < k:
break
n += k
k /= 10
return n
for n in (0, 1, 3, 13, 45, 114, 144, 456, 1456, 1018, 3255):
print "%10d -> %10d" % (n, remove(n))
0 -> 0
1 -> 0
3 -> 3
13 -> 3
45 -> 45
114 -> 14
144 -> 44
456 -> 456
1456 -> 456
1018 -> 18
3255 -> 3255
This is the program for the HP-16C:
001 - 43,22, A LBL A
002 - 1 1
003 - 0 0
004 - 0 0
005 - 10 /
006 - 24 DEC
007 - 1 1
008 - 0 0
009 - 0 0
010 - 0 0
011 - 0 0
012 - 43,22, 0 LBL 0
013 - 30 -
014 - 43 2 x<0
015 - 22 1 GTO 1
016 - 43 36 LSTx
017 - 43 1 x<=y
018 - 22 2 GTO 2
019 - 22 3 GTO 3
020 - 43,22, 1 LBL 1
021 - 43 36 LSTx
022 - 43,22, 2 LBL 2
023 - 40 +
024 - 43 36 LSTx
025 - 1 1
026 - 0 0
027 - 10 /
028 - 43 30 x>0
029 - 22 0 GTO 0
030 - 43,22, 3 LBL 3
031 - 33 Rv
032 - 43 21 RTN
My table doesn't agree in all cases:
INPUT OUTPUT
285801 h 328 d
271101 h 1 d
3E7F03 h 5999 d
3F7F03 h 6255 d
AE01 h 74 d
F02 h 5 d
3DA01 h 986 d
3F3E02 h 6190 d
2B6799 h 1111 d
Nevertheless I hope this is what you were looking for.
Kind regards
Thomas
Edited: 3 June 2013, 2:58 p.m.
|