Connell Sequence | C # code to generate first ' n ' terms of Connell Sequence ; Function to generate a fixed number of even or odd terms . The size of r decides whether numbers to be generated even or odd . ; Generating the first ' n ' terms of Connell Sequence ; A dummy 0 is inserted at the beginning for consistency ; Calling function gen ( ) to generate ' k ' number of terms ; Checking if ' n ' terms are already generated ; Removing the previously inserted dummy 0 ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < long > gen ( long n , List < long > r ) { long a = r [ r . Count - 1 ] ; a ++ ; for ( int i = 1 ; i <= n ; a += 2 , i ++ ) r . Add ( a ) ; return r ; } static List < long > conell ( long n ) { List < long > res = new List < long > ( ) ; long k = 1 ; res . Add ( 0 ) ; while ( true ) { res = gen ( k , res ) ; k ++ ; int j = res . Count - 1 ; while ( j != n && j + k > n ) k -- ; if ( j >= n ) break ; } res . RemoveAt ( 0 ) ; return res ; } static void Main ( ) { long n = 10 ; Console . WriteLine ( " The ▁ first ▁ " + n + " ▁ terms ▁ are " ) ; List < long > res = conell ( n ) ; for ( int i = 0 ; i < res . Count ; i ++ ) Console . Write ( res [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } }