How to resolve the algorithm Anagrams/Deranged anagrams step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Anagrams/Deranged anagrams step by step in the 11l programming language

Table of Contents

Problem Statement

Two or more words are said to be anagrams if they have the same characters, but in a different order. By analogy with derangements we define a deranged anagram as two words with the same characters, but in which the same character does not appear in the same position in both words. Use the word list at unixdict to find and display the longest deranged anagram.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Anagrams/Deranged anagrams step by step in the 11l programming language

Source code in the 11l programming language

F is_not_deranged(s1, s2)
   L(i) 0 .< s1.len
      I s1[i] == s2[i]
         R 1B
   R 0B

Dict[String, Array[String]] anagram
V count = 0
L(word) File(‘unixdict.txt’).read().split("\n")
   V a = sorted(word)
   I a !C anagram
      anagram[a] = [word]
   E
      L(ana) anagram[a]
         I is_not_deranged(ana, word)
            L.break
      L.was_no_break
         anagram[a].append(word)
         count = max(count, word.len)

L(ana) anagram.values()
   I ana.len > 1 & ana[0].len == count
      print(ana)

  

You may also check:How to resolve the algorithm Modular inverse step by step in the RPL programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the Groovy programming language
You may also check:How to resolve the algorithm Enumerations step by step in the Phix programming language
You may also check:How to resolve the algorithm Xiaolin Wu's line algorithm step by step in the ATS programming language
You may also check:How to resolve the algorithm Roots of a function step by step in the PicoLisp programming language