Anticipa.....

As the clock winds down towards the end of the challenge, more people have solved the reverse challenge using 5 characters. Nearly 20 hours worth of searching has not yielded the answer to me and after about 100 tries, the best I can do is finish with 32 characters total. That's 13 characters coded for those not keeping track.

The challenge is actually asking for the first bit set in the given <int> k. So for example:
The number 1073741824 in binary is :‭01000000000000000000000000000000‬. If you count, from the right, the first bit set is 31. Hence the answer, 31.

1 = 0001 = 1
2 = 0010 = 2
23 = 0001 0111 = 1

And so on. After scouring the interwebs and cplusplus.com/reference I found a little function called ffs() or Find First Set. This function finds the first bit 0-1 set (meaning turned on or 1) and returns the position.

So my grand solution:

return ffs(k);

Easy, peasy, lemon squeezey.

The shortest solution:

int(*rightGuy)(int) = ffs; WOW!

After I figure out how this works I'll post the break down of this super code!

Comments

Popular posts from this blog

What's For Lunch App!