Coding Conundrums Evolved 2: Binary Biomass
This post is part of a biweekly series of programming problems, targeted at those learning to program using C# at University. The problems will vary in difficulty - some will be rather easy, and some will be quite challenging! Don't worry if you can't solve a problem just yet - come back to it in a few months and it'll seem a lot easier than it did before.
Welcome back to Coding Conundrums Evolved, my take on Rob Miles' original Coding Conundrums series. Last time we built a translator for an alien language. As promised, you can find my solution to that problem here. The password to the archive is eyamporrean
. In episode 2, some scientists have made an amazing discovery.
(Above: The ISS as seen from the Space Shuttle Atlantis when departing from the station.)
The scientists on the Zirros orbital research station have managed to create a brand new species of tree (which they've decided to call the mikoko tree) in their lab that grows in precisely the same way every time, allowing the number of leaves on a tree to be predicted with accuracy months or even years in advance.
Upon hearing about this new discovery, the engineering department of Zirros immediately designed a biomass generators a that runs on the leaves of the mikoko tree, since they have been having issues with the station's solar panels recently.
The mikoko starts with a single shoot, which splits into 2 every 9 days. Every time the shoot splits in two, all the previous joints grow a cluster of up to 3 leaves. A joint may not hold more than 3 leaves at once. Incredibly, the mikoko doesn't actually need any of its leaves to grow. It can perform all the photosynthesis it needs to in its branches, apparently. Furthermore, the shoots on the mikoko can be snipped off, at which point the tree ceases to grow any further. In this state it still produces the clusters of leaves every 9 days. The scientists have performed various experiments and come to the conclusion that a single leaf produces 1.5 energy credits when burnt in one of engineering's new biomass generators. The Zirros station, according to engineering, uss 56 energy credits per day.
It is anticipated that once the scientists' paper is released on the mikoko, every station / spaceship / colony within 25 light years will want to power themselves very own mikoko farm. Doing the calculation to work out how big of a tree is needed for each installation is boring and time consuming, and so you've been asked to write a program that will do the calculations needed to work it out automatically.
Given the number of energy credits a station uses per day, write a program that will calculate the day on which a mikoko tree should be snipped such that it will produce enough leaves to produce enough energy to power the station in question. The following stations have already issued requests:
- Zirros station: 56 credits per day
- Spaceship Iveinya: 12 credits per day
- Mining station Kira 4: 304 credits per day
- Spaceship Aheya: 2 credits per day
Helpful Hints
- It might help to draw it out on a whiteboard first. Make sure you've got your head around the problem before you start writing code.
- Don't be afraid to ask questions in the comments if there's something you don't understand! I'll be happy to help you.
- Make sure that you manually test your program to make sure that it gives the correct output. While your program might work with one input, it might not with another.
Challenge
The scientists have also found that you can plant 5 leaves together, and a new mikoko shoot will grow after 3 days. Alter your program so that it takes this into account when reporting the day that the mikoko trees should be snipped. Make your program also report the days on which leaves should be taken from the existing tree(s) and planted to create new trees.
As per last time, my solution can be found here, and the password will be released with the next challenge.
Update: The next post has been released! Find it here: Fiddly Fuel. The last post was Alien Encounter