Gould 's Sequence | Utility function to count odd numbers in ith row of Pascals 's triangle ; Initialize count as zero ; Return 2 ^ count ; Function to generate gould 's Sequence ; loop to generate gould 's Sequence up to n ; Get n ; Function call
< ? php function countOddNumber ( $ row_num ) { $ count = 0 ; while ( $ row_num ) { $ count += $ row_num & 1 ; $ row_num >>= 1 ; } return ( 1 << $ count ) ; } function gouldSequence ( $ n ) { for ( $ row_num = 0 ; $ row_num < $ n ; $ row_num ++ ) { echo countOddNumber ( $ row_num ) , " " ; } } $ n = 16 ; gouldSequence ( $ n ) ; ? >