Re: Another days between dates challenge for 11c Message #3 Posted by Gerson W. Barbosa on 16 Aug 2009, 1:38 p.m., in response to message #2 by Katie Wasserman
The following is based on the method used in the TI-59 Master Library Module (page 76). Day of the Week has also been included. The program is far from optimized: 91 + 3*7 + 3*2 = 116.
001- LBL A 035- * 069- RCL 1
002- GSB 0 036- STO+ 0 070- EEX
003- x<>y 037- Rv 071- 2
004- GSB 0 038- ENTER 072- /
005- - 039- ENTER 073- INT
006- RTN 040- . 074- 1
007- LBL 0 041- 4 075- +
008- 0 042- * 076- .
009- STO 0 043- 2 077- 7
010- Rv 044- . 078- 5
011- EEX 045- 3 079- *
012- 2 046- + 080- INT
013- * 047- INT 081- STO- 0
014- ENTER 048- STO 2 082- RCL 1
015- FRAC 049- Rv 083- 4
016- EEX 050- 1 084- /
017- 4 051- - 085- INT
018- * 052- 3 086- STO+ 0
019- STO 1 053- 1 087- RCL 2
020- 3 054- x<>y 088- STO- 0
021- 6 055- * 089- R^
022- 5 056- STO+ 0 090- RCL 0
023- * 057- Rv 091- RTN
024- STO+ 0 058- 1 092- LBL B
025- Rv 059- LSTx 093- GSB 0
026- INT 060- x>y 094- ENTER
027- EEX 061- GTO 1 095- CHS
028- 2 062- x<>y 096- 7
029- / 063- STO- 1 097- /
030- INT 064- CLx 098- INT
031- LSTx 065- STO 2 099- 7
032- FRAC 066- LBL 1 100- *
033- EEX 067- Rv 101- +
034- 2 068- Rv 102- RTN
Date format is MM.DDYYYY
GSB A: works just like DeltaDYS on the 12C.
GSB B: similar to DATE on the 12C, but requires only one argument, the date, and returns 0=Sat, 1=Sun, ... 6=Fri.
Equivalent TurboBCD program:
Program DaysBetweenDates;
var days, dt1, dt2: real;
function f(dt: real): real;
var d, m, y, t, x: real;
begin
y:=1e4*(Frac(100*dt));
m:=Int(dt);
d:=Int(100*(Frac(dt)));
x:=Int(0.4*m+2.3);
t:=365*y+d+31*(m-1);
if (m-1)<=1 then
begin
y:=y-1;
x:=0
end;
f:=t+Int(y/4)-Int(0.75*(Int(y/100)+1))-x
end;
begin
ReadLn(dt1,dt2);
days:=f(dt2)-f(dt1);
WriteLn(days:7:0)
end.
>
Running
6.011960 10.311976
5996
>
Running
2.281900 3.011900
1
>
Edited to correct a typo in line 060
Edited: 16 Aug 2009, 7:19 p.m.
|