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

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Anagrams/Deranged anagrams step by step in the J 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 J programming language

Source code in the j programming language

   #words=: 'b' freads 'unixdict.txt'
25104
   #anagrams=: (#~ 1 < #@>) (</.~ /:~&>) words
1303
   #maybederanged=: (#~ (1 -.@e. #@~."1)@|:@:>&>) anagrams
432
   #longest=: (#~ [: (= >./) #@>@{.@>) maybederanged
1
   longest
┌───────────────────────┐
│┌──────────┬──────────┐│
││excitation│intoxicate││
│└──────────┴──────────┘│
└───────────────────────┘


  

You may also check:How to resolve the algorithm Substring step by step in the Seed7 programming language
You may also check:How to resolve the algorithm 24 game step by step in the Ceylon programming language
You may also check:How to resolve the algorithm Pathological floating point problems step by step in the Java programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Function definition step by step in the BASIC programming language