using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Common { public static class CzDataHelper1 { #region 计算 /// /// 得到和值 /// /// /// public static int GetHz(string code) { var list = code.Split('+')[0].Split(',').ToList(); if (code.IsEmpty()) return 0; return list.Sum(p => p.TryToInt32()); } /// /// 得到跨度 /// /// /// public static int GetKd(string code) { var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p); if (code.IsEmpty()) return 0; return list.FirstOrDefault().TryToInt32() - list.LastOrDefault().TryToInt32(); } /// /// 所有跨度,百十,十个,百个,跨度 /// /// /// public static List GetKdAll(string code) { try { var openCodeList = code.Split('+')[0].Split(',').Select(p => p.TryToInt32()).ToList(); if (code.IsEmpty()) return new List { 0, 0, 0, 0 }; return new List { Math.Abs(openCodeList[0] - openCodeList[1]), Math.Abs(openCodeList[1] - openCodeList[2]), Math.Abs(openCodeList[0] - openCodeList[2]), GetKd(code) }; } catch (Exception ex) { throw; } } /// /// AC值计算 /// /// /// public static int GetAc(string code) { var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p); List result = GetCombination(list.ToArray(), 2); ArrayList acarray = new ArrayList(); int tpac = 0; for (int i = 0; i < result.Count; i++) { string[] tp = result[i].Split(','); int tmp = Math.Abs(Convert.ToInt32(tp[0]) - Convert.ToInt32(tp[1])); if (!acarray.Contains(tmp)) { tpac++; acarray.Add(tmp); } } return tpac - (list.Count() - 1); } /// /// 根据和值返回和尾 /// /// /// public static int GetHw(int hz) { return hz % 10; } /// /// 根据号码返回和尾 /// /// /// public static int GetHw(string code) { return GetHz(code) % 10; } /// /// 得到组选 /// /// /// public static string GetZx(string value) { var list = value.Split(',').ToList(); if (list.Count < 3) { list = new List(); foreach (var item in value) { list.Add(item.ToString()); } } list = list.Where(p => !string.IsNullOrEmpty(p.Trim())).Select(p => p.Trim()).ToList(); if (list.GroupBy(p => p).Count() == 1) { return "豹子"; } else if (list.GroupBy(p => p).Count() == 2) { return "组三"; } return "组六"; } /// /// 对于开奖号的初始处理 /// /// /// /// public static List GetCode(this string code, bool isLq = false) { var array = code.Split('+').ToList(); var list = array[0].Split(',').ToList(); if (isLq == true && array.Count == 2) list = list.Concat(array[1].Split(',').ToList()).ToList(); return list; } /// /// 组合算法 /// /// 组合源数据 /// 所选组合个数 /// public static List GetCombination(string[] data, int count) { Dictionary dic = new Dictionary(); List output = new List(); for (int i = 0; i < data.Length; i++) { dic.Add(data[i], i); } SelectN(dic, data, count, 1, ref output); return output; } /// /// 字典组合算法 /// /// /// /// /// /// public static void SelectN(Dictionary dd, string[] data, int count, int times, ref List output) { Dictionary dic = new Dictionary(); foreach (KeyValuePair kv in dd) { for (int i = kv.Value + 1; i < data.Length; i++) { if (times < count - 1) { dic.Add(kv.Key + "," + data[i], i); } else { output.Add(kv.Key + "," + data[i]); } } } times++; if (dic.Count > 0) { SelectN(dic, data, count, times, ref output); } } #endregion #region 大小 /// /// 获取数字大小个数比 /// /// 开奖号码 /// 红球区间 /// public static string GetDxb(string code, string red) { int d = 0, x = 0; int number = red.Contains(",")?red.Split(',')[1].TryToInt32() / 2: red.Split(',')[0].TryToInt32() / 2; code.Split('+')[0].Split(',').ToList().ForEach(p => { if (p.TryToInt32() > number) d++; else x++; }); return $"{d}:{x}"; } /// /// 得到汉字形态大小 /// /// /// public static string GetDxxtCh(string code, string red) { List value = new List(); int number = red.Contains(",") ? red.Split(',')[1].TryToInt32() / 2 : red.Split(',')[0].TryToInt32() / 2; code.Split(',').ToList().ForEach(p => { if (p.TryToInt32() > number) value.Add("大"); else value.Add("小"); }); return value.Join(""); } /// /// 获取汉字大小 和尾、跨度(值) /// /// 开奖号码 /// 红球区间 /// public static string GetDxCh(string val, string red) { int number = red.Contains(",") ? red.Split(',')[1].TryToInt32() / 2 : red.Split(',')[0].TryToInt32() / 2; if (val.TryToInt32() > number) return "大"; else return "小"; } #endregion #region 奇偶 /// /// 奇偶数字个数比 /// /// /// public static string GetJob(string code) { var list = code.Split('+')[0].Split(',').ToList(); var j = 0; var o = 0; list.ForEach(p => { if (int.Parse(p) % 2 == 0) { o++; } else j++; }); return $"{j}:{o}"; } /// /// 奇偶汉字形态 /// /// /// public static string GetJoxtCh(string code) { List value = new List(); code.Split('+')[0].Split(',').ToList().ForEach(p => { if (int.Parse(p) % 2 == 0) value.Add("偶"); else value.Add("奇"); }); return value.Join(""); } /// /// 单双汉字形态 /// /// /// public static string GetDsxtCh(string code) { List value = new List(); code.Split('+')[0].Split(',').ToList().ForEach(p => { if (int.Parse(p) % 2 == 0) value.Add("双"); else value.Add("单"); }); return value.Join(""); } /// /// 获取一个值的奇偶 /// /// /// public static string GetJo(int code) { if (code % 2 == 0) return "偶"; else return "奇"; } #endregion #region 012路 /// /// 012路(和值、合尾、跨度) /// /// /// public static string Get012Value(int value) { if (value % 3 == 0) { return "0"; } else if (value % 3 == 1) { return "1"; } return "2"; } /// /// 012路 形态 /// /// /// public static string GetXt012Value(string code) { var result = ""; code.Split(',').ToList().ForEach(p => { if (int.Parse(p) % 3 == 0) { result += "0"; } else if (int.Parse(p) % 3 == 1) { result += "1"; } else { result += "2"; } }); return result; } /// /// 012路个数比 /// /// /// public static string GetXt012be(string code) { int a0 = 0, a1 = 0, a2 = 0; code.Split(',').ToList().ForEach(p => { if (int.Parse(p) % 3 == 0) a0++; else if (int.Parse(p) % 3 == 1) a1++; else a2++; }); return $"{a0}:{a1}:{a2}"; } #endregion #region 单双 /// /// 得到形态 单双 /// /// /// public static string GetXtDsValue(string code) { var result = ""; code.Split(',').ToList().ForEach(p => { if (int.Parse(p) % 2 != 0) { result += "单"; } else { result += "双"; } }); return result; } /// /// 得到单双(和值、合尾、跨度) /// /// /// public static string GetDsValue(int value) { if (value % 2 != 0) { return "单"; } return "双"; } #endregion #region 质合 /// /// 获取汉字质合 0为合 1为质(适用0-100) /// /// /// public static string GetzhCh(int value) { //0~100 List zs = new List { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; if (zs.Contains(value)) return "质"; else return "合"; } /// /// 获取数字质合个数比 0为合 1为质(适用0-100) /// /// /// public static string GetZhb(string code) { int z = 0, h = 0; //0~100 List zs = new List { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; code.Split(',').ToList().ForEach(a => { if (zs.Contains(a.TryToInt32())) z++; else h++; }); return $"{z}:{h}"; } /// /// 获取汉字质合形态 0为合 1为质(适用0-100) /// /// /// public static string GetZhxtCH(string code) { List value = new List(); //0~100 List zs = new List { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; code.Split(',').ToList().ForEach(a => { if (zs.Contains(a.TryToInt32())) value.Add("质"); else value.Add("合"); }); return value.Join(""); } #endregion #region 组三 ABC /// /// 获取组三形态 /// /// /// public static string GetZus(string code) { string result = "ABC"; List k = code.Split(',').ToList(); if (k[0] == k[1]) result = "AAB"; if (k[1] == k[2]) result = "BAA"; if (k[0] == k[2]) result = "ABA"; return result; } #endregion #region 三区比 /// /// 获取三区比 /// /// /// /// public static string GetSqb(string code, string red) { int q1 = 0, q2 = 0, q3 = 0; int number1 = red.Split(',')[0].TryToInt32() % 3 == 0 ? red.Split(',')[0].TryToInt32() / 3 : red.Split(',')[0].TryToInt32() / 3 + 1; int number2 = number1 * 2; code.Split('+')[0].Split(',').ToList().ForEach(a => { if (a.TryToInt32() > number2) q3++; else if (a.TryToInt32() > number1) q2++; else q1++; }); return $"{q1}:{q2}:{q3}"; } #endregion #region 连号 /// /// 得到开奖号的连号总数 /// /// /// public static int GetLhCount(string code) { int c = 0; List kjh = GetCode(code).Select(p => p.TryToInt32()).ToList(); if (kjh != null && kjh.Count > 0) { kjh.Sort(); for (int i = 0; i < kjh.Count; i++) { if (i > 0 && (kjh[i] - kjh[i - 1]) == 1) c++; } if (c > 0) c = c + 1; } return c; } /// /// 得到连号数字 /// /// /// public static List GetLh(string code) { var list = new List(); var opList = GetCode(code).Select(p => p.TryToInt32()).ToList(); for (int i = 1; i < opList.Count; i++) { if (opList[i] - 1 == opList[i - 1]) { list.Add(opList[i]); list.Add(opList[i - 1]); } } return list.Distinct().ToList(); } /// /// 得到非连号数据 /// /// /// public static List GetNoLh(string code) { var list = new List(); var opList = GetCode(code).Select(p => p.TryToInt32()).ToList(); var lh = GetLh(code); list = (from a in opList where !lh.Contains(a) select a).ToList(); return list; } /// /// 获取当前code是否是斜连号 /// /// /// /// /// public static List GetXlh(string code, string prvCode) { var opList = GetCode(code).Select(p => p.TryToInt32()).ToList(); if (prvCode.IsEmpty()) return opList; var list = new List(); var prvList = prvCode.IsEmpty()?new List(): GetCode(prvCode).Select(p => p.TryToInt32()).ToList(); opList.ForEach(p => { if (prvList.Contains(p - 1) || prvList.Contains(p + 1)) { list.Add(p); } }); return list.Distinct().ToList(); } /// /// 得到非连号数据 /// /// /// public static List GetNoXlh(string code, string prvCode) { var opList = GetCode(code).Select(p => p.TryToInt32()).ToList(); if (prvCode.IsEmpty()) return opList; var list = new List(); var lh = GetXlh(code,prvCode); list = (from a in opList where !lh.Contains(a) select a).ToList(); return list; } #endregion #region 重号 /// /// 得到重号 /// /// 当前开奖号 /// 上一期 /// 下一期开奖号 /// public static List GetCh(string code,string prvCode, string nextCode) { var list = new List(); var opList = GetCode(code).Select(p => p.TryToInt32()).ToList(); var prvList = prvCode.IsEmpty() ? new List() : GetCode(prvCode).Select(p => p.TryToInt32()).ToList(); var nextList = nextCode.IsEmpty() ? new List() : GetCode(nextCode).Select(p => p.TryToInt32()).ToList(); for (int i = 0; i < opList.Count; i++) { if (prvList.Contains(opList[i]) || nextList.Contains(opList[i])) list.Add(opList[i]); } return list.Distinct().ToList(); } /// /// 得到重号 /// /// 当前开奖号 /// /// public static List GetNoCh(string code, string prvCode,string nextCode) { var opList = GetCode(code).Select(p => p.TryToInt32()).ToList(); var list = new List(); var lh = GetCh(code, prvCode, nextCode); list = (from a in opList where !lh.Contains(a) select a).ToList(); return list; } #endregion } }