combin

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 4 Imported by: 1

README

Combin

Go Reference Go Report Card Coverage Status

Purpose

Library that provides to drawn combinations

Usage

Example:

package main

import (
    "fmt"

    "github.com/akramarenkov/combin"
)

func main() {
    for combination := range combin.Every([]int{4, 3, 2, 1}) {
        fmt.Println(combination)
    }
    // Output:
    // [4]
    // [4 3]
    // [4 3 2]
    // [4 3 2 1]
    // [4 3 1]
    // [4 2]
    // [4 2 1]
    // [4 1]
    // [3]
    // [3 2]
    // [3 2 1]
    // [3 1]
    // [2]
    // [2 1]
    // [1]
}

Documentation

Overview

Library that provides to drawn combinations.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Every

func Every[Slice ~[]Type, Type any](source Slice) iter.Seq[Slice]

A range iterator over every possible combinations (of length from 1 to the length of the specified slice) of slice elements without repeating elements within a single combination.

The returned slice of combination is valid only for current iteration of the loop.

Example
package main

import (
	"fmt"

	"github.com/akramarenkov/combin"
)

func main() {
	for combination := range combin.Every([]int{4, 3, 2, 1}) {
		fmt.Println(combination)
	}
}
Output:

[4]
[4 3]
[4 3 2]
[4 3 2 1]
[4 3 1]
[4 2]
[4 2 1]
[4 1]
[3]
[3 2]
[3 2 1]
[3 1]
[2]
[2 1]
[1]

func EveryQuantity

func EveryQuantity[Type any](source []Type) *big.Int

Returns the quantity of combinations that can be obtained from the Every function.

If the number of combinations for n elements is m, then for n+1 elements the number of combinations is m + m + 1. It is easy to see that such an increment corresponds to the function 2^n - 1.

func EverySize

func EverySize[Type any](source []Type) uint64

Returns the size of combinations that can be obtained from the Every function.

The returned value is intended to be used in the make call as the size parameter so is truncated to the maximum value for uint64 if the calculated value exceeds it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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