[Community Puzzle] A Bunny and Carrots

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @FBF_Luis,validated by @selenae,@UncleV and @anon65947109.
If you have any issues, feel free to ping them.

1 Like

I solved this puzzle 100% but clearly not in a single line as some of the best solutions. Could somebody please point me to the actual math that is involved the logic for the solution simply counting in a single list?

1 Like

I don’t think this problem is well defined when a whole row of carrots is gone, thus splitting the garden into multiple regions. The example code effectively fences each contiguous region separately, but there’s nothing in the statement to suggest that. It says region of carrots, not regions of carrots.

CXXXC could be fenced as:

 _       _
|C|X X X|C|
 -       -

with perimeter = 8, or as

 _ _ _ _ _
|C X X X C|
 - - - - -

with perimeter = 12

1 Like

Agreed, this should be expressed in the problem statement. My initial implementation assumed that a single contiguous perimeter was necessary and included a length of 2 for each empty column (as if an infinitely thin corrridor connected the nonempty regions of the garden together). As in:

 _ _ _ _ _
|C|X X X|C|
 -       -