123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- 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 计算
- /// <summary>
- /// 得到和值
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static int GetHz(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- if (code.IsEmpty())
- return 0;
- return list.Sum(p => p.TryToInt32());
- }
- /// <summary>
- /// 得到跨度
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- 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();
- }
- /// <summary>
- /// 所有跨度,百十,十个,百个,跨度
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static List<int> GetKdAll(string code)
- {
- try
- {
- var openCodeList = code.Split('+')[0].Split(',').Select(p => p.TryToInt32()).ToList();
- if (code.IsEmpty())
- return new List<int> { 0, 0, 0, 0 };
- return new List<int> {
- Math.Abs(openCodeList[0] - openCodeList[1]),
- Math.Abs(openCodeList[1] - openCodeList[2]),
- Math.Abs(openCodeList[0] - openCodeList[2]),
- GetKd(code)
- };
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- /// <summary>
- /// AC值计算
- /// </summary>
- /// <param name="kjh"></param>
- /// <returns></returns>
- public static int GetAc(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
- List<string> 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);
- }
- /// <summary>
- /// 根据和值返回和尾
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static int GetHw(int hz)
- {
- return hz % 10;
- }
- /// <summary>
- /// 根据号码返回和尾
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static int GetHw(string code)
- {
- return GetHz(code) % 10;
- }
- /// <summary>
- /// 得到组选
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetZx(string value)
- {
- var list = value.Split(',').ToList();
- if (list.Count < 3)
- {
- list = new List<string>();
- 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 "组六";
- }
- /// <summary>
- /// 对于开奖号的初始处理
- /// </summary>
- /// <param name="code"></param>
- /// <param name="isLq"></param>
- /// <returns></returns>
- public static List<string> 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;
- }
- /// <summary>
- /// 组合算法
- /// </summary>
- /// <param name="data">组合源数据</param>
- /// <param name="count">所选组合个数</param>
- /// <returns></returns>
- public static List<string> GetCombination(string[] data, int count)
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- List<string> output = new List<string>();
- for (int i = 0; i < data.Length; i++)
- {
- dic.Add(data[i], i);
- }
- SelectN(dic, data, count, 1, ref output);
- return output;
- }
- /// <summary>
- /// 字典组合算法
- /// </summary>
- /// <param name="dd"></param>
- /// <param name="data"></param>
- /// <param name="count"></param>
- /// <param name="times"></param>
- /// <param name="output"></param>
- public static void SelectN(Dictionary<string, int> dd, string[] data, int count, int times, ref List<string> output)
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- foreach (KeyValuePair<string, int> 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 大小
- /// <summary>
- /// 获取数字大小个数比
- /// </summary>
- /// <param name="code">开奖号码</param>
- /// <param name="red">红球区间</param>
- /// <returns></returns>
- 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}";
- }
- /// <summary>
- /// 得到汉字形态大小
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetDxxtCh(string code, string red)
- {
- List<string> value = new List<string>();
- 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("");
- }
- /// <summary>
- /// 获取汉字大小 和尾、跨度(值)
- /// </summary>
- /// <param name="code">开奖号码</param>
- /// <param name="red">红球区间</param>
- /// <returns></returns>
- 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 奇偶
- /// <summary>
- /// 奇偶数字个数比
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- 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}";
- }
- /// <summary>
- /// 奇偶汉字形态
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static string GetJoxtCh(string code)
- {
- List<string> value = new List<string>();
- code.Split('+')[0].Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 2 == 0)
- value.Add("偶");
- else
- value.Add("奇");
- });
- return value.Join("");
- }
- /// <summary>
- /// 单双汉字形态
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static string GetDsxtCh(string code)
- {
- List<string> value = new List<string>();
- code.Split('+')[0].Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 2 == 0)
- value.Add("双");
- else
- value.Add("单");
- });
- return value.Join("");
- }
- /// <summary>
- /// 获取一个值的奇偶
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static string GetJo(int code)
- {
- if (code % 2 == 0)
- return "偶";
- else
- return "奇";
- }
- #endregion
- #region 012路
- /// <summary>
- /// 012路(和值、合尾、跨度)
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string Get012Value(int value)
- {
- if (value % 3 == 0)
- {
- return "0";
- }
- else if (value % 3 == 1)
- {
- return "1";
- }
- return "2";
- }
- /// <summary>
- /// 012路 形态
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 012路个数比
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- 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 单双
- /// <summary>
- /// 得到形态 单双
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetXtDsValue(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 2 != 0)
- {
- result += "单";
- }
- else
- {
- result += "双";
- }
- });
- return result;
- }
- /// <summary>
- /// 得到单双(和值、合尾、跨度)
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetDsValue(int value)
- {
- if (value % 2 != 0)
- {
- return "单";
- }
- return "双";
- }
- #endregion
- #region 质合
- /// <summary>
- /// 获取汉字质合 0为合 1为质(适用0-100)
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetzhCh(int value)
- {
- //0~100
- List<int> zs = new List<int> { 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 "合";
- }
- /// <summary>
- /// 获取数字质合个数比 0为合 1为质(适用0-100)
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetZhb(string code)
- {
- int z = 0, h = 0;
- //0~100
- List<int> zs = new List<int> { 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}";
- }
- /// <summary>
- /// 获取汉字质合形态 0为合 1为质(适用0-100)
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetZhxtCH(string code)
- {
- List<string> value = new List<string>();
- //0~100
- List<int> zs = new List<int> { 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
- /// <summary>
- /// 获取组三形态
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static string GetZus(string code)
- {
- string result = "ABC";
- List<string> 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 三区比
- /// <summary>
- /// 获取三区比
- /// </summary>
- /// <param name="code"></param>
- /// <param name="red"></param>
- /// <returns></returns>
- 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 连号
- /// <summary>
- /// 得到开奖号的连号总数
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static int GetLhCount(string code)
- {
- int c = 0;
- List<int> 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;
- }
- /// <summary>
- /// 得到连号数字
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static List<int> GetLh(string code)
- {
- var list = new List<int>();
- 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();
- }
- /// <summary>
- /// 得到非连号数据
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static List<int> GetNoLh(string code)
- {
- var list = new List<int>();
- 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;
- }
- /// <summary>
- /// 获取当前code是否是斜连号
- /// </summary>
- /// <param name="code"></param>
- /// <param name="prvCode"></param>
- /// <param name="nextCode"></param>
- /// <returns></returns>
- public static List<int> GetXlh(string code, string prvCode)
- {
- var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
- if (prvCode.IsEmpty())
- return opList;
- var list = new List<int>();
- var prvList = prvCode.IsEmpty()?new List<int>(): 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();
- }
- /// <summary>
- /// 得到非连号数据
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static List<int> GetNoXlh(string code, string prvCode)
- {
- var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
- if (prvCode.IsEmpty())
- return opList;
- var list = new List<int>();
- var lh = GetXlh(code,prvCode);
- list = (from a in opList
- where !lh.Contains(a)
- select a).ToList();
- return list;
- }
- #endregion
- #region 重号
- /// <summary>
- /// 得到重号
- /// </summary>
- /// <param name="code">当前开奖号</param>
- /// <param name="prvCode">上一期</param>
- /// <param name="nextCode">下一期开奖号</param>
- /// <returns></returns>
- public static List<int> GetCh(string code,string prvCode, string nextCode)
- {
- var list = new List<int>();
- var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
- var prvList = prvCode.IsEmpty() ? new List<int>() : GetCode(prvCode).Select(p => p.TryToInt32()).ToList();
- var nextList = nextCode.IsEmpty() ? new List<int>() : 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();
- }
- /// <summary>
- /// 得到重号
- /// </summary>
- /// <param name="code">当前开奖号</param>
- /// <param name="prvCode"上一期或者下一期开奖号</param>
- /// <returns></returns>
- public static List<int> GetNoCh(string code, string prvCode,string nextCode)
- {
- var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
- var list = new List<int>();
- var lh = GetCh(code, prvCode, nextCode);
- list = (from a in opList
- where !lh.Contains(a)
- select a).ToList();
- return list;
- }
- #endregion
- }
- }
|