计数发电机组【难度:1级】:
答案1:
public class Kata
{
public static double Powers(int[] array)
{
return System.Math.Pow(2.0, array.Length);
}
}
答案2:
using System;
public class Kata
{
public static double Powers(int[] list) =>
Math.Pow(2, list.Length);
}
答案3:
using System;
public class Kata
{
public static double Powers(int[] list)
{
return Math.Pow(2.0, list.Length);
}
}
答案4:
using System;
public class Kata
{
public static double Powers(int[] list)
{
var count = list.Length;
return Math.Pow(2, count);
}
}
答案5:
using System.Numerics;
using System;
public class Kata
{
public static double Powers(int[] list)
{
return Math.Pow(2,list.Length);
if(list.Length == 0)
return 1;
BigInteger output = 0;
for(int i = 0; i <= list.Length; i++)
output += Combination(list.Length, i);
return (double)output;
}
private static BigInteger Factorial(int i)
{
BigInteger output = 1;
BigInteger steps = i;
while(steps > 1)
{
output *= steps;
steps--;
}
return output;
}
private static BigInteger Combination(int i, int j)
{
BigInteger output = Factorial(i) / (Factorial(j) * Factorial(i-j));
return output;
}
}
答案6:
public class Kata
{
public static double Powers(int[] list)
{
double res = 1;
for (int i=0; i<list.Length; i++)
{
res *= 2;
}
return res;
}
}
答案7:
using System;
public class Kata
{
public static double Powers(int[] list)
{
if (list == null || list.Length == 0)
{
return 1;
}
return Math.Pow(2, list.Length);
}
}
答案8:
public class Kata
{
public static double Powers(int[] list)
{
return (double)System.Math.Pow(2, list.Length);
}
}
答案9:
using System;
using System.Linq;
public class Kata
{
public static double Powers(int[] list) =>
Math.Pow(2, list.Length);
}
答案10:
public class Kata
{
public static double Powers(int[] list) => System.Math.Pow(2, list.Length);
}