I think I looked at this for too long. I have some data that look like this:
@a = (
{ name => 'ethan', depth => 0 },
{ name => 'victoria', depth => 1 },
{ name => 'stephen', depth => 2 },
{ name => 'christopher', depth => 3 },
{ name => 'isabella', depth => 2 },
{ name => 'ethan', depth => 3 },
{ name => 'emma', depth => 0 },
{ name => 'michael', depth => 1 },
{ name => 'olivia', depth => 2 },
{ name => 'alexander', depth => 3 },
{ name => 'stephen', depth => 1 },
{ name => 'sophia', depth => 0 },
{ name => 'michael', depth => 1 },
{ name => 'ava', depth => 1 },
{ name => 'joshua', depth => 2 }
);
This is a simple tree data structure. Each time "depth" = 0, this is the beginning of a new "tree". What I would like to know is how many of these trees appear in each of the names? The desired result would be a single hash with names as a key, and a counter as a value.
Kink in this case, if you look carefully, the first tree contains the name "ethane" twice. Any tree can have any name more than once, but this should be considered only 1, since they all occur in the same tree. However, Michael will have a score of 2, as he appears in two different trees.
, . , - .