Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58781
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Anagrams/Deranged anagrams |
| Date | 2017-05-07 17:48 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <oenmlu$1dmv$1@gioia.aioe.org> (permalink) |
> 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/
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Rosetta: Anagrams/Deranged anagrams "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-07 17:48 +0000
csiph-web