npm.io
1.0.4 • Published 10 years ago

water-bucket-algorithm

Licence
MIT
Version
1.0.4
Deps
1
Vulns
0
Weekly
0

The Water Bucket Algorithm

NPM Version Coverage Status Build Status Downloads Dependency Status License

"You are standing in front of a lake with a 3 gallon bucket and a 5 gallon bucket, what is the minimum number of steps need to reach 4 gallons if at all possible?"

"Now abstract that into a function for two buckets of any size and any target value between 1 and the largest bucket size"

Here is an implementation of that algorithm

Install

npm install water-bucket-algorithm

Usage

ES5
var bucket = require("water-bucket-algorithm").default;
// bucket(bucketSize1, bucketSize2, target)

bucket(3,5,4) // -> 6
bucket(2,8,1) // -> "Not Possible"
ES6/2015
import bucket from "water-bucket-algorithm"

// bucket(bucketSize1, bucketSize2, target)

bucket(3,5,4) // -> 6
bucket(2,8,1) // -> "Not Possible"

License

MIT William Gottschalk

Keywords