/* Determine whether strings are anagrams (Code golf) in Picat. https://codegolf.stackexchange.com/questions/1294/determine-whether-strings-are-anagrams """ Determine whether strings are anagrams Challenge Given two strings, work out if they both have exactly the same characters in them. Example Input word, wrdo This returns true because they are the same but just scrambled. Input word, wwro This returns false. Input boat, toba This returns true Rules Here are the rules! Assume input will be at least 1 char long, and no longer than 8 chars. No special characters, only a–z All inputs can be assumed to be lowercase Test Cases boat, boat = true toab, boat = true oabt, toab = true a, aa = false zzz, zzzzzzzz = false zyyyzzzz, yyzzzzzy = true sleepy, pyels = false p,p = true """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go ?=> Ts = [["boat", "boat"], ["toab", "boat"], ["oabt", "toab"], ["a", "aa"], ["zzz", "zzzzzzzz"], ["zyyyzzzz", "yyzzzzzy"], ["sleepy", "pyels"], ["p","p"] ], foreach([A,B] in Ts) cond(t(A,B),(A=B=true),(A=B=false)).println end, nl. go => true. % As a predicate. % 25 chars t(A,B)=>sort(A)==sort(B). % 23 chars s(A,B)=>A.sort==B.sort.