public object Clone()
        {
            var newJug = new Jug(Capacity);

            newJug.UpdateContent(Current);
            return(newJug);
        }
Example #2
0
        /// <summary>
        /// Transfer water from current <see cref="Jug"/> to destination <see cref="Jug"/>
        /// </summary>
        /// <param name="current">The current jug</param>
        /// <param name="destination">The destination jug</param>
        /// <returns>A <see cref="bool"/> denoting if this rule was applied</returns>
        bool TransferWater(Jug current, Jug destination)
        {
            if (current.IsEmpty() || destination.IsFull())
            {
                return(false);
            }

            var amount = Math.Min(current.Current, destination.EmptySpace);

            current.UpdateContent(-amount);
            destination.UpdateContent(amount);

            return(true);
        }