Skip to content

wgottschalk/bucketAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published