algorithm

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Comb

func Comb(data []interface{}, k int) [][]interface{}

func CombFlag

func CombFlag(m, n int) []string

*

  • 获得从 m 中取 n 的所有组合
  • 思路如下:
  • 生成一个长度为 m 的数组,
  • 数组元素的值为 1 表示其下标代表的数被选中,为 0 则没选中。 *
  • 1. 初始化数组,前 n 个元素置 1,表示第一个组合为前 n 个数;
  • 2. 从左到右扫描数组元素值的 “10” 组合,找到第一个 “10” 组合后将其变为 “01” 组合;
  • 3. 将其左边的所有 “1” 全部移动到数组的最左端
  • 4. 当 n 个 “1” 全部移动到最右端时(没有 “10” 组合了),得到了最后一个组合。

Types

type RobinSeed

type RobinSeed struct {
	Index int
	Lock  *sync.Mutex
}
var (
	Robin *RobinSeed
)

func NewRobinSeed

func NewRobinSeed() *RobinSeed

func (*RobinSeed) NextN

func (r *RobinSeed) NextN(max int) int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL