Code Hunt (Microsoft Research)

这两天看见 codehunt.com 这个网页编码‘小游戏’还不错,玩儿了玩儿,顺便学习C#

00 TRAINING

00.02:

(3星)

x+1


00.03:

(3星)

x<<1;


00.04:

(3)

x+y;


01 ARITHMETIC

01.01:

(3)

-x;


01.02:

(3)

x-2


01.03:

(3)

x*x


01.04:

(3)

3*x;


01.05:

(3)

x/3;


01.06:

(3)

4/x;


01.07:

(3)

x-y;


01.08:

(3)

x+(y<<1);


01.09:

(3)

x*y;


01.10:

(3)

x+y/3;


01.11:

(3)

x/y


01.12:

(3)

x%3;


01.13:

(3)

x%3+1;


01.14:

(3)

10/x;


01.15:

(3)

(x+y+z)/3;



02 LOOPS

02.01:

(SKILL 3星)

Enumerable.Range(0, n).ToArray();


02.02:

(3)

  int [] answer = new int [n];
  for (int i=0; i<n; i++) {
   answer[i] = (i*n);
  }


02.03:

(2)

Enumerable.Select(Enumerable.Range(0, n), x => x * x).ToArray();


02.04:

(3)

v.Aggregate((a, b) => a + b);


02.05:

(3)

n*(n-1)*(2*n-1)/6;


02.06:

(2)

s.Count(x => x == 'a');


02.07:

(2)

int counter = 0;
  foreach (char c in s) {
   if (c == x)
    counter++;
  }
  return counter;


03 LOOPS 2

03.01:

(2星)

if (power == 0) return 1;
  return number*Puzzle(number, power-1);

(2星)

   int ans = 1;
   while (power > 0) {
    ans *= number;
    power--;
   }
   return ans;


03.02:

(3)

int ans = 1;
  while (i > 1) {
   ans *= i;
   i--;
  }
  return ans;


03.03:

(3)

int ans = 1;
  for (int i=lowerBound; i<=upperBound; i++)
   ans *= i;
  return ans;


03.04:

(3)

if (n <= 0)
   return 0;
  n = (n-1)/2;
  return n*(n+1);


03.05:

(3)

return (n*(n+1)*(2*n+1)+3*(n+1)*n)/12;


03.06:

(3)

return System.Text.RegularExpressions.Regex.Replace(word, ".", "_ ").Trim();

(3)

return String.Join(" ", Enumerable.Repeat("_", word.Length).ToArray());


 03.07:

(3)

char[] c = new char[s.Length];
        for (int i=0; i<c.Length; i++) {
   c[i] = (char)((s[i]-'a'+'f'-'a')%26+'a');
  }
        return new string(c);



03.08:

(3)

return (x+"").Length;



04 CONDITIONALS


(to be continued...)





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值