From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: New to Ada need help implementing Warshall's algorithm
Date: Sun, 25 Sep 2016 09:06:56 -0700 (PDT)
Date: 2016-09-25T09:06:56-07:00 [thread overview]
Message-ID: <d30f3527-8ffb-48c4-9118-99e8eb153dc1@googlegroups.com> (raw)
In-Reply-To: <ec6d1235-6923-4f10-9978-e908cc7750ef@googlegroups.com>
On Friday, September 23, 2016 at 10:07:53 AM UTC-5, James Brewer wrote:
>
> It is three diffent sets of data. I think I may try to simplify the input data to a 0,1 2d array for each set, read the set in and then process each set writing it to an output file (the last two I will have to figure out).
Here's a working program that does the IO, to get you started. It reads from a file, writes to standard out.
Reading the entire input line from the file, then processing it, simplifies debugging.
with Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
procedure Warshall
is
procedure Put_Usage
is
begin
Put_Line ("Usage: warshall <input file name>");
end Put_Usage;
File : File_Type;
begin
Open (File, In_File, Ada.Command_Line.Argument (1));
loop
exit when End_Of_File (File);
declare
Line : constant String := Get_Line (File);
-- Each line should have format 'A B' where, A, B => 1 | 0
A : Boolean;
B : Boolean;
begin
if Line (1) = '0' then
A := False;
else
A := True;
end if;
if Line (3) = '0' then
B := False;
else
B := True;
end if;
-- FIXME: implement warshall's algorithm
Put_Line ("A, B: " & Boolean'Image (A) & " " & Boolean'Image (B));
end;
end loop;
end Warshall;
given an input file:
0 1
1 0
this produces:
A, B: FALSE TRUE
A, B: TRUE FALSE
I'm happy to hear about an instructor using Ada to teach algorithms!
-- Stephe
next prev parent reply other threads:[~2016-09-25 16:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-21 22:05 New to Ada need help implementing Warshall's algorithm James Brewer
2016-09-23 4:31 ` Shark8
2016-09-23 6:26 ` Simon Wright
2016-09-23 15:07 ` James Brewer
2016-09-25 16:06 ` Stephen Leake [this message]
2016-09-26 20:40 ` Simon Wright
2016-09-23 14:54 ` James Brewer
2018-02-12 17:45 ` Lucretia
2016-09-26 17:38 ` James Brewer
2016-09-26 18:29 ` Stephen Leake
2018-02-12 15:36 ` jre11712
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox