Golomb sequence | Return the nth element of Golomb sequence ; base case ; Recursive Step ; Print the first n term of Golomb Sequence ; Finding first n terms of Golomb Sequence . ; Driver Code
function findGolomb ( n ) { if ( n == 1 ) return 1 ; return 1 + findGolomb ( n - findGolomb ( findGolomb ( n - 1 ) ) ) ; } function printGolomb ( n ) { for ( let i = 1 ; i <= n ; i ++ ) document . write ( findGolomb ( i ) + " " ) ; } var n = 9 ; printGolomb ( n ) ;