Post Reply 
[Free42] Minichallenge: ->DATE
08-13-2020, 08:23 AM (This post was last modified: 08-13-2020 10:40 AM by Werner.)
Post: #1
[Free42] Minichallenge: ->DATE
Flags 31 and 67 control the DATE format in Free42:
D.MY F67C, F31S
M.DY F67C, F31C
Y.MD F67S (F31C)

Given YYYY in Z, MM in Y and DD in X, write a routine that will return the date in the current format.
Shortes number of lines, then number of bytes.
Good luck!

Werner
While you're at it, write the reverse routine DATE-> as well

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
08-13-2020, 06:54 PM
Post: #2
RE: [Free42] Minichallenge: ->DATE
My solution, with YYYY in Z, MM in Y and DD in X, it returns the date in the current format:

Code:
00 { 31-Byte Prgm }
01▸LBL "→DATE"
02 FS? 31
03 X<>Y
04 FC? 67
05 RCL ST Z
06 100
07 FC? 67
08 STO÷ ST Y
09 STO÷ ST Y
10 STO÷ ST Z
11 ÷
12 +
13 +
14 END

And the reverse routine:

Code:
00 { 37-Byte Prgm }
01▸LBL "DATE→"
02 IP
03 LASTX
04 FP
05 100
06 ×
07 IP
08 LASTX
09 FP
10 100
11 FC? 67
12 STO× ST Y
13 ×
14 STO ST T
15 FC? 67
16 R↓
17 FS? 31
18 X<>Y
19 END
Find all posts by this user
Quote this message in a reply
08-13-2020, 07:11 PM
Post: #3
RE: [Free42] Minichallenge: ->DATE
Close ;-)
Actually, the first routine matches mine in line and byte count, but yours can be made 1 byte shorter ;-)
I still have a 2 byte edge over the second.
Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
08-13-2020, 08:26 PM
Post: #4
RE: [Free42] Minichallenge: ->DATE
(08-13-2020 07:11 PM)Werner Wrote:  Close ;-)
Actually, the first routine matches mine in line and byte count, but yours can be made 1 byte shorter ;-)

You're right, here is the 1 byte shorter version :

Code:
00 { 30-Byte Prgm }
01▸LBL "→DATE"
02 FS? 31
03 X<>Y
04 FC? 67
05 RCL ST Z
06 100
07 FC? 67
08 STO÷ ST Y
09 STO÷ ST Z
10 X↑2
11 ÷
12 +
13 +
14 END
Find all posts by this user
Quote this message in a reply
08-17-2020, 06:27 AM
Post: #5
RE: [Free42] Minichallenge: ->DATE
here's my entry for DATE→ :

Code:
00 { 35-Byte Prgm }
01 LBL "DATE→"
02 IP
03 LASTX
04 FP
05 100
06 x
07 IP
08 LASTX
09 FP
10 100
11 x
12 FS? 67
13 RTN
14 LASTX
15 x
16 X<> ST Z
17 FC? 31
18 X<>Y
19 END

Thanks for your participation, Didier! Your routine could again be made 1 byte shorter (X^2 io STOx ST Y), which would make it just 1 byte more than mine, with the same line count.
Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
08-17-2020, 12:23 PM
Post: #6
RE: [Free42] Minichallenge: ->DATE
(08-17-2020 06:27 AM)Werner Wrote:  Thanks for your participation, Didier! Your routine could again be made 1 byte shorter (X^2 io STOx ST Y)

"X^2" and "STOx ST Y" don't do the same thing.

With X^2 you end up with Y unchanged and X^2 in X. With STOx ST Y you end up with X*Y in Y and X unchanged.

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
08-17-2020, 01:13 PM
Post: #7
RE: [Free42] Minichallenge: ->DATE
The full code snippet reads
Code:
10 100
11 FC? 67
12 STO× ST Y
13 ×

and here, STOx ST Y may be replaced by X^2, since LASTX is not used further on.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 5 Guest(s)