Skip to content

Instantly share code, notes, and snippets.

@stackia
Created July 1, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stackia/664fe5eb134fa4ec90e00543217bc320 to your computer and use it in GitHub Desktop.
Save stackia/664fe5eb134fa4ec90e00543217bc320 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication4
{
public static class Program
{
public static void Main(string[] args)
{
// 见 Decode 方法
}
public static List<ResultItem> Decode(string mode, string input)
{
Func<string, List<ResultItem>> process = a =>
{
var cc = new List<ResultItem>();
Func<char, int> ee =
aa => aa >= '0' && '9' >= aa ? int.Parse(aa.ToString()) : aa - 'a' + 10;
Func<string, int, ResultItem> ff = (aaa, bbb) =>
{
var ccc = ee(aaa[bbb]);
var ddd = ee(aaa[bbb + 1]);
ddd = 15 & ddd;
var fff = (12 & ccc) >> 2;
var ggg = (2 & ccc) > 0;
var hhh = (1 & ccc) > 0;
return new ResultItem
{
Value = ddd,
Winner = fff,
PlayerPair = ggg,
BankerPair = hhh
};
};
var gg = 0;
for (; gg < a.Length - 1; gg += 2)
{
var bb = ff(a, gg);
if (bb.Winner != 3) cc.Add(bb);
else cc = new List<ResultItem>();
}
return cc;
};
if (string.IsNullOrEmpty(mode) || string.IsNullOrEmpty(input)) return new List<ResultItem>();
switch (mode)
{
case "7bal":
case "bal":
return process(input);
case "rol":
case "rofl":
return input.Split(';').Select(s => new ResultItem
{
Result = s
}).ToList();
default:
throw new NotSupportedException(mode);
}
}
public class ResultItem
{
public bool BankerPair { get; set; }
public bool PlayerPair { get; set; }
public int Value { get; set; }
public int Winner { get; set; }
public string Result { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment