Sector Fourteen

14.01 - return x * (x + 1) / 2;
14.02 - return (x * ((x*x) + 1)) / 2;
14.03 - i don't know
14.04 - i have no idea
14.05 - using System;
using System.Linq;
public class Program {
    public static int Puzzle(int[] list) {
        return list.Distinct().Count();
    }
}
14.06 - using System;
using System.Linq;
public class Program {
    public static int[] Puzzle(int[] list) {
        return list.Distinct().ToArray();
    }
}
14.07 - using System;
using System.Linq;
public class Program {
    public static bool Puzzle(string s) {
char[] arr = s.ToCharArray();
Array.Reverse(arr);
string r = new string(arr);
return s==r;
      
    }
}
14.08 - char[] arr = a.ToCharArray();
Array.Reverse(arr);
string r = new string(arr);
if(a == b || r == b){
return true;
}
return false;
14.09 - if(yintercept1==yintercept2 && slope1==slope2){
return "same line";
}
if(slope1==slope2){
return "parallel lines";
}
float yint1 = yintercept1;
float yint2 = yintercept2;
float x = 0;
float y = 0;
float slope3 = 0;
float yint3 = 0;
string r = "";
slope3 = slope1 - slope2;
yint3  = yint1 - yint2;
x = (yint3 * -1) / slope3;
y = (slope1 * x) + yint1;
r = "(" + x + ", " + y +")";
return r;

1 comment:

  1. 14.04 - may work ?

    using System;
    public class Program {
    public static string Puzzle(string s) {
    char[] cc = s.ToCharArray();
    string result = string.Empty;
    if (s.Length%2 == 0)
    {
    for (int j = 0; j < cc.Length/2; j++)
    {
    result += Convert.ToChar((Convert.ToInt32(cc[2*j]) + Convert.ToInt32(cc[2*j+1])) / 2);
    }
    }
    else
    {
    for (int j = 0; j < cc.Length/2; j++)
    {
    result += Convert.ToChar((Convert.ToInt32(cc[2*j]) + Convert.ToInt32(cc[2*j+1])) / 2);
    }
    result += cc[cc.Length - 1];
    }
    return result;
    }
    }

    ReplyDelete