Number of different cyclic paths of length N in a tetrahedron | Function to count the number of steps in a tetrahedron ; initially coming to B is B -> B ; cannot reach A , D or C ; iterate for all steps ; recurrence relation ; memoize previous values ; returns steps ; Driver Code
< ? php function countPaths ( $ n ) { $ zB = 1 ; $ zADC = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ nzB = $ zADC * 3 ; $ nzADC = ( $ zADC * 2 + $ zB ) ; $ zB = $ nzB ; $ zADC = $ nzADC ; } return $ zB ; } $ n = 3 ; echo countPaths ( $ n ) ; ? >