Oh, how clumsy of me. I was aiming for {ch:=s[c]; and then {if ch='#' then}, . . . but realized I could use {if s[c]='#' then} and didn't remove the other code.
And still, your idea (technique) is better.
function astCounterGrid1(m1: tmemo): integer;
var
r,c : integer;
aC: integer;
s : string;
begin
aC:=0; result:=0;
for r:= 0 to m1.Lines.Count-1 do begin
s := m1.Lines.Strings[r];
for c:=0 to length(s) do
if s[c]='#' then inc(aC);
end;
result := aC;
end; // me; my updated version
Below, is CorneliusDavid suggestion, plus I added the capture for #13#10 end-of-line codes (when used in tmemo as a grid).
function astCounterGrid2(m1: tmemo): integer;
var
aC: integer;
s : string;
begin
aC:=0; result:=0;
s := m1.Text;
s := StringReplace(s, #13#10, '', [rfReplaceAll]);
s := StringReplace(s, '.' , '', [rfReplaceAll]);
Inc(ac, s.Length);
result := aC;
end; // carnelious suggestion and my updates
Both routines produce the same results. They capture the total asteroid counts for all the examples:
Best is 3,4 because it can detect 8 asteroids : had 10
Best is 5,8 with 33 other asteroids detected: had 40
Best is 1,2 with 35 other asteroids detected: had 40
Best is 6,3 with 41 other asteroids detected: had 50
Best is 11,13 with 210 other asteroids detected: had 300
I often use the tmemo component as a "grid" to help me with visualization, though it does add to the extra work to compensate for it, like when accounting for the #13#10 char codes that are added.
Had I used an multi-dimentional array[1..5, 1..5] of char, then the #13#10 would not be there and we could eliminate the line with:
s := StringReplace(s, #13#10, '', [rfReplaceAll]);