Skip to content

High-performance tool for calculating all combinations of matching target amount from the list of given amounts

Notifications You must be signed in to change notification settings

chenqionghe/amount-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amount Calculator

High-performance tool for calculating all combinations of matching target amount from the list of given amounts

Install

go get -u github.com/chenqionghe/amount-calculator

Usage

Code Example

package main

import (
	"fmt"
	"github.com/chenqionghe/amount-calculator"
)

func main() {
	// all your amounts
	items := []float64{12, 135, 11, 12, 15, 16, 18, 32, 64, 76, 50}
	// target amount
	target := float64(156)
	// allow to overflow
	overflow := float64(1)

	obj := amountcalculator.New(items, target, overflow)
	fmt.Println(obj.GetCombinations())
}

output

[[11 15 16 18 32 64] [16 64 76] [12 18 76 50]]

Commandline Mode Example

create your own go file: main.go

package main

import (
	"github.com/chenqionghe/amount-calculator"
)

func main() {
	amountcalculator.RunCliMode()
}

compile

go build -o amount-calculator

run and pass three parameters

  • items: all your amounts
  • max: target amount
  • overflow: allow to overflow
 ./amount-calculator -max=156 -overflow=1 -items=12,135,11,12,15,16,18,32,64,76,50
156 [11 15 16 18 32 64]
156 [16 64 76]
156 [12 18 76 50]
157 [12 15 16 18 32 64]
157 [15 16 18 32 76]
157 [15 16 76 50]
156 [11 15 16 18 32 64]
156 [16 64 76]
156 [12 18 76 50]
157 [12 15 16 18 32 64]
157 [15 16 18 32 76]
157 [15 16 76 50]

About

High-performance tool for calculating all combinations of matching target amount from the list of given amounts

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages