2014-10-04 2 views

답변

5

내가 ASet

scala> val A =Set("a","b","c","d") 
A: scala.collection.immutable.Set[String] = Set(a, b, c, d) 


scala> val AComb=A.toSet[String].subsets.map(_.mkString).toVector 
AComb: Vector[String] = Vector("", a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, abcd) 

내가 먼저 것을 필요로하지 않는다고 생각하고 있음을 가정하고 요소이므로 시도해보십시오

scala> val AComb=A.toSet[String].subsets.map(_.mkString).toVector.tail 
AComb: scala.collection.immutable.Vector[String] = Vector(a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, abcd) 

scala> val AComb=A.toSet[String].subsets.map(_.mkString).toVector.init.tail 
AComb: scala.collection.immutable.Vector[String] = Vector(a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd) 

scala> val xc1=Set("sunny","hot","high","FALSE","no") 
xc1: scala.collection.immutable.Set[String] = Set(sunny, FALSE, hot, no, high) 

scala> val AComb=xc1.toSet[String].subsets.map(_.mkString(" ")).toVector.tail; 
AComb: scala.collection.immutable.Vector[String] = Vector(sunny, FALSE, hot, no, high, sunny FALSE, sunny hot, sunny no, sunny high, FALSE hot, FALSE no, FALSE high, hot no, hot high, no high, sunny FALSE hot, sunny FALSE no, sunny FALSE high, sunny hot no, sunny hot high, sunny no high, FALSE hot no, FALSE hot high, FALSE no high, hot no high, sunny FALSE hot no, sunny FALSE hot high, sunny FALSE no high, sunny hot no high, FALSE hot no high) 
+0

마지막 요소를 삭제하는 방법은 무엇입니까? – rosy

+0

오류 : (144, 28) 형식 인수 [String] toSet의 형식 매개 변수 범위에 맞지 않습니다. [B> : Any] val AComb = xc1.toSet [String] .subsets.map _.mkString) .toVector.init.tail ^ – rosy

+0

내 세트를 Set [Any]로 선언합니다. 이것이 문제였습니다. 그래서 Set [String]으로 바꿉니다. 그것을 null 값, 즉 반환합니다. ( – rosy

관련 문제