Giter Site home page Giter Site logo

go-combi's Introduction

go-combi

Go codecov Go Report Card

combi implements some combinatoric functions

SYNOPSIS

You can see a sample code in cmd directory.

package main

import (
	"fmt"

	"github.com/sadah/go-combi"
)

func main() {
    ints := []int{1, 2, 3}
    psi := combi.PowerSetInts(ints)
    fmt.Println(psi)
    // => [[] [1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]
}

DESCRIPTION

TBD

API

Power Set

Power Set Index

psi := combi.PowerSetIndex(5)
fmt.Println(psi)
// => [[] [0] [1] [0 1] [2] [0 2] [1 2] [0 1 2]]

Power Set Ins

ints := []int{1, 2, 3}
psi := combi.PowerSetInts(ints)
fmt.Println(psi)
// => [[] [1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]

Power Set Strs

strs := []string{"a", "b", "c"}
pss := combi.PowerSetStrs(strs)
fmt.Println(pss)
// => [[] [a] [b] [a b] [c] [a c] [b c] [a b c]]

Combination

Combination Index

cin := combi.CombinationIndex(3, 2)
fmt.Println(cin)
// => [[0 1] [0 2] [1 2]]

Combination Ints

ints := []int{1, 2, 3}
ci := combi.CombinationInts(ints, 2)
fmt.Println(ci)
// => [[1 2] [1 3] [2 3]]

Combination Strs

strs := []string{"a", "b", "c"}
cs := combi.CombinationStrs(strs, 2)
fmt.Println(cs)
// => [[a b] [a c] [b c]]

Permutation

TBD

Arithmetic Functions

C

C returns C(n,k)

C(n,k) = n!/((n-k)!k!)

c := combi.C(5, 2)
fmt.Println(c)
// => 10

P

P calculates P(n, k)

P(n, k) = n! / k!

p := combi.P(5, 2)
fmt.Println(p)
// => 20

Factorical

Factorial returns n!

factorial := combi.Factorial(5)
fmt.Println(factorial)
// => 120

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.