-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKataPotter.cs
57 lines (44 loc) · 1.38 KB
/
KataPotter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KataPotter
{
public static class KataPotter
{
private static Dictionary<int, double> remises = new Dictionary<int, double>();
private static double defaultPriceBook = 8;
public static double getPrices(int[] books)
{
remises = remises.Count == 0 ? InitRemise() : remises;
return books.Count() != 0 ? getPricesBook(books) : 0;
}
private static double getPricesBook(int[] books)
{
if (books.Count() == 1)
{
return defaultPriceBook;
}
var price = 0.0;
double remise;
remises.TryGetValue(books.Distinct().Count(), out remise);
price = books.Distinct().Count() * defaultPriceBook * remise;
var dif = books.Count() - books.Distinct().Count();
if (dif > 0)
{
price += dif * defaultPriceBook;
}
return price;
}
private static Dictionary<int, double> InitRemise()
{
remises.Add(1, 1);
remises.Add(2, 0.95);
remises.Add(3, 0.90);
remises.Add(4, 0.80);
remises.Add(5, 0.75);
return remises;
}
}
}