Print N terms of Withoff Sequence | Python3 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
import math NEW_LINE def Wythoff ( mp , n , k ) : NEW_LINE INDENT tau = ( math . sqrt ( 5 ) + 1 ) / 2 NEW_LINE t_n_k = 0 NEW_LINE if ( ( n in mp ) and ( k in mp [ n ] ) ) : NEW_LINE INDENT return mp [ n ] [ k ] ; NEW_LINE DEDENT if ( k == - 1 ) : NEW_LINE INDENT return n - 1 ; NEW_LINE DEDENT elif ( k == 0 ) : NEW_LINE INDENT t_n_k = math . floor ( n * tau ) ; NEW_LINE DEDENT else : NEW_LINE INDENT t_n_k = Wythoff ( mp , n , k - 1 ) + Wythoff ( mp , n , k - 2 ) NEW_LINE DEDENT if n not in mp : NEW_LINE INDENT mp [ n ] = dict ( ) NEW_LINE DEDENT mp [ n ] [ k ] = t_n_k ; NEW_LINE return int ( t_n_k ) NEW_LINE DEDENT def Wythoff_Array ( n ) : NEW_LINE INDENT i = 0 NEW_LINE j = 0 NEW_LINE count = 0 ; NEW_LINE mp = dict ( ) NEW_LINE while ( count < n ) : NEW_LINE INDENT print ( Wythoff ( mp , i + 1 , j + 1 ) , end = ' ' ) NEW_LINE count += 1 NEW_LINE if ( count != n ) : NEW_LINE INDENT print ( " , ▁ " , end = ' ' ) NEW_LINE DEDENT i += 1 NEW_LINE j -= 1 NEW_LINE if ( j < 0 ) : NEW_LINE INDENT j = i ; NEW_LINE i = 0 ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 15 ; NEW_LINE Wythoff_Array ( n ) ; NEW_LINE DEDENT