-
Notifications
You must be signed in to change notification settings - Fork 1
/
SecondPokerizer.cs
43 lines (39 loc) · 1.25 KB
/
SecondPokerizer.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
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace poker_estimator
{
internal class SecondPokerizer
{
public const long Day = 8 * 60 * 60;
private static readonly ImmutableList<decimal> PokerKeys =
new List<decimal> { (decimal) 0.5, 1, 2, 3, 5, 8, 13, 20, 40, 100 }
.ToImmutableList();
private static readonly ImmutableDictionary<ulong, string> PokerDictionary =
PokerKeys.ToImmutableDictionary(
key => (ulong)(key * Day),
key => key.ToString());
private readonly ulong? _seconds;
public SecondPokerizer(string seconds)
{
try
{
_seconds = ulong.Parse(seconds);
}
catch (Exception)
{
_seconds = null;
}
}
public string ToPokerDays()
{
var pokerKey = PokerDictionary.Keys
.Cast<ulong?>()
.Where(pokerValue => _seconds.HasValue && _seconds.Value <= pokerValue)
.DefaultIfEmpty(null)
.Min();
return pokerKey.HasValue ? PokerDictionary[pokerKey.Value] : "?";
}
}
}