CzDataHelper1.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Common
  8. {
  9. public static class CzDataHelper1
  10. {
  11. #region 计算
  12. /// <summary>
  13. /// 得到和值
  14. /// </summary>
  15. /// <param name="code"></param>
  16. /// <returns></returns>
  17. public static int GetHz(string code)
  18. {
  19. var list = code.Split('+')[0].Split(',').ToList();
  20. if (code.IsEmpty())
  21. return 0;
  22. return list.Sum(p => p.TryToInt32());
  23. }
  24. /// <summary>
  25. /// 得到跨度
  26. /// </summary>
  27. /// <param name="code"></param>
  28. /// <returns></returns>
  29. public static int GetKd(string code)
  30. {
  31. var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
  32. if (code.IsEmpty())
  33. return 0;
  34. return list.FirstOrDefault().TryToInt32() - list.LastOrDefault().TryToInt32();
  35. }
  36. /// <summary>
  37. /// 所有跨度,百十,十个,百个,跨度
  38. /// </summary>
  39. /// <param name="code"></param>
  40. /// <returns></returns>
  41. public static List<int> GetKdAll(string code)
  42. {
  43. try
  44. {
  45. var openCodeList = code.Split('+')[0].Split(',').Select(p => p.TryToInt32()).ToList();
  46. if (code.IsEmpty())
  47. return new List<int> { 0, 0, 0, 0 };
  48. return new List<int> {
  49. Math.Abs(openCodeList[0] - openCodeList[1]),
  50. Math.Abs(openCodeList[1] - openCodeList[2]),
  51. Math.Abs(openCodeList[0] - openCodeList[2]),
  52. GetKd(code)
  53. };
  54. }
  55. catch (Exception ex)
  56. {
  57. throw;
  58. }
  59. }
  60. /// <summary>
  61. /// AC值计算
  62. /// </summary>
  63. /// <param name="kjh"></param>
  64. /// <returns></returns>
  65. public static int GetAc(string code)
  66. {
  67. var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
  68. List<string> result = GetCombination(list.ToArray(), 2);
  69. ArrayList acarray = new ArrayList();
  70. int tpac = 0;
  71. for (int i = 0; i < result.Count; i++)
  72. {
  73. string[] tp = result[i].Split(',');
  74. int tmp = Math.Abs(Convert.ToInt32(tp[0]) - Convert.ToInt32(tp[1]));
  75. if (!acarray.Contains(tmp))
  76. {
  77. tpac++;
  78. acarray.Add(tmp);
  79. }
  80. }
  81. return tpac - (list.Count() - 1);
  82. }
  83. /// <summary>
  84. /// 根据和值返回和尾
  85. /// </summary>
  86. /// <param name="hz"></param>
  87. /// <returns></returns>
  88. public static int GetHw(int hz)
  89. {
  90. return hz % 10;
  91. }
  92. /// <summary>
  93. /// 根据号码返回和尾
  94. /// </summary>
  95. /// <param name="hz"></param>
  96. /// <returns></returns>
  97. public static int GetHw(string code)
  98. {
  99. return GetHz(code) % 10;
  100. }
  101. /// <summary>
  102. /// 得到组选
  103. /// </summary>
  104. /// <param name="value"></param>
  105. /// <returns></returns>
  106. public static string GetZx(string value)
  107. {
  108. var list = value.Split(',').ToList();
  109. if (list.Count < 3)
  110. {
  111. list = new List<string>();
  112. foreach (var item in value)
  113. {
  114. list.Add(item.ToString());
  115. }
  116. }
  117. list = list.Where(p => !string.IsNullOrEmpty(p.Trim())).Select(p => p.Trim()).ToList();
  118. if (list.GroupBy(p => p).Count() == 1)
  119. {
  120. return "豹子";
  121. }
  122. else if (list.GroupBy(p => p).Count() == 2)
  123. {
  124. return "组三";
  125. }
  126. return "组六";
  127. }
  128. /// <summary>
  129. /// 对于开奖号的初始处理
  130. /// </summary>
  131. /// <param name="code"></param>
  132. /// <param name="isLq"></param>
  133. /// <returns></returns>
  134. public static List<string> GetCode(this string code, bool isLq = false)
  135. {
  136. var array = code.Split('+').ToList();
  137. var list = array[0].Split(',').ToList();
  138. if (isLq == true && array.Count == 2)
  139. list = list.Concat(array[1].Split(',').ToList()).ToList();
  140. return list;
  141. }
  142. /// <summary>
  143. /// 组合算法
  144. /// </summary>
  145. /// <param name="data">组合源数据</param>
  146. /// <param name="count">所选组合个数</param>
  147. /// <returns></returns>
  148. public static List<string> GetCombination(string[] data, int count)
  149. {
  150. Dictionary<string, int> dic = new Dictionary<string, int>();
  151. List<string> output = new List<string>();
  152. for (int i = 0; i < data.Length; i++)
  153. {
  154. dic.Add(data[i], i);
  155. }
  156. SelectN(dic, data, count, 1, ref output);
  157. return output;
  158. }
  159. /// <summary>
  160. /// 字典组合算法
  161. /// </summary>
  162. /// <param name="dd"></param>
  163. /// <param name="data"></param>
  164. /// <param name="count"></param>
  165. /// <param name="times"></param>
  166. /// <param name="output"></param>
  167. public static void SelectN(Dictionary<string, int> dd, string[] data, int count, int times, ref List<string> output)
  168. {
  169. Dictionary<string, int> dic = new Dictionary<string, int>();
  170. foreach (KeyValuePair<string, int> kv in dd)
  171. {
  172. for (int i = kv.Value + 1; i < data.Length; i++)
  173. {
  174. if (times < count - 1)
  175. {
  176. dic.Add(kv.Key + "," + data[i], i);
  177. }
  178. else
  179. {
  180. output.Add(kv.Key + "," + data[i]);
  181. }
  182. }
  183. }
  184. times++;
  185. if (dic.Count > 0)
  186. {
  187. SelectN(dic, data, count, times, ref output);
  188. }
  189. }
  190. #endregion
  191. #region 大小
  192. /// <summary>
  193. /// 获取数字大小个数比
  194. /// </summary>
  195. /// <param name="code">开奖号码</param>
  196. /// <param name="red">红球区间</param>
  197. /// <returns></returns>
  198. public static string GetDxb(string code, string red)
  199. {
  200. int d = 0, x = 0;
  201. int number = red.Contains(",")?red.Split(',')[1].TryToInt32() / 2: red.Split(',')[0].TryToInt32() / 2;
  202. code.Split('+')[0].Split(',').ToList().ForEach(p =>
  203. {
  204. if (p.TryToInt32() > number)
  205. d++;
  206. else
  207. x++;
  208. });
  209. return $"{d}:{x}";
  210. }
  211. /// <summary>
  212. /// 得到汉字形态大小
  213. /// </summary>
  214. /// <param name="hz"></param>
  215. /// <returns></returns>
  216. public static string GetDxxtCh(string code, string red)
  217. {
  218. List<string> value = new List<string>();
  219. int number = red.Contains(",") ? red.Split(',')[1].TryToInt32() / 2 : red.Split(',')[0].TryToInt32() / 2;
  220. code.Split(',').ToList().ForEach(p =>
  221. {
  222. if (p.TryToInt32() > number)
  223. value.Add("大");
  224. else
  225. value.Add("小");
  226. });
  227. return value.Join("");
  228. }
  229. /// <summary>
  230. /// 获取汉字大小 和尾、跨度(值)
  231. /// </summary>
  232. /// <param name="code">开奖号码</param>
  233. /// <param name="red">红球区间</param>
  234. /// <returns></returns>
  235. public static string GetDxCh(string val, string red)
  236. {
  237. int number = red.Contains(",") ? red.Split(',')[1].TryToInt32() / 2 : red.Split(',')[0].TryToInt32() / 2;
  238. if (val.TryToInt32() > number)
  239. return "大";
  240. else
  241. return "小";
  242. }
  243. #endregion
  244. #region 奇偶
  245. /// <summary>
  246. /// 奇偶数字个数比
  247. /// </summary>
  248. /// <param name="code"></param>
  249. /// <returns></returns>
  250. public static string GetJob(string code)
  251. {
  252. var list = code.Split('+')[0].Split(',').ToList();
  253. var j = 0;
  254. var o = 0;
  255. list.ForEach(p =>
  256. {
  257. if (int.Parse(p) % 2 == 0)
  258. {
  259. o++;
  260. }
  261. else
  262. j++;
  263. });
  264. return $"{j}:{o}";
  265. }
  266. /// <summary>
  267. /// 奇偶汉字形态
  268. /// </summary>
  269. /// <param name="code"></param>
  270. /// <returns></returns>
  271. public static string GetJoxtCh(string code)
  272. {
  273. List<string> value = new List<string>();
  274. code.Split('+')[0].Split(',').ToList().ForEach(p =>
  275. {
  276. if (int.Parse(p) % 2 == 0)
  277. value.Add("偶");
  278. else
  279. value.Add("奇");
  280. });
  281. return value.Join("");
  282. }
  283. /// <summary>
  284. /// 单双汉字形态
  285. /// </summary>
  286. /// <param name="code"></param>
  287. /// <returns></returns>
  288. public static string GetDsxtCh(string code)
  289. {
  290. List<string> value = new List<string>();
  291. code.Split('+')[0].Split(',').ToList().ForEach(p =>
  292. {
  293. if (int.Parse(p) % 2 == 0)
  294. value.Add("双");
  295. else
  296. value.Add("单");
  297. });
  298. return value.Join("");
  299. }
  300. /// <summary>
  301. /// 获取一个值的奇偶
  302. /// </summary>
  303. /// <param name="code"></param>
  304. /// <returns></returns>
  305. public static string GetJo(int code)
  306. {
  307. if (code % 2 == 0)
  308. return "偶";
  309. else
  310. return "奇";
  311. }
  312. #endregion
  313. #region 012路
  314. /// <summary>
  315. /// 012路(和值、合尾、跨度)
  316. /// </summary>
  317. /// <param name="hz"></param>
  318. /// <returns></returns>
  319. public static string Get012Value(int value)
  320. {
  321. if (value % 3 == 0)
  322. {
  323. return "0";
  324. }
  325. else if (value % 3 == 1)
  326. {
  327. return "1";
  328. }
  329. return "2";
  330. }
  331. /// <summary>
  332. /// 012路 形态
  333. /// </summary>
  334. /// <param name="hz"></param>
  335. /// <returns></returns>
  336. public static string GetXt012Value(string code)
  337. {
  338. var result = "";
  339. code.Split(',').ToList().ForEach(p =>
  340. {
  341. if (int.Parse(p) % 3 == 0)
  342. {
  343. result += "0";
  344. }
  345. else if (int.Parse(p) % 3 == 1)
  346. {
  347. result += "1";
  348. }
  349. else
  350. {
  351. result += "2";
  352. }
  353. });
  354. return result;
  355. }
  356. /// <summary>
  357. /// 012路个数比
  358. /// </summary>
  359. /// <param name="hz"></param>
  360. /// <returns></returns>
  361. public static string GetXt012be(string code)
  362. {
  363. int a0 = 0, a1 = 0, a2 = 0;
  364. code.Split(',').ToList().ForEach(p =>
  365. {
  366. if (int.Parse(p) % 3 == 0)
  367. a0++;
  368. else if (int.Parse(p) % 3 == 1)
  369. a1++;
  370. else
  371. a2++;
  372. });
  373. return $"{a0}:{a1}:{a2}";
  374. }
  375. #endregion
  376. #region 单双
  377. /// <summary>
  378. /// 得到形态 单双
  379. /// </summary>
  380. /// <param name="hz"></param>
  381. /// <returns></returns>
  382. public static string GetXtDsValue(string code)
  383. {
  384. var result = "";
  385. code.Split(',').ToList().ForEach(p =>
  386. {
  387. if (int.Parse(p) % 2 != 0)
  388. {
  389. result += "单";
  390. }
  391. else
  392. {
  393. result += "双";
  394. }
  395. });
  396. return result;
  397. }
  398. /// <summary>
  399. /// 得到单双(和值、合尾、跨度)
  400. /// </summary>
  401. /// <param name="hz"></param>
  402. /// <returns></returns>
  403. public static string GetDsValue(int value)
  404. {
  405. if (value % 2 != 0)
  406. {
  407. return "单";
  408. }
  409. return "双";
  410. }
  411. #endregion
  412. #region 质合
  413. /// <summary>
  414. /// 获取汉字质合 0为合 1为质(适用0-100)
  415. /// </summary>
  416. /// <param name="value"></param>
  417. /// <returns></returns>
  418. public static string GetzhCh(int value)
  419. {
  420. //0~100
  421. 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 };
  422. if (zs.Contains(value))
  423. return "质";
  424. else
  425. return "合";
  426. }
  427. /// <summary>
  428. /// 获取数字质合个数比 0为合 1为质(适用0-100)
  429. /// </summary>
  430. /// <param name="value"></param>
  431. /// <returns></returns>
  432. public static string GetZhb(string code)
  433. {
  434. int z = 0, h = 0;
  435. //0~100
  436. 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 };
  437. code.Split(',').ToList().ForEach(a =>
  438. {
  439. if (zs.Contains(a.TryToInt32()))
  440. z++;
  441. else
  442. h++;
  443. });
  444. return $"{z}:{h}";
  445. }
  446. /// <summary>
  447. /// 获取汉字质合形态 0为合 1为质(适用0-100)
  448. /// </summary>
  449. /// <param name="value"></param>
  450. /// <returns></returns>
  451. public static string GetZhxtCH(string code)
  452. {
  453. List<string> value = new List<string>();
  454. //0~100
  455. 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 };
  456. code.Split(',').ToList().ForEach(a =>
  457. {
  458. if (zs.Contains(a.TryToInt32()))
  459. value.Add("质");
  460. else
  461. value.Add("合");
  462. });
  463. return value.Join("");
  464. }
  465. #endregion
  466. #region 组三 ABC
  467. /// <summary>
  468. /// 获取组三形态
  469. /// </summary>
  470. /// <param name="code"></param>
  471. /// <returns></returns>
  472. public static string GetZus(string code)
  473. {
  474. string result = "ABC";
  475. List<string> k = code.Split(',').ToList();
  476. if (k[0] == k[1])
  477. result = "AAB";
  478. if (k[1] == k[2])
  479. result = "BAA";
  480. if (k[0] == k[2])
  481. result = "ABA";
  482. return result;
  483. }
  484. #endregion
  485. #region 三区比
  486. /// <summary>
  487. /// 获取三区比
  488. /// </summary>
  489. /// <param name="code"></param>
  490. /// <param name="red"></param>
  491. /// <returns></returns>
  492. public static string GetSqb(string code, string red)
  493. {
  494. int q1 = 0, q2 = 0, q3 = 0;
  495. int number1 = red.Split(',')[0].TryToInt32() % 3 == 0 ? red.Split(',')[0].TryToInt32() / 3 : red.Split(',')[0].TryToInt32() / 3 + 1;
  496. int number2 = number1 * 2;
  497. code.Split('+')[0].Split(',').ToList().ForEach(a =>
  498. {
  499. if (a.TryToInt32() > number2)
  500. q3++;
  501. else if (a.TryToInt32() > number1)
  502. q2++;
  503. else
  504. q1++;
  505. });
  506. return $"{q1}:{q2}:{q3}";
  507. }
  508. #endregion
  509. #region 连号
  510. /// <summary>
  511. /// 得到开奖号的连号总数
  512. /// </summary>
  513. /// <param name="code"></param>
  514. /// <returns></returns>
  515. public static int GetLhCount(string code)
  516. {
  517. int c = 0;
  518. List<int> kjh = GetCode(code).Select(p => p.TryToInt32()).ToList();
  519. if (kjh != null && kjh.Count > 0)
  520. {
  521. kjh.Sort();
  522. for (int i = 0; i < kjh.Count; i++)
  523. {
  524. if (i > 0 && (kjh[i] - kjh[i - 1]) == 1)
  525. c++;
  526. }
  527. if (c > 0)
  528. c = c + 1;
  529. }
  530. return c;
  531. }
  532. /// <summary>
  533. /// 得到连号数字
  534. /// </summary>
  535. /// <param name="code"></param>
  536. /// <returns></returns>
  537. public static List<int> GetLh(string code)
  538. {
  539. var list = new List<int>();
  540. var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
  541. for (int i = 1; i < opList.Count; i++)
  542. {
  543. if (opList[i] - 1 == opList[i - 1])
  544. {
  545. list.Add(opList[i]);
  546. list.Add(opList[i - 1]);
  547. }
  548. }
  549. return list.Distinct().ToList();
  550. }
  551. /// <summary>
  552. /// 得到非连号数据
  553. /// </summary>
  554. /// <param name="code"></param>
  555. /// <returns></returns>
  556. public static List<int> GetNoLh(string code)
  557. {
  558. var list = new List<int>();
  559. var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
  560. var lh = GetLh(code);
  561. list = (from a in opList
  562. where !lh.Contains(a)
  563. select a).ToList();
  564. return list;
  565. }
  566. /// <summary>
  567. /// 获取当前code是否是斜连号
  568. /// </summary>
  569. /// <param name="code"></param>
  570. /// <param name="prvCode"></param>
  571. /// <param name="nextCode"></param>
  572. /// <returns></returns>
  573. public static List<int> GetXlh(string code, string prvCode)
  574. {
  575. var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
  576. if (prvCode.IsEmpty())
  577. return opList;
  578. var list = new List<int>();
  579. var prvList = prvCode.IsEmpty()?new List<int>(): GetCode(prvCode).Select(p => p.TryToInt32()).ToList();
  580. opList.ForEach(p =>
  581. {
  582. if (prvList.Contains(p - 1) || prvList.Contains(p + 1))
  583. {
  584. list.Add(p);
  585. }
  586. });
  587. return list.Distinct().ToList();
  588. }
  589. /// <summary>
  590. /// 得到非连号数据
  591. /// </summary>
  592. /// <param name="code"></param>
  593. /// <returns></returns>
  594. public static List<int> GetNoXlh(string code, string prvCode)
  595. {
  596. var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
  597. if (prvCode.IsEmpty())
  598. return opList;
  599. var list = new List<int>();
  600. var lh = GetXlh(code,prvCode);
  601. list = (from a in opList
  602. where !lh.Contains(a)
  603. select a).ToList();
  604. return list;
  605. }
  606. #endregion
  607. #region 重号
  608. /// <summary>
  609. /// 得到重号
  610. /// </summary>
  611. /// <param name="code">当前开奖号</param>
  612. /// <param name="prvCode">上一期</param>
  613. /// <param name="nextCode">下一期开奖号</param>
  614. /// <returns></returns>
  615. public static List<int> GetCh(string code,string prvCode, string nextCode)
  616. {
  617. var list = new List<int>();
  618. var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
  619. var prvList = prvCode.IsEmpty() ? new List<int>() : GetCode(prvCode).Select(p => p.TryToInt32()).ToList();
  620. var nextList = nextCode.IsEmpty() ? new List<int>() : GetCode(nextCode).Select(p => p.TryToInt32()).ToList();
  621. for (int i = 0; i < opList.Count; i++)
  622. {
  623. if (prvList.Contains(opList[i]) || nextList.Contains(opList[i]))
  624. list.Add(opList[i]);
  625. }
  626. return list.Distinct().ToList();
  627. }
  628. /// <summary>
  629. /// 得到重号
  630. /// </summary>
  631. /// <param name="code">当前开奖号</param>
  632. /// <param name="prvCode"上一期或者下一期开奖号</param>
  633. /// <returns></returns>
  634. public static List<int> GetNoCh(string code, string prvCode,string nextCode)
  635. {
  636. var opList = GetCode(code).Select(p => p.TryToInt32()).ToList();
  637. var list = new List<int>();
  638. var lh = GetCh(code, prvCode, nextCode);
  639. list = (from a in opList
  640. where !lh.Contains(a)
  641. select a).ToList();
  642. return list;
  643. }
  644. #endregion
  645. }
  646. }