Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #58781 > unrolled thread

Rosetta: Anagrams/Deranged anagrams

Started by"Robert L." <No_spamming@noWhere_7073.org>
First post2017-05-07 17:48 +0000
Last post2017-05-07 17:48 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

  Rosetta: Anagrams/Deranged anagrams "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-07 17:48 +0000

#58781 — Rosetta: Anagrams/Deranged anagrams

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-05-07 17:48 +0000
SubjectRosetta: Anagrams/Deranged anagrams
Message-ID<oenmlu$1dmv$1@gioia.aioe.org>
> 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.
> 
> Task
> 
> Use the word list at unixdict to find and display the longest
> deranged anagram.


IO.readlines('unixdict.txt').map(&:strip).
group_by{|str| str.chars.sort}.
map{|key,words| words.combination(2).select{|a,b|
  a.chars.zip(b.chars).none?{|c,d| c==d}}}.
reject(&:empty?).max_by{|ary| ary[0][0].size}

 ===>
[["excitation", "intoxicate"]]

Using a larger word-list:

IO.readlines('words').map(&:strip).
group_by{|str| str.chars.sort}.
map{|key,words| words.combination(2).select{|a,b|
  a.chars.zip(b.chars).none?{|c,d| c==d}}}.
reject(&:empty?).max_by{|ary| ary[0][0].size}

 ===>
[["actinomeris", "creationism"], ["actinomeris", "reactionism"],
 ["anisometric", "creationism"], ["anisometric", "reactionism"]]


In Forth?

-- 
[T]he number of Jews killed there was 800,000,000.... [T]he Talmud makes it all
clear by informing us that the blood of the holocausted Jews ran to the sea in
a huge tidal wave that swept boulders in its path and was so deep that it
reached the nostrils of the Romans' horses.
nationalvanguard.org/2014/09/disillusioned-part-1/

[toc] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web