Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[PROG CHALLENGE #024] Non-Corporate Edition

Name: Anonymous 2020-01-13 16:05

Write a function:

int solution(int N);

that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.

Name: Anonymous 2020-01-15 7:15

>>43
1.Bingap functions operate with unsigned ints.
2.only 5bits are needed to store 32bit binary gap which is 6.4 times less than int(32).
3.calculating int_max binary gaps each time the program starts negates any performance benefits.
4.hardware with less than 8GB will either swap to disk or crash.
5.Uncached RAM access will cause cache flushes as you attempt to read random values from the array.
https://stackoverflow.com/questions/1756825/how-can-i-do-a-cpu-cache-flush-in-x86-windows "The wbinvd instruction takes on the order of 2000-5000 clock cycles to complete!"

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List