Advertisement
Guest User

Untitled

a guest
May 27th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. static decimal GetPrice(IEnumerable<Products> products, IDictionary<Products, decimal> prices)
  2.         {
  3.             var grouping = products.ToLookup(l => l);
  4.             var ab = FullSetCount(List(grouping[Products.A], grouping[Products.B])) * 0.1m;
  5.             var de = FullSetCount(List(grouping[Products.D], grouping[Products.E])) * 0.05m;
  6.             var efg = FullSetCount(List(grouping[Products.E], grouping[Products.F], grouping[Products.G])) * 0.05m;
  7.             var aAndklm = products
  8.                 .Where(p => p == Products.K || p == Products.L || p == Products.M)
  9.                 .Take(grouping[Products.A].Count())
  10.                 .Aggregate(0m, (acc, p) => acc + prices[p] * 0.05m);
  11.             decimal onCount;
  12.             switch (products.Except(List(Products.A, Products.B)).Count())
  13.             {
  14.                 case var c when c < 3:
  15.                     onCount = 1m;
  16.                     break;
  17.                 case 3:
  18.                     onCount = 0.95m;
  19.                     break;
  20.                 case 4:
  21.                     onCount = 0.90m;
  22.                     break;
  23.                 case var c when c >= 5:
  24.                     onCount = 0.95m;
  25.                     break;
  26.                 default:
  27.                     onCount = 1m;
  28.                     break;
  29.             }
  30.  
  31.             var initalSum = products.Sum(p => prices[p]);
  32.             var result = (initalSum - ab - de - efg - aAndklm) * onCount;
  33.             return result;
  34.         }
  35.  
  36.         static int FullSetCount<T>(params IEnumerable<T>[] cols)
  37.         {
  38.             return cols.Select(c => c.Count()).Min();
  39.         }
  40.  
  41.         static IEnumerable<T> List<T>(params T[] items) => items;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement