Finding cartesian product in Java(在 Java 中查找笛卡尔积)
问题描述
我想找到一组元素的笛卡尔积.这是一个例子
I want to find cartesian product of set of elements. Here's an example
示例 1:
sets : (ab) (bc) (ca)
笛卡尔积是:
abc aba acc aca bbc bba bcc bca
示例 2:
sets : (zyx) b c
笛卡尔积是:
zbc ybc xbc
所以我正在考虑一种在 Java 中执行的算法,它可以在开始时找到在编译时定义的特定数量组的笛卡尔积.
So I am thinking of an algorithm to execute in Java which can find cartesian product of particular amount of groups defined at compile time at the start.
推荐答案
您可以使用 Sets.cartesianProduct() 方法来自 Google 的 Guava 库 用于生成笛卡尔积:
You can use the Sets.cartesianProduct() method from Google's Guava libraries to generate Cartesian products:
com.google.common.collect.Sets.cartesianProduct(Set[] yourSets)
要是一切都这么简单就好了!
If only everything was that easy!
这篇关于在 Java 中查找笛卡尔积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Java 中查找笛卡尔积
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
