一、if語句 if 語句讓你能夠檢查程式的當前狀態,並據此採取相應的措施。if語句可應用於列表,以另一種方式處理列表中的大多數元素,以及特定值的元素1、簡單示例 names=['xiaozhan','caiyilin','zhoushen','DAOlang','huangxiaoming'] fo ...
1.前言
周易學了一段時間了,今天來分享一個針對梅花易起卦的輔助小演算法。前提是,讀者需要有一定的周易業務知識。
2.六十四卦的介紹
直奔主題,下麵是我整理消化總結的一張圖:
3.卦象的解釋
4.梅花易起卦演算法介紹
參考地址:http://www.quanxue.cn/QT_XiaoYa/YiJing/YiJing06.html
5. PHP版梅花易起卦演算法實現
$keys = [
[
"坤為地",
"地天泰",
"地澤臨",
"地火明夷",
"地雷復",
"地風升",
"地水師",
"地山謙"
],
[
"天地否",
"乾為天",
"天澤履",
"天火同人",
"天雷無妄",
"天風姤",
"天水訟",
"天山遁"
],
[
"澤地萃",
"澤天夬",
"兌為澤",
"澤火革",
"澤雷隨",
"澤風中孚",
"澤水困",
"澤山咸"
],
[
"火地晉",
"火天大有",
"火澤睽",
"離為火",
"火雷噬嗑",
"火風鼎",
"火水未濟",
"火山旅"
],
[
"雷地豫",
"雷天大壯",
"雷澤歸妹",
"雷火豐",
"震為雷",
"雷風恆",
"雷水解",
"雷山小過"
],
[
"風地觀",
"風天小畜",
"風澤中孚",
"風火家人",
"風雷益",
"巽為風",
"風水渙",
"風山漸"
],
[
"水地比",
"水天需",
"水澤節",
"水火既濟",
"水雷屯",
"水風井",
"坎為水",
"水山旅"
],
[
"山地剝",
"山天大畜",
"山澤損",
"山火賁",
"山雷頤",
"山風蠱",
"山水蒙",
"艮為山"
]];
$binary_keys = [0x0, 0x7, 0x3, 0x5, 0x1, 0x6, 0x2, 0x4];
function validate($value)
{
return true;
}
function generateDiagrams($a, $b, $c)
{
global $keys, $binary_keys;
$diagrams = $sDiagrams = $hDiagrams = $bDiagrams = '';
if (validate([$a, $b, $c])) {
$a %= 8;
$b %= 8;
$c = $c % 6 === 0 ? 6 : $c % 6;
//本卦
$sDiagrams = $keys[$a][$b];
/**
* 互卦
* 上卦 3 4 5 爻
* 下卦 2 3 4 爻
*/
$diagrams = $binary_keys[$a] << 3 | $binary_keys[$b];
$upDiagramsKey = (0x1C & $diagrams) >> 2;
$downDiagramsKey = ($diagrams & 0xE) >> 1;
list($up_key, $down_key) = findKeyFromBinaryKeys($upDiagramsKey, $downDiagramsKey);
if ($up_key && $down_key) {
$hDiagrams = $keys[$up_key][$down_key];
}
//變爻
$diagrams = $diagrams ^ (0x1 << ($c - 1));
$upDiagramsKey = $diagrams >> 3;
$downDiagramsKey = $diagrams & 0x7;
list($up_key, $down_key) = findKeyFromBinaryKeys($upDiagramsKey, $downDiagramsKey);
if ($up_key && $down_key) {
$bDiagrams = $keys[$up_key][$down_key];
}
}
return [$sDiagrams, $hDiagrams, $bDiagrams];
}
function findKeyFromBinaryKeys($upKey, $downKey)
{
global $binary_keys;
return [array_search($upKey, $binary_keys), array_search($downKey, $binary_keys)];
}
var_dump(generateDiagrams(43, 82, 56));
6. Excel巨集實現
Sub 梅花易起卦()
Dim keys(8, 8) As String
keys(0, 0) = "坤為地"
keys(0, 1) = "地天泰"
keys(0, 2) = "地澤臨"
keys(0, 3) = "地火明夷"
keys(0, 4) = "地雷復"
keys(0, 5) = "地風升"
keys(0, 6) = "地水師"
keys(0, 7) = "地山謙"
keys(1, 0) = "天地否"
keys(1, 1) = "乾為天"
keys(1, 2) = "天澤履"
keys(1, 3) = "天火同人"
keys(1, 4) = "天雷無妄"
keys(1, 5) = "天風姤"
keys(1, 6) = "天水訟"
keys(1, 7) = "天山遁"
keys(2, 0) = "澤地萃"
keys(2, 1) = "澤天夬"
keys(2, 2) = "兌為澤"
keys(2, 3) = "澤火革"
keys(2, 4) = "澤雷隨"
keys(2, 5) = "澤風中孚"
keys(2, 6) = "澤水困"
keys(2, 7) = "澤山咸"
keys(3, 0) = "火地晉"
keys(3, 1) = "火天大有"
keys(3, 2) = "火澤睽"
keys(3, 3) = "離為火"
keys(3, 4) = "火雷噬嗑"
keys(3, 5) = "火風鼎"
keys(3, 6) = "火水未濟"
keys(3, 7) = "火山旅"
keys(4, 0) = "雷地豫"
keys(4, 1) = "雷天大壯"
keys(4, 2) = "雷澤歸妹"
keys(4, 3) = "雷火豐"
keys(4, 4) = "震為雷"
keys(4, 5) = "雷風恆"
keys(4, 6) = "雷水解"
keys(4, 7) = "雷山小過"
keys(5, 0) = "風地觀"
keys(5, 1) = "風天小畜"
keys(5, 2) = "風澤中孚"
keys(5, 3) = "風火家人"
keys(5, 4) = "風雷益"
keys(5, 5) = "巽為風"
keys(5, 6) = "風水渙"
keys(5, 7) = "風山漸"
keys(6, 0) = "水地比"
keys(6, 1) = "水天需"
keys(6, 2) = "水澤節"
keys(6, 3) = "水火既濟"
keys(6, 4) = "水雷屯"
keys(6, 5) = "水風井"
keys(6, 6) = "坎為水"
keys(6, 7) = "水山旅"
keys(7, 0) = "山地剝"
keys(7, 1) = "山天大畜"
keys(7, 2) = "山澤損"
keys(7, 3) = "山火賁"
keys(7, 4) = "山雷頤"
keys(7, 5) = "山風蠱"
keys(7, 6) = "山水蒙"
keys(7, 7) = "艮為山"
Dim binary_keys(8) As Integer
binary_keys(0) = &H0
binary_keys(1) = &H7
binary_keys(2) = &H3
binary_keys(3) = &H5
binary_keys(4) = &H1
binary_keys(5) = &H6
binary_keys(6) = &H2
binary_keys(7) = &H4
A = Sheet1.Range("H16").Value Mod 8
B = Sheet1.Range("I16").Value Mod 8
C = Sheet1.Range("J16").Value Mod 6
If (Not (CBool(C Xor 0))) Then
C = 6
End If
'本卦
Sheet1.Range("H21").Value = keys(A, B)'互卦'下卦 2 3 4 爻'上卦 3 4 5 爻
diagrams = binary_keys(A) * 2 ^ 3 Or binary_keys(B)
upDiagramsKey = (&H1C And diagrams) / 2 ^ 2
downDiagramsKey = (diagrams And &HE) / 2 ^ 1
For i = 0 To UBound(binary_keys) - 1If (Not (CBool(binary_keys(i) Xor upDiagramsKey))) Then
up_key = i
End IfIf (Not (CBool(binary_keys(i) Xor downDiagramsKey))) Then
down_key = i
End IfNext i
Sheet1.Range("I21").Value = keys(up_key, down_key)
'變爻
diagrams = diagrams Xor (&H1 * 2 ^ (C - 1))
upDiagramsKey = diagrams / 2 ^ 3
downDiagramsKey = diagrams And &H7
For i = 0 To UBound(binary_keys) - 1If (Not (CBool(binary_keys(i) Xor upDiagramsKey))) Then
up_key = i
End IfIf (Not (CBool(binary_keys(i) Xor downDiagramsKey))) Then
down_key = i
End IfNext i
Sheet1.Range("J21").Value = keys(up_key, down_key)
End Sub
7.參考
本文來自博客園,作者:淙淙溪流,轉載請註明原文鏈接:https://www.cnblogs.com/pitmanhuang/p/16186983.html