Skip to content

Instantly share code, notes, and snippets.

@jrwdexter
Last active December 2, 2015 16:55
Show Gist options
  • Select an option

  • Save jrwdexter/858185d66a85d60b4e8a to your computer and use it in GitHub Desktop.

Select an option

Save jrwdexter/858185d66a85d60b4e8a to your computer and use it in GitHub Desktop.

Last year, {INSERT_HOLIDAY_MYTH_HERE} (hereafter referred to as "Santa") created a special GMO: the Candy Cane Plant. However, after creating the plant Santa and his biologist friends found out that it suffered from an extreme deficiency: each plant could only breed once. Each candy cane plant has the following properties and methods:

public class CandyCanePlant
{
  int CandyCanesProducedPerWeek { get; set; }
  bool HasBred { get; set; }
}

public class BreederService
{
  public CandyCanePlant Breed(CandyCanePlant father, CandyCanePlant mother);
}

A newly bred candy cane plant has a production value of:

Math.Pow(fathersProductionValue, mothersProductionValue) % (fathersProductionValue + mothersProductionValue)

and has a HasBred value of false.

Write code that optimizes the total number of candy canes produced per week given an initial stock of CandyCanePlant[] plants, producing a new collection of CandyCanePlant[]s. The output of your code should also produce the total number of candy canes produced per week with the bred stock.

For example, given the following initial stock:

CandyCanePlant { CandyCanesPerWeek = 5}
CandyCanePlant { CandyCanesPerWeek = 3}
CandyCanePlant { CandyCanesPerWeek = 2}

Your code should inform Santa what his final stock will be, as well as the total production value of said stock. The above example should produce a total production output of

CandyCanePlant { CandyCanesPerWeek = 7, HasBred = true}
CandyCanePlant { CandyCanesPerWeek = 5, HasBred = true}
CandyCanePlant { CandyCanesPerWeek = 4, HasBred = false}
CandyCanePlant { CandyCanesPerWeek = 3, HasBred = true}
CandyCanePlant { CandyCanesPerWeek = 2, HasBred = true}

and a production value of 21 per week.

Code will be judged based on a large input stock of Candy Cane Plants.

Bonus Problem (hard!):

The above code models an ideal world - in the real world, Candy Cane Plants experience a production reduction of 1 candy cane per week, until they hit 0 candy cane plants produced. Assuming that breeding takes 1 week and produces no candy canes, inform Santa of how many total candy canes will be produced in the optimal breeding scenario.

Note that breeding in certain weeks may produce more optimal plants than other weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment