Sector Nine

9.01 - return list[i];
9.02 - return list[0] + list[list.Length - 1];
9.03 -using System;
using System.Collections.Generic;
public class Program {
    public static bool Puzzle(int[] list, int i) {

return new List<int>(list).Contains(i);
}
}
9.04 -  using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
public static int[] Puzzle(int x) {
int[] v = Enumerable.Repeat(x, 10).ToArray();
return v;
}
}
thanks Darkstar
9.05 - int [] r = new int [n];
for(int i = 0; i < n; i++){
r[i] = i;
}
return r;
9.06 - bool [] r = new bool [10];
for(int i = 0; i < 10; i++){
r[i] = true;
}
return r;
9.07 -  string [] r = new string [s.Length];
for(int i = 0; i < s.Length; i++){
r[i] = s[i].ToString();
}
return r;
9.08 - int [] r = new int [i + 1];
for(int n = i, j = 0 ; n > 0; n--, j++){
r[j] = n;
}
return r;
9.09 - for(int i = 0; i < numbers.Length; i++){
numbers[i] = -numbers[i];
}
return numbers;
9.10 - Array.Reverse(numbers); return numbers;
9.11 - char[] c = s.ToCharArray();
          Array.reverse(c);
          return new string(c);
9.12 - for (int x = 0; x < amount; x++){
int t = numbers[numbers.Length - 1];
for (int i = numbers.Length - 1; i > 0; i--){
numbers[i] = numbers[i - 1];
}
        numbers[0] = t;
}
return numbers;
9.13 -  int r = 0;
r = numbers[i];
numbers[i] = numbers[j];
numbers[j] = r;
return numbers;
9.14 - int[] r = new int[a.Length];
if(a.Length >= b.Length){
r = new int [a.Length];
a.CopyTo(r, 0);
}
if(b.Length > a.Length){
r = new int [b.Length];
b.CopyTo(r, 0);
}
for(int i = 0; i < a.Length && i < b.Length ; i++){
r[i] = a[i] + b[i];
}
return r;

5 comments:

  1. <9.04>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    public class Program {
    public static int[] Puzzle(int x) {
    int[] v = Enumerable.Repeat(x, 10).ToArray();
    return v;
    }
    }

    ReplyDelete
  2. 9.06
    using System;
    public class Program {
    public static bool[] Puzzle() {
    return new bool[10] {true, true, true, true, true, true, true, true, true, true};
    }
    }

    ReplyDelete
  3. wrong answer to 9.03 and 9.11

    ReplyDelete
  4. 9.12 for 2 bricks
    int[] res = new int[numbers.Length];
    Array.ConstrainedCopy(numbers,numbers.Length-amount,res,0,amount);
    Array.ConstrainedCopy(numbers,0,res,amount,numbers.Length-amount);
    return res;

    ReplyDelete
  5. 9.05
    using System;
    using System.Collections.Generic;
    using System.Linq;
    public class Program {
    public static int[] Puzzle(int n) {
    return Enumerable.Range(0, n).ToArray();
    }
    }

    ReplyDelete