用户登录
用户注册

分享至

在 Java 中查找笛卡尔积

  • 作者: 黄某某007
  • 来源: 51数据库
  • 2022-10-26

问题描述

我想找到一组元素的笛卡尔积.这是一个例子

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相关