-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
68 lines (59 loc) · 2.04 KB
/
Utils.cs
File metadata and controls
68 lines (59 loc) · 2.04 KB
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
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2016
{
static class Utils
{
public static IEnumerable<string> splitLines(string input)
{
return input.Replace("\r", "").Split('\n').Select(l => l.Trim());
}
public static void Test(Func<dynamic, string> method, dynamic input, string output)
{
Test(method, new dynamic[] { input }, new string[] { output });
}
public static void Test(Func<dynamic, string> method, dynamic[] inputs, string[] outputs)
{
for (int i = 0; i < inputs.Length; i++)
{
var actual = method(inputs[i]);
Console.Write(inputs[i] + " -> " + actual);
if (actual == outputs[i])
{
WriteLine(" : OK", ConsoleColor.Green);
}
else
{
WriteLine(" : WRONG. Should be " + outputs[i], ConsoleColor.Red);
}
}
}
static MD5 md5 = System.Security.Cryptography.MD5.Create();
public static string MD5(string input)
{
return BitConverter.ToString(md5.ComputeHash(Encoding.ASCII.GetBytes(input))).Replace("-", "").ToLower();
}
public static void WriteLine(string msg, ConsoleColor color)
{
Console.WriteLine();
var old = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(msg);
Console.ForegroundColor = old;
}
public static void ClearLine()
{
Console.Write(new string(' ', Console.WindowWidth));
Console.CursorLeft = 0;
}
public static void WriteTransient(string msg)
{
Console.Write(msg);
Console.CursorLeft = 0;
}
}
}