周易算卦流程c++实现

代码

#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;
}

在这里插入图片描述
六爻分别为:少阴、少阴、少阳、老阳、老阳、少阴

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值