周易算卦流程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;
}

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

相关推荐
MSTcheng.2 分钟前
【C++】C++11新特性(二)
java·开发语言·c++·c++11
晓13135 分钟前
第七章 【C语言篇:文件】 文件全面解析
linux·c语言·开发语言
愚者游世5 分钟前
Delegating Constructor(委托构造函数)各版本异同
开发语言·c++·程序人生·面试·改行学it
小镇敲码人6 分钟前
探索华为CANN框架中的ACL仓库
c++·python·华为·acl·cann
梵刹古音7 分钟前
【C语言】 指针基础与定义
c语言·开发语言·算法
Ekehlaft11 分钟前
这款国产 AI,让 Python 小白也能玩转编程
开发语言·人工智能·python·ai·aipy
rit843249913 分钟前
MATLAB中Teager能量算子提取与解调信号的实现
开发语言·matlab
开源技术15 分钟前
Python GeoPandas基础知识:地图、投影和空间连接
开发语言·ide·python
Cult Of19 分钟前
Alicea Wind的个人网站开发日志(2)
开发语言·python·vue
我找到地球的支点啦24 分钟前
通信扩展——扩频技术(超级详细,附带Matlab代码)
开发语言·matlab