aboutsummaryrefslogtreecommitdiff
path: root/challenge-280/deadmarshal/modula-3/ch1/src/Ch1.m3
blob: d770df7d4db53c39f3913c2089bd51440caddfc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
MODULE Ch1 EXPORTS Main;

IMPORT SIO,Text;

PROCEDURE TwiceAppearance(READONLY Str:TEXT):CHAR =
  VAR
    Counts:ARRAY[0..26] OF INTEGER := ARRAY[0..26] OF INTEGER{0,..};
    Idx:INTEGER := 0;
  BEGIN
    FOR I := 0 TO Text.Length(Str)-1 DO
      Idx := ORD(Text.GetChar(Str,I)) - ORD('a');
      IF Counts[Idx] # 0 THEN RETURN Text.GetChar(Str,I) END;
      INC(Counts[Idx])
    END;
    RETURN '\000'
  END TwiceAppearance;
  
BEGIN
  SIO.PutChar(TwiceAppearance("acbddbca")); SIO.Nl();
  SIO.PutChar(TwiceAppearance("abccd")); SIO.Nl();
  SIO.PutChar(TwiceAppearance("abcdabbb")); SIO.Nl()
END Ch1.