5 Character Function!

I just finished my first "Author Challenge" on Code Fights. This was a "reverse challenge" where you are given the function signature (int function (int x)) and a list of sample tests. The challenge is to find out what the Author is looking for. What's the problem, what's the solution? Also, try and solve it in as little characters as possible.

I figured it out in 92 characters and thought I was pretty smart. The solution was to find out how many times a number was divisible by 2 evenly, I think. Anything under 10 (0-9) needed to be returned. So my final code:

int rightGuy (int k)
{
   int counter = 0;
   if (k < 10)
      return k;
   while (k % 2 == 0)
   {
      k  /=  k / 2;
      counter++;
   }
   return counter;
}

There it is in all of it's beauty! 92 characters that resolved the problem. I got my 1000 gold coins, a badge, and some XP! Then I went to the solution board and found that I was the 20th ranked C++ coder, and the 100th ranked overall coder. Nice! Who is number 1 though? A C++ coder who solved it in 5 CHARACTERS!

int rightGuy (int k)
{
   5 CHARACTERS HERE;
}

I spent the next hour looking for a solution that might fit a 5 character function. I looked through all of the Standard Libraries and tried to think of how to convert my solution into a 5 CHARACTER equation! No dice.

I guess I'll have to wait another 23 hours to see how he solved that one! Congrats to him. I'm looking forward to seeing his solution!

Comments

Popular posts from this blog

What's For Lunch App!