"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
npm install water-bucket-algorithm
var bucket = require("water-bucket-algorithm").default;
// bucket(bucketSize1, bucketSize2, target)
bucket(3,5,4) // -> 6
bucket(2,8,1) // -> "Not Possible"
import bucket from "water-bucket-algorithm"
// bucket(bucketSize1, bucketSize2, target)
bucket(3,5,4) // -> 6
bucket(2,8,1) // -> "Not Possible"
MIT © William Gottschalk