周易算卦流程c++实现

代码

cpp 复制代码
#include<iostream>
using namespace std;
#include<vector>
#include<cstdlib>
#include<ctime>
#include<Windows.h>

int huaYiXiangLiang(int all, int& left)
{
	Sleep(3000);
	srand(time(0));
	left = rand() % all + 1;
	while (true) {
		if (left >= all-1 || left <= 1)
		{
			left = rand() % all + 1;
		}
		else break;
	}
	return all - left;
}

int main()
{
	vector<int> liuYao;

	for (int yao = 1; yao <= 6; ++yao) {
		vector<int> gua;
		int daYanZhiShu = 55;
		int qiYong = 55 - 6;

		for (int step = 1; step <= 3; ++step) {
			#if 1 分而为二以象两
			int left = 0;
			int right = huaYiXiangLiang(qiYong, left);
			cout << "left: " << left << ", right: " << right << endl;
			#endif

			int tmpRight = right;
#if 1 挂一以象三
			tmpRight -= 1;
			gua.push_back(1);
			cout << "tmpRight: " << tmpRight << endl;
#endif

#if 1 揲之以四以象四时
			while (tmpRight > 4)
			{
				tmpRight -= 4;
			}
			cout << "tmpRight: " << tmpRight << endl;
#endif

#if 1 归奇于扐以象闰
			if (tmpRight == 4) {
				left -= 4;
				tmpRight -= 4;
				gua.push_back(8);
			}
			else if (tmpRight < 4)
			{
				left -= (4 - tmpRight);
				tmpRight = 0;
				gua.push_back(4);
			}
			cout << "left: " << left << endl;
#endif

			for (int i = 0; i < gua.size(); ++i)
			{
				qiYong -= gua[i];
			}
			gua.clear();

			std::cout << "new qiYong: " << qiYong << endl;

			if (step != 3) {
				// 放回1
				qiYong += 1;
			}

		}
		liuYao.push_back( qiYong / 4 );
		cout << yao << " complete.\r\n";
	}
	for (int yao : liuYao) {
		cout << yao << " ";
	}
	cout << endl;

	return 0;
}

六爻分别为:少阴、少阴、少阳、老阳、老阳、少阴

相关推荐
lly2024066 小时前
jEasyUI 创建子网格
开发语言
·心猿意码·6 小时前
C++ 链接陷阱与底层溯源:ODR、inline 与匿名命名空间的那些坑
c++
always_TT6 小时前
内存泄漏是什么?如何避免?
android·java·开发语言
java1234_小锋6 小时前
Java高频面试题:怎么实现Redis的高可用?
java·开发语言·redis
oyguyteggytrrwwwrt6 小时前
抄写YOLOE源码——先抄写ultralytics包,关于__init__.py
开发语言·python
格林威6 小时前
Baumer相机铝箔表面针孔检测:提升包装阻隔性的 7 个核心策略,附 OpenCV+Halcon 实战代码!
开发语言·人工智能·数码相机·opencv·计算机视觉·c#·工业相机
金刚狼886 小时前
UUID和Name不在同一条BLE广播报文里
c++·windows
wanderist.6 小时前
从Nim游戏到SG函数
c++·算法·蓝桥杯
日出等日落6 小时前
用 Kavita实现我的远程数字书屋搭建记!
java·开发语言·ide·vscode·编辑器
我是伪码农7 小时前
JS 复习
开发语言·前端·javascript