From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.8 required=3.0 tests=BAYES_50,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:ac8:7601:: with SMTP id t1mr23900775qtq.323.1607859392829; Sun, 13 Dec 2020 03:36:32 -0800 (PST) X-Received: by 2002:a05:620a:2290:: with SMTP id o16mr25960203qkh.101.1607859392667; Sun, 13 Dec 2020 03:36:32 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 13 Dec 2020 03:36:32 -0800 (PST) In-Reply-To: <957fd2ad-079d-40c3-8fbf-a7d009deb714n@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=2a02:1206:4564:fe50:5179:1381:6bfc:41dd; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG NNTP-Posting-Host: 2a02:1206:4564:fe50:5179:1381:6bfc:41dd References: <867dpmpy50.fsf@stephe-leake.org> <3739d281-8131-4096-b51d-11ac18647aecn@googlegroups.com> <957fd2ad-079d-40c3-8fbf-a7d009deb714n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Advent of code day 12 From: Gautier Write-Only Address Injection-Date: Sun, 13 Dec 2020 11:36:32 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:60823 List-Id: > I used interface and tagged types to make solution more interesting :) Cool! I was a bit disturbed by the code duplication around the ship's position and the Manhattan_Distance function. Here is and idea to address it: package Day_12 is package Controls is type Control_Interface is limited interface; procedure Move (Self : in out Control_Interface; North : Natural := 0; South : Natural := 0; East : Natural := 0; West : Natural := 0) is abstract; procedure Turn (Self : in out Control_Interface; Left : Natural := 0; Right : Natural := 0) is abstract; procedure Forward (Self : in out Control_Interface; Value : Positive) is abstract; function Manhattan_Distance (Self : Control_Interface) return Natural is abstract; end Controls; package Basic_Ships is type Position is record East : Integer; North : Integer; end record; type Basic_Ship_Data is abstract new Controls.Control_Interface with record Ship : Position; end record; function Manhattan_Distance (Self : Basic_Ship_Data) return Natural; end Basic_Ships; package Part_1 is type Ship_Data is new Basic_Ships.Basic_Ship_Data with record Angle : Integer := 0; end record; procedure Move (Self : in out Ship_Data; North : Natural := 0; South : Natural := 0; East : Natural := 0; West : Natural := 0); procedure Turn (Self : in out Ship_Data; Left : Natural := 0; Right : Natural := 0); procedure Forward (Self : in out Ship_Data; Value : Positive); end Part_1; package Part_2 is type Ship_Data is new Basic_Ships.Basic_Ship_Data with record Waypoint : Basic_Ships.Position := (East => 10, North => 1); end record; procedure Move (Self : in out Ship_Data; North : Natural := 0; South : Natural := 0; East : Natural := 0; West : Natural := 0); procedure Turn (Self : in out Ship_Data; Left : Natural := 0; Right : Natural := 0); procedure Forward (Self : in out Ship_Data; Value : Positive); end Part_2; end Day_12;