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

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

相关推荐
开发者工具分享16 分钟前
如何应对敏捷转型中的团队阻力
开发语言
gregmankiw22 分钟前
C#调用Rust动态链接库DLL的案例
开发语言·rust·c#
roman_日积跬步-终至千里37 分钟前
【Go语言基础【20】】Go的包与工程
开发语言·后端·golang
秦少游在淮海1 小时前
C++ - string 的使用 #auto #范围for #访问及遍历操作 #容量操作 #修改操作 #其他操作 #非成员函数
开发语言·c++·stl·string·范围for·auto·string 的使用
const5441 小时前
cpp自学 day2(—>运算符)
开发语言·c++
心扬1 小时前
python生成器
开发语言·python
阿蒙Amon1 小时前
06. C#入门系列【自定义类型】:从青铜到王者的进阶之路
开发语言·c#
虾球xz1 小时前
CppCon 2015 学习:CLANG/C2 for Windows
开发语言·c++·windows·学习
CodeWithMe2 小时前
【C/C++】namespace + macro混用场景
c语言·开发语言·c++
蓝婷儿2 小时前
6个月Python学习计划 Day 17 - 继承、多态与魔术方法
开发语言·python·学习