Sector Three

3.01 - int r = 1;
   for(int i = 0; i < power; i++){
   r = r *number;
   }
 return r;
3.02 - int r = 1;
for(int a = i; a > 0  ;a-- ){
r = r * a;
}
return r;
3.03 - int r = 1;
for(int i = lowerBound; i <= upperBound; i++){
r = r*i;
}
return r;
3.04 - //UPDATED//
return n < 0 ? 0 : ((n - 1) / 2) * ((n + 1) / 2);
3.05 - int r = 0;
for(int i = 0; i <= upperBound; i++){
for(int a = 0; a < i; a++){
r += a;
}
r += i;
}
return r;
3.06 - string r = "";
for(int i = 0; i <  word.Length; i++){
if (i == word.Length - 1)
  r = r + "_";
else
r = r + "_ ";
}


return r;
3.07 - int m = 5;
   char[] c = new char[s.Length];
   for(int i = 0; i < s.Length; i++)
   c[i] = (char)((s[i] + m - (int)'a') % 26 + (int)'a');
   return new String(c);
3.08 - string r = "";
 r = x.ToString(r);
return r.Length;

3 comments:

  1. You can actually solve 3.04 without a loop:

    return n < 0 ? 0 : ((n - 1) / 2) * ((n + 1) / 2);

    And it counts as 3 point solution.

    ReplyDelete
  2. How is it possible to get 3 points on 3.01?

    ReplyDelete
  3. 3.01 (int)(long)Math.Pow(number, power)
    3.02 (i == 0) ? 1 : i * Puzzle(i-1)
    3.03
    int product = 1;
    for (int i = lowerBound; i <= upperBound; ++i) {
    product *= i;
    }
    return product;
    3.04 (n <= 0) ? 0 : (n+1)/2*((n+1)/2-1)
    3.05 upperBound*(upperBound+1)*(upperBound+2)/6
    3.06 string.Join(" ", (new string('_', word.Length)).AsEnumerable())
    3.07 string.Join("",s.Select(c => (char)((c > 117) ? (c - 21) : (c + 5))))
    3.08 Enumerable.Count(Convert.ToString(x))

    ReplyDelete