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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Wythoff ( map < int , map < int , int > > & mp , int n , int k ) { double tau = ( sqrt ( 5 ) + 1 ) / 2.0 , t_n_k ; if ( mp [ n ] [ k ] != 0 ) return mp [ n ] [ k ] ; if ( k == -1 ) { return n - 1 ; } else if ( k == 0 ) { t_n_k = floor ( n * tau ) ; } else { t_n_k = Wythoff ( mp , n , k - 1 ) + Wythoff ( mp , n , k - 2 ) ; } mp [ n ] [ k ] = t_n_k ; return ( int ) t_n_k ; } void Wythoff_Array ( int n ) { int i = 0 , j = 0 , count = 0 ; map < int , map < int , int > > mp ; while ( count < n ) { cout << Wythoff ( mp , i + 1 , j + 1 ) ; count ++ ; if ( count != n ) cout << " , ▁ " ; i ++ ; j -- ; if ( j < 0 ) { j = i ; i = 0 ; } } } int main ( ) { int n = 15 ; Wythoff_Array ( n ) ; return 0 ; }