# PART 2: LETTER PAIR/TRIPLETS: # ----------------------- read `ENGLISH.txt`: Dictionary:=ENG(): Pairs:=table(): for Length from 2 to nops(Dictionary) do: Words:=Dictionary[Length]: for Index from 1 to nops(Words) do: Word:=Words[Index]: for K from 1 to nops(Word) - 1 do: if assigned(Pairs[Word[K],Word[K+1]]) then: Pairs[Word[K],Word[K+1]]:=Pairs[Word[K],Word[K+1]]+1: else Pairs[Word[K],Word[K+1]]:=1: fi: od: od: od: print("Total number of pairs:"); print(nops([indices(Pairs)])); Entries:=[entries(Pairs)]: TotalOverTen:=0: for Index from 1 to nops(Entries) do: if op(Entries[Index]) > 10 then: TotalOverTen:=TotalOverTen+1: fi: od: print("Total number of pairs appearing over 10 times:"); print(TotalOverTen); Triplets:=table(): for Length from 3 to nops(Dictionary) do: Words:=Dictionary[Length]: for Index from 1 to nops(Words) do: Word:=Words[Index]: for K from 1 to nops(Word) - 2 do: if assigned(Triplets[Word[K],Word[K+1],Word[K+2]]) then: Triplets[Word[K],Word[K+1],Word[K+2]]:=Triplets[Word[K],Word[K+1],Word[K+2]]+1: else Triplets[Word[K],Word[K+1],Word[K+2]]:=1: fi: od: od: od: print("Total number of triplets:"); print(nops([indices(Triplets)]));