/* Rot-13 words in Picat. Rot 13 on words: Which words are Rot 13 of another word. Some examples: [w = abba,rot13 = noon] [w = abhc,rot13 = noup] [w = abib,rot13 = novo] [w = abjurer,rot13 = nowhere] [w = chechen,rot13 = purpura] [w = cheery,rot13 = purrel] [w = freir,rot13 = serve] [w = fubar,rot13 = shone] [w = junger,rot13 = whatre] [w = kers,rot13 = xref] [w = lana,rot13 = ynan] maxLen = 7 maxWord = [abjurer,nowhere] This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go => File = "words_lower.txt", Words = new_map([W=1 : W in read_file_lines(File), length(W) > 3]), MaxLen = 0, MaxWord = "", foreach(W in keys(Words).sort(), W[1] @< 'n') Len = length(W), if Len > 3 then Rot13 = rot13(W), if Words.has_key(Rot13) then println([w=W,rot13=Rot13]), if Len > MaxLen then MaxLen := Len, MaxWord := [W,Rot13], println(newmax=[Len,W,Rot13]) end end end end, println(maxLen=MaxLen), println(maxWord=MaxWord), nl. % Rot 13 using a map rot13(S) = S2 => Lower = "abcdefghijklmnopqrstuvwxyz", Upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", M = create_map(Lower, Upper), % If a char is not in a..zA..z then show it as it is. S2 := [M.get(C,C) : C in S]. create_map(Lower, Upper) = M => M = new_map(), Len = Lower.length, LDiv := Lower.length div 2, foreach(I in 1..Len) II = (LDiv+I) mod Len, if II == 0 then II := Len end, M.put(Upper[I],Upper[II]), M.put(Lower[I],Lower[II]) end.