From 34aa316cdbeb0e57f530089e366856b7f86b72cc Mon Sep 17 00:00:00 2001 From: Abigail Date: Sun, 15 Aug 2021 17:59:44 +0200 Subject: Fix calculation of diameter passing through root --- challenge-125/abigail/perl/ch-2.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-125/abigail/perl/ch-2.pl b/challenge-125/abigail/perl/ch-2.pl index 29d0c71c02..45806530f7 100644 --- a/challenge-125/abigail/perl/ch-2.pl +++ b/challenge-125/abigail/perl/ch-2.pl @@ -65,12 +65,12 @@ package Tree { # # Depth of a tree is 1 + max (depth left child, depth right child) # Diameter of a tree is max (diameter left child, - # diameter right child, 1 + depth left child + depth right child). + # diameter right child, depth left child + depth right child). # return (0, 0) unless $self; # Leaves have no depth nor diameter. my ($ldp, $ldm) = $self -> left -> _diameter; my ($rdp, $rdm) = $self -> right -> _diameter; - (max ($ldp, $rdp), max ($ldm, $rdm, 1 + $ldp + $rdp)) + (max ($ldp, $rdp), max ($ldm, $rdm, $ldp + $rdp)) } } -- cgit