[Community Puzzle] Tiny Forest

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @AdrienLB,validated by @Timinator,@lllllllllllllllllll1 and @FredericLocquet.
If you have any issues, feel free to ping them.

Hi there,

I just finished this tiny forest puzzle, and my first impression is that there are missing test cases.
To cover more cases that help understand the logic behind this puzzle you could add this test case:

one-tree-2
Input:

5
5
. . . . .
. . . . .
. . Y . .
. . . . .
. . . . .

Expected Output:

23

This one shows that the seed could be placed under a space occupied by ā€œa tree when you donā€™t plant the initial seedā€.

It may seems like a corner case, but my initial solution passed all existing test cases but failed 2 validators. It goes without saying that it was not hard-coded :slight_smile:

1 Like

@AdrienLB Did you have a look :slight_smile: ?

The author is last seen on the forum around 2 months ago, so they probably havenā€™t read your messageā€¦

Could any approver @Timinator,@lllllllllllllllllll1 and @FredericLocquet take a look?

What language did you write your initial solution in? Is it published? Iā€™d like to explore this a bit more with you and see how your solution can pass all test cases, but not all validators.

Letā€™s assume we have your 5x5 plot of land with one tree already on the middle spot. Even if you donā€™t plant any seed at all, the resulting forest will cover the entire 5x5 plot except for the four corners. A single seed placed in the middle row or the middle column on a 5x5 plot of land will produce a pattern that will cover the two closest corners, but not the two distant corners. So, yes, I believe your proposed test case is accurate. However, I need help understanding what situation is covered by this test case that is not covered in the existing test cases?

Hey @Timinator thank you for looking into this :slight_smile: !
My solution is published, in Rust.

I also have the code that passes all tests but not the all validators.
Can we discuss the solution here without spoiling people or should we take it elsewhere ?

ps: @5DN1L thanks for the heads up

1 Like

I will send you a PM where you can share your code privately.

Hello, sorry I didnā€™t know this forum part existed, I havenā€™t had notifications before.
I will look at your problem asap !! :slight_smile:

I donā€™t think there are any notification on the website, which is a shame !
There are only email notifications :confused:

Did I miss something? Are we going to look at the code that passes all test cases but not all validators? I never saw any code. I miss things all the time, so I might just need to be pointed in the right direction.

Sorry, I was in the process of answering you yesterday, and got taken in by some code :sweat_smile:
You have the code in PM, and I added @AdrienLB to the discussion.

1 Like

I will answer there too :
I executed your code.
I didnā€™t read and understand your code, donā€™t know rust, but I think I donā€™t need.
The output is somewhat clear, you are doing a simple run without planting seed and then you determine what is the best place from the places left.


YEAR 33
,Y,Y,Y,
Y,Y,Y,Y,Y
Y,Y,Y,Y,Y
Y,Y,Y,Y,Y
,Y,Y,Y,


YEAR 0
X, , , ,
, , , ,
, ,Y, ,
, , , ,
, , , ,

Like above you put the seed in the corner, to fill one of the four empty spaces, but if you put it at equal distance from two empty spot it will cover in the end two corner not one.
Solution should be:
, , X , ,
, , , ,
, ,Y, ,
, , , ,
, , , ,
So you will have one more tree in the end.
I have added a testcase
Thank you @OoLaVache for pointing this problem
Thank you @Timinator for asking for the code

Tell me if everything is ok now :slight_smile:

I need some time to implement the difficult version of this puzzle, but diablo4 just went out, so later xD

1 Like

The new test case correctly failed with my code that wasnā€™t passing the validators.
Thank you for adding it :hugs:

1 Like

Great puzzle, but the instructions need minor clarification.

You say that ā€œseeds need 10 years to grow into a treeā€. This can only mean that a seed that is less than ten years old is not a tree.

The task is to ā€œfind the maximum number of trees after 33 years you can have by planting the seed at the best placeā€. From the first statement, one can only conclude that seeds less than 10 years old at the 33rd year should not be counted as trees for this purpose.

Only from running the test cases does it becomes clear that your intent was to say that ā€œA seed is counted as a tree, but does not produce more seeds for 10 years after it is planted or dropped by a parent tree.ā€

1 Like

Actually, i hv also tried to solve it. During its solving , i just wanted to know how to determine seeds nd trees specific positions over the iterations.

[nope]
pfa(attached_proof):

Hello,

Sorry I didnā€™t understand what is your issue, and what you are trying to do, can you explain it again if you still have issues?

Regards,

Thank you for your comment and sorry for the late answer I will fix it

@sammck I was correcting it but was not really sure, after investigating there is nothing to change
In the main example we can see there is 21 trees and the seeds ā€œXā€ are not counted in it.
A seed transforms in a tree after 10 years. It is not a tree until then.

Which testcases make you think otherwise?

1 Like

Itā€™s been a long time and I donā€™t clearly remember this issue, but I think the issue is this: In the main example, after 33 years the correct answer is that there are 21 trees and 2 seeds, as your example shows. However, some of those 21 trees are aged 1-9 years. Since you say ā€œseeds need 10 years to grow into a treeā€, I felt that it is misleading to consider a ā€œsaplingā€ aged 1-9 years to be a ā€œtreeā€.

In my solution I have :

if( MAP_Tiles[i][j].val == ā€˜Xā€™ )
{
if( MAP_Tiles[i][j].grow == 10 )
{
MAP_Tiles[i][j].val = ā€˜Yā€™;

So all 21 trees ā€œYā€ you see in the first example are seeds aged of 10+ years so trees.
I can rephrase as :
-After 10 years a seed is matured enough to be considered as a Tree.
Is it better?

1 Like