Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions problem-solving/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,90 @@ static void Main(string[] args)
{
}

public static long Sum(IEnumerable<int> numbers)
{
int value = 0;
long sum = 0;
for (int i = 0; i < numbers.Count(); i++)
{
value = numbers.ElementAt(i);
sum = sum + value;

}
return sum;
}
public static long SumArray(IEnumerable<int> arr)
{
// return the sum of all the values in the array
// TODO
return 0;
//int value = 0;
//long sum = 0;
//for (int i = 0; i < arr.Count(); i++)
//{
// value = arr.ElementAt(i);
// sum = sum + value;

//}

return Sum(arr);
}

public static bool IsOdd(int value)
{
return value % 2 != 0;
}
public static long SumArrayOddValues(IEnumerable<int> arr)
{
// return the sum of all the values in the array that are odd
// TODO
return 0;
int value = 0;
long sum = 0;
for (int i = 0; i < arr.Count(); i++)
{
value = arr.ElementAt(i);
if(IsOdd(value))
sum = sum + value;

}
return sum;
}

public static long SumArrayEverySecondValue(IEnumerable<int> arr)
{
// return the sum of every second value in the array. i.e. the 2nd value + the 4th value + the 6th value ...
// TODO
return 0;
int value = 0;
long sum = 0;
int count = arr.Count();
for (int i = 0; i < count; i++)
{
if(i<=count-2)
{
value = arr.ElementAt(++i);
sum = sum + value;
}

}
return sum;

}

public static IEnumerable<int> GetUniqueValues(IEnumerable<int> arr)
{
// return an array that contains only unique values from the passed in array
// TODO
return null;



return arr.Distinct();
}

public static IEnumerable<int> GetArrayIntersect(IEnumerable<int> arrA, IEnumerable<int> arrB)
{
// return an array that contains all the values that are in array A and array B
// TODO
return null;

return arrA.Intersect(arrB);
}

public static IEnumerable<int> GetArrayNotIntersect(IEnumerable<int> arrA, IEnumerable<int> arrB)
Expand Down