[ create a new paste ] login | about

Link: http://codepad.org/lyTYadn7    [ raw code | output | fork ]

C, pasted on Jan 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

int f(int n){int m=0,l=0;n^=n<<1;for(;n;n>>=1,l++)if(n&1)m=l>m?l:m,l=0;return m;}

int main() {
	printf("%d->%d\n", 16, f(16)); // 4
	printf("%d->%d\n", 893, f(893)); // 5
	printf("%d->%d\n", 1337371, f(1337371)); // 6
	printf("%d->%d\n", 9965546, f(9965546)); // 7
	printf("%d->%d\n", 1672448, f(1672448)); // 8
	printf("%d->%d\n", 3326719, f(3326719)); // 8
	return 0;
}


Output:
1
2
3
4
5
6
16->4
893->5
1337371->6
9965546->7
1672448->8
3326719->8


Create a new paste based on this one


Comments: