28.0k views
1 vote
Implement a function called myFilter that does the following: Takes a sequence of integers with values from 0 to 100 Remove all multiples of 6 less than 42 Then square each number Finally, remove any resulting integer that is odd public class Problem2 { public static IEnumerable myFilter(IEnumerable input) { } } static void Main(string[] args)

1 Answer

6 votes

Answer:

using System;

using System.Collections.Generic;

using System.Linq;

public class Problem1 {

public static IEnumerable < int > myFilter(IEnumerable < int > input) {

return input.Where((val, index) => {

//First remove all multiples of 6 less than 42

return !(val % 6 == 0 && val < 42);

}).Select((val, index) => {

//Then square each number

return val * val;

}).Where((val, index) => {

// Finally, remove any resulting integer that is odd

return !(val % 1 == 0);

});

}

public static void Main(string[] args) {

Random rnd = new Random(5);

//Takes a sequence of integers with values from 0 to 100

var listForProblem = Enumerable.Range(1, 100).Select(i => rnd.Next() % 101);

var answer = Problem1.myFilter(listForProblem);

foreach(int i in answer) {

Console.WriteLine(i);

}

}

}

Step-by-step explanation:

The Problem 1 solution is explanatory enough.

Your problem 2 question is lacking details. However, i have written a code that sorts it.

User Maxim Imakaev
by
5.0k points