module Solutions.P71 (internalPathLength) where
import Problems.MultiwayTrees
internalPathLength :: MultiwayTree a -> Int
internalPathLength :: forall a. MultiwayTree a -> Int
internalPathLength = Int -> MultiwayTree a -> Int
forall a. Int -> MultiwayTree a -> Int
internalPathLength' Int
0
internalPathLength' :: Int -> MultiwayTree a -> Int
internalPathLength' :: forall a. Int -> MultiwayTree a -> Int
internalPathLength' Int
l (MultiwayTree a
_ []) = Int
l
internalPathLength' Int
l (MultiwayTree a
_ [MultiwayTree a]
ts) = Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) Int
l (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (MultiwayTree a -> Int) -> [MultiwayTree a] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> MultiwayTree a -> Int
forall a. Int -> MultiwayTree a -> Int
internalPathLength' (Int -> MultiwayTree a -> Int) -> Int -> MultiwayTree a -> Int
forall a b. (a -> b) -> a -> b
$ Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) [MultiwayTree a]
ts