0

I tried to solve Level 03.03 in Code Hunt. But, as I found no solution, I got this code line from the internet.

public static int Puzzle(int lowerBound, int upperBound)
{
    return lowerBound == upperBound ? upperBound : (upperBound * Puzzle(lowerBound,upperBound - 1));
}

The solutions are:

lowerBound      upperBound      EXPECTED RESULT
1               8               40320
15              24              244963328
16              17              272

Does anyone has an idea for, what is meant with this code? I just don't get it.

Mehdi Khademloo
  • 2,754
  • 2
  • 20
  • 40
Matt126
  • 997
  • 11
  • 25

1 Answers1

2
if(lowerBound == upperBound)
{
     return upperBound;
}
else
{
    return (upperBound * Puzzle(lowerBound,upperBound - 1));
}

You can read about condition operator here: http://msdn.microsoft.com/en-us/library/ty67wk28.aspx

mybirthname
  • 17,949
  • 3
  • 31
  • 55