Magical Duplication Tree
Description:
Story (skippable):
Once upon a time, a farmer came across a magic seed shop. Once inside, the salesman sold him a pack of magical trees. Before leaving, the salesman gave him a warning:
"These are no ordinary trees, farmer. These trees split up into smaller, further dividing duplicate trees with each passing day," The salesperson said.
The farmer returned home with his purchase and decided to clear a patch of land for the new crop. He planted one down in the middle of his field. Upon returning the next day, the farmer was greeted by two slightly smaller trees in place of the original tree, as promised.
The farmer got both very excited and very nervous. He realized he had an easy way to turn a profit. That was great news for him! But he also figured he had no idea of how to predict and report what his profits would be.
The farmer needs your help coding a function that can return what the field will look like after a certain number of days.
Task:
You are given a multi-line string p_field
containing a single magic tree that recursively divides itself into a split
number of shorter copies every day. Return the p_field after n
days. The tree's splitting decreases its height by one |
each generation.
Only valid tree's will be asked for, there will be no asking for splitting for more days than possible.
WARNING: These fields can get BIG!!! Make sure your code runs efficiently.
Example:
The following is the start of a p_field
with a split
value of 2
:
o
|
|
|
On day 1, the field will look like this:
oo
||
||
The next day, the field would grow to this:
oooo
||||
In 3 days, which is the maximum possible n
value for this example,
the field will look like this:
oooooooo
If n
is 2, your function needs to return the third p_field
displayed and return the fourth example if n
was 3.
If split
is 3, the function instead returns ooooooooooooooooooooooooooo
on the third day. (1 => 3 => 9 => 27)
Similar Kata:
Stats:
Created | Oct 2, 2022 |
Published | Oct 7, 2022 |
Warriors Trained | 312 |
Total Skips | 0 |
Total Code Submissions | 302 |
Total Times Completed | 112 |
Python Completions | 112 |
Total Stars | 6 |
% of votes with a positive feedback rating | 84% of 31 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 8 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |