Print N terms of Withoff Sequence | C # program to find Wythoff array ; Function to find the n , k term of Wythoff array ; tau = ( sqrt ( 5 ) + 1 ) / 2 ; Already_stored ; T ( n , - 1 ) = n - 1. ; T ( n , 0 ) = floor ( n * tau ) . ; T ( n , k ) = T ( n , k - 1 ) + T ( n , k - 2 ) for k >= 1. ; Store ; Return the ans ; Function to find first n terms of Wythoff array by traversing in anti - diagonal ; Map to store the Wythoff array ; Anti diagonal ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int Wythoff ( Dictionary < int , Dictionary < int , int > > mp , int n , int k ) { double tau = ( Math . Sqrt ( 5 ) + 1 ) / 2.0 , t_n_k ; if ( mp . ContainsKey ( n ) && mp [ n ] . ContainsKey ( k ) && mp [ n ] [ k ] != 0 ) return mp [ n ] [ k ] ; if ( k == - 1 ) { return n - 1 ; } else if ( k == 0 ) { t_n_k = Math . Floor ( n * tau ) ; } else { t_n_k = Wythoff ( mp , n , k - 1 ) + Wythoff ( mp , n , k - 2 ) ; } if ( ! mp . ContainsKey ( n ) ) { mp [ n ] = new Dictionary < int , int > ( ) ; } mp [ n ] [ k ] = ( int ) t_n_k ; return ( int ) t_n_k ; } static void Wythoff_Array ( int n ) { int i = 0 , j = 0 , count = 0 ; Dictionary < int , Dictionary < int , int > > mp = new Dictionary < int , Dictionary < int , int > > ( ) ; while ( count < n ) { Console . Write ( Wythoff ( mp , i + 1 , j + 1 ) ) ; count ++ ; if ( count != n ) Console . Write ( " , ▁ " ) ; i ++ ; j -- ; if ( j < 0 ) { j = i ; i = 0 ; } } } static void Main ( ) { int n = 15 ; Wythoff_Array ( n ) ; } }