码迷,mamicode.com
首页 > 其他好文 > 详细

[4Clojure]解题记录-#77

时间:2014-11-27 21:55:09      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   color   sp   for   on   div   bs   

Anagram Finder
 

Difficulty: Medium
Topics:  
 
Write a function which finds all the anagrams in a vector of words. A word x is an anagram of word y if all the letters in x can be rearranged in a different order to form y. Your function should return a set of sets, where each sub-set is a group of words which are anagrams of each other. Each sub-set should have at least two words. Words without any anagrams should not be included in the result.
(找出输入集合的所有符合条件的子集,这个条件是,子集中的单词都是有相同的字母通过不同方式排列组合而成)
 
(= (__ ["meat" "mat" "team" "mate" "eat"])  #{#{"meat" "team" "mate"}})
 
(= (__ ["veer" "lake" "item" "kale" "mite" "ever"]) #{#{"veer" "ever"} #{"lake" "kale"} #{"mite" "item"}})
 
解长度:69
(fn [s] 
   (set (map set (filter #(> (count %) 1) (vals (group-by frequencies s))))))
(group-by 非常强大)

[4Clojure]解题记录-#77

标签:style   io   ar   color   sp   for   on   div   bs   

原文地址:http://www.cnblogs.com/zjfu/p/4127119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!