Post Reply 
(41/42) AGM - Arithmetic-Geometric Mean
06-10-2020, 02:14 PM (This post was last modified: 06-11-2020 01:00 AM by Gerson W. Barbosa.)
Post: #9
RE: (41/42) AGM - Arithmetic-Geometric Mean
(06-10-2020 01:16 PM)Werner Wrote:  Seeing that yours really is only 29 bytes (if you replace the GTO "AGM" by a short numeric label), it was not easy to do better. But not impossible, and 41-compatible:

Code:
00 { 27-Byte Prgm } @   X       Y       Z       T
01▸LBL 02
02 X<>Y
03 X<> ST T
04 2
05 ÷
06▸LBL "AGM" @          a       b       z
07 STO ST T @           a       b       z       a
08 X<>Y
09 STO+ ST T @          b       a       z       2AM
10 STO× ST Y
11 X<>Y
12 SQRT @               GM      b       z       2AM
13 X≠Y?
14 GTO 00
15 R↓
16 END

Well done!

With a 1-character label, like “M”, mine is actually 27 bytes long, 15 steps (including LBL & END). I’ve labeled yours “W” here (for Werner, or Winner :-), 25 bytes, 16 steps and 41-compatible. That’s what I’ll keep on my 41C and 41CV.

Just a small typo in your listing: line 14 should be GTO 02 (or line 01 changed to LBL 00).

Regards,

Gerson.

——-

P.S.: Just for the record,

Code:

00 { 30-Byte Prgm }
01▸LBL "AGM"
02 STO ST T
03 X<>Y
04 +
05 2
06 STO÷ ST Y
07 X<> ST L
08 X=Y?
09 GTO 01
10 R↑
11 ×
12 SQRT
13 GTO "AGM"
14▸LBL 01
15 R↓
16 END

30 bytes (26 bytes for 1-character global labels), 16 steps, 41-compatible.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (41/42) AGM - Arithmetic-Geometric Mean - Gerson W. Barbosa - 06-10-2020 02:14 PM



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