|
@@ -7,7 +7,7 @@ public class WellRecord
|
|
|
private readonly string _record;
|
|
private readonly string _record;
|
|
|
private readonly int[] _checksum;
|
|
private readonly int[] _checksum;
|
|
|
|
|
|
|
|
- private static readonly Dictionary<string, long> MemoMap = new Dictionary<string, long>();
|
|
|
|
|
|
|
+ public static readonly Dictionary<string, long> MemoMap = new Dictionary<string, long>();
|
|
|
|
|
|
|
|
public WellRecord(string record, int[] checksum)
|
|
public WellRecord(string record, int[] checksum)
|
|
|
{
|
|
{
|
|
@@ -15,14 +15,13 @@ public class WellRecord
|
|
|
_checksum = checksum;
|
|
_checksum = checksum;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void Print()
|
|
|
|
|
|
|
+ public long Count(int multiply)
|
|
|
{
|
|
{
|
|
|
- Console.WriteLine($"{_record} => {string.Join(", ", _checksum)}");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public long Count()
|
|
|
|
|
- {
|
|
|
|
|
- return CountPermuations(_record, _checksum);
|
|
|
|
|
|
|
+ var input = string.Join("?", Enumerable.Repeat(_record, multiply));
|
|
|
|
|
+ var values = Enumerable.Repeat(_checksum, multiply).SelectMany(x => x).ToArray();
|
|
|
|
|
+
|
|
|
|
|
+ Console.WriteLine($"{input} => {string.Join(", ", values)}");
|
|
|
|
|
+ return CountPermuations(input, values);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private long CountPermuations(string tail, int[] values)
|
|
private long CountPermuations(string tail, int[] values)
|
|
@@ -30,7 +29,6 @@ public class WellRecord
|
|
|
var key = Key(tail, values);
|
|
var key = Key(tail, values);
|
|
|
if (MemoMap.TryGetValue(key, out long count))
|
|
if (MemoMap.TryGetValue(key, out long count))
|
|
|
{
|
|
{
|
|
|
- Console.WriteLine($"Memoized {key}: {count}");
|
|
|
|
|
return count;
|
|
return count;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -67,7 +65,6 @@ public class WellRecord
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var result = dotCount + hashCount;
|
|
var result = dotCount + hashCount;
|
|
|
- Console.WriteLine($"Computed {key}: {result}");
|
|
|
|
|
MemoMap[key] = result;
|
|
MemoMap[key] = result;
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|