Example #1
0
 static Func<int, int> ChooseOperation(ITalkToUser ui)
 {
     var operation = ui.Ask("choose operation");
     if( operation == "syracuse" )
     {
         var rank = int.Parse(ui.Ask("rank"));
         return i => SyracuseSequence(i).ElementAt(rank-1);
     }
     else if( operation == "integer sum" )
     {
         return i => i*(i+1)/2;
     }
     else
     {
         return i => i*i;
     }
 }
Example #2
0
 static Func<IEnumerable<int>, IEnumerable<int>> ChooseFilter(ITalkToUser ui)
 {
     var filter = ui.Ask("choose filter");
     if( filter == "odd under" )
     {
         var maxValue = int.Parse(ui.Ask("max value"));
         return e => e.TakeWhile( n => n <= maxValue ).Where( n => n%2==1 );
     }
     else if( filter == "under" )
     {
         var maxValue = int.Parse(ui.Ask("max value"));
         return e => e.TakeWhile( n => n <= maxValue );
     }
     else
     {
         var numberOfItems = int.Parse(ui.Ask("number of items"));
         return e => e.Take(numberOfItems);
     }
 }