合婚演算法之用JAVA實現本命卦合婚法
阿新 • • 發佈:2019-01-07
問題:我輸入 男方的生日:1980-01-01 01:01:01 女方生日:1980-01-01 01:01:01
跪求這樣一個八字合婚演算法
合婚軟體似乎很多,關鍵是怎麼去寫或者說演算法,網路上幾乎沒有類似文章
作為易學高手的我(大師♂羅莊)對告訴各位碼農如何製作合婚軟體 負有不可推卸的責任。
演算法介紹:
現在很多鄉村算命先生都用 呂才合婚法或本命卦合婚法。
我老師教我的也是本命卦合婚法,
這個演算法有很多版本,我這裡採用中華易帆風順研究院齊炳權老師演算法
原始:
http://blog.sina.com.cn/s/blog_62a4f99c0102dygx.html
一。本命卦數理:坎1,坤2,震3,巽4,中宮5(男坤,女艮),乾6,兌7,艮8,離9。
二。中華易帆風順研究院齊炳權老師總結出最快速的計算方法如下:
男性:11-出生年橫加(也為流年玄空飛星入中宮計算公式)
女性:4+出生年橫加
舉例:1989年出生的男性:11-(1+9+8+9)=11-(27)=11-(2+7)=2,即本命卦為坤卦;
1989年出生的女性 :4+(1+9+8+9)=4+(27)=4+9=(13)=1+3=4,即本命卦為巽卦 。
2012年出生的男性:11-(2+0+1+2)=11-5=6,即本命卦為乾卦;
2012年出生的女性:4+(2+0+1+2)=4+5=9,即本命卦為離卦。
結果可以看看原文
這裡用點程式碼實現下而已
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package luozhuanghehun; /** * 本命卦合婚 * * @author luozhuang 大師♂羅莊 */ public class Luozhuanghehun { enum sex { man, woman; } enum basicstring { 坎, 坤, 震, 巽, 乾, 兌, 艮, 離; } public String hehun(String man, String woman) { if (man.length() != 4 || woman.length() != 4) { return "輸入不正確"; } return peihun(getnumber(man,sex.man), getnumber(woman,sex.woman)); } public String peihun(String man, String woman) { return peihun(getnumber(man,sex.man), getnumber(woman,sex.woman)); } private String peihun(int man, int woman) { basicstring mang = basicsnumber(man, sex.man); basicstring womang = basicsnumber(woman, sex.woman); // 乾命男配艮命女 ,艮命男配乾命女; if (mang == basicstring.乾 && womang == basicstring.艮) { return "延年婚"; } if (womang == basicstring.乾 && mang == basicstring.艮) { return "延年婚"; } // 震命男配坎命女,坎命男配震命女; if (mang == basicstring.震 && womang == basicstring.坎) { return "延年婚"; } if (womang == basicstring.震 && mang == basicstring.坎) { return "延年婚"; } // 兌命男配坤命女,坤命男配兌命女; if (mang == basicstring.兌 && womang == basicstring.坤) { return "延年婚"; } if (womang == basicstring.兌 && mang == basicstring.坤) { return "延年婚"; } // 巽命男配離命女,離命男配巽命女; if (mang == basicstring.巽 && womang == basicstring.離) { return "延年婚"; } if (womang == basicstring.巽 && mang == basicstring.離) { return "延年婚"; } // 坎命男配巽命女,巽命男配坎命女; if (mang == basicstring.坎 && womang == basicstring.巽) { return "生氣婚"; } if (womang == basicstring.坎 && mang == basicstring.巽) { return "生氣婚"; } // 震命男配離命女,離命女配震命男; if (mang == basicstring.震 && womang == basicstring.離) { return "生氣婚"; } if (womang == basicstring.震 && mang == basicstring.離) { return "生氣婚"; } // 乾命男配兌命女,兌命男配乾命女; if (mang == basicstring.乾 && womang == basicstring.兌) { return "生氣婚"; } if (womang == basicstring.乾 && mang == basicstring.兌) { return "生氣婚"; } // 艮命男配坤命女,坤命男配艮命女。 if (mang == basicstring.艮 && womang == basicstring.坤) { return "生氣婚"; } if (womang == basicstring.艮 && mang == basicstring.坤) { return "生氣婚"; } // 坎命男配艮命女,艮命男配坎命女; if (mang == basicstring.艮 && womang == basicstring.坎) { return "天醫婚"; } if (womang == basicstring.艮 && mang == basicstring.坎) { return "天醫婚"; } // 坤命男配巽命女,巽命男配坤命女; if (mang == basicstring.坤 && womang == basicstring.巽) { return "天醫婚"; } if (womang == basicstring.坤 && mang == basicstring.巽) { return "天醫婚"; } // 震命男配乾命女,乾命男配震命女; if (mang == basicstring.震 && womang == basicstring.乾) { return "天醫婚"; } if (womang == basicstring.震 && mang == basicstring.乾) { return "天醫婚"; } // 兌命男配離命女,離命男配兌命女。 if (mang == basicstring.兌 && womang == basicstring.離) { return "天醫婚"; } if (womang == basicstring.兌 && mang == basicstring.離) { return "天醫婚"; } // 坎命男配乾命女,乾命男配坎命女; if (mang == basicstring.坎 && womang == basicstring.乾) { return "六煞婚"; } if (womang == basicstring.坎 && mang == basicstring.乾) { return "六煞婚"; } // 震命男配艮命女,艮命男配震命女; if (mang == basicstring.震 && womang == basicstring.艮) { return "六煞婚"; } if (womang == basicstring.震 && mang == basicstring.艮) { return "六煞婚"; } // 兌命男配巽命女,巽命男配兌命女; if (mang == basicstring.兌 && womang == basicstring.巽) { return "六煞婚"; } if (womang == basicstring.兌 && mang == basicstring.巽) { return "六煞婚"; } // 離命男配坤命女,坤命男配離命女。 if (mang == basicstring.離 && womang == basicstring.坤) { return "六煞婚"; } if (womang == basicstring.離 && mang == basicstring.坤) { return "六煞婚"; } // 坎命男配離命女,離命男配坎命女; if (mang == basicstring.坎 && womang == basicstring.離) { return "禍害婚"; } if (womang == basicstring.坎 && mang == basicstring.離) { return "禍害婚"; } //巽命男配震命女,震命男配巽命女; if (mang == basicstring.巽 && womang == basicstring.震) { return "禍害婚"; } if (womang == basicstring.巽 && mang == basicstring.震) { return "禍害婚"; } //乾命男配坤命女,坤命男配乾命女; if (mang == basicstring.乾 && womang == basicstring.坤) { return "禍害婚"; } if (womang == basicstring.乾 && mang == basicstring.坤) { return "禍害婚"; } //兌命男配巽命女,巽命男配兌命女; if (mang == basicstring.兌 && womang == basicstring.巽) { return "禍害婚"; } if (womang == basicstring.兌 && mang == basicstring.巽) { return "禍害婚"; } // 坎命男配坎命女,乾命男配乾命女; // // 坤命男配坤命女,兌命男配兌命女; // // 震命男配震命女,艮命男配艮命女; // // 巽命男配巽命女,離命男配離命女。 if (mang == womang) { return "伏位婚"; } // 坎命男配兌命女,兌命男配坎命女; if (mang == basicstring.坎 && womang == basicstring.兌) { return "五鬼婚"; } if (womang == basicstring.坎 && mang == basicstring.兌) { return "五鬼婚"; } // 震命男配坤命女,坤命男配震命女; if (mang == basicstring.震 && womang == basicstring.坤) { return "五鬼婚"; } if (womang == basicstring.震 && mang == basicstring.坤) { return "五鬼婚"; } // 離命男配艮命女,艮命男配離命女; if (mang == basicstring.離 && womang == basicstring.艮) { return "五鬼婚"; } if (womang == basicstring.離 && mang == basicstring.艮) { return "五鬼婚"; } // 乾命男配巽命女,巽命男配乾命女。; if (mang == basicstring.乾 && womang == basicstring.巽) { return "五鬼婚"; } if (womang == basicstring.乾 && mang == basicstring.巽) { return "五鬼婚"; } // 坎命男配坤命女,坤命男配坎命女; if (mang == basicstring.坎 && womang == basicstring.坤) { return "絕命婚"; } if (womang == basicstring.坎 && mang == basicstring.坤) { return "絕命婚"; } // 震命男配兌命女,兌命男配震命女; if (mang == basicstring.震 && womang == basicstring.兌) { return "絕命婚"; } if (womang == basicstring.震 && mang == basicstring.兌) { return "絕命婚"; } // 巽命男配艮命女,艮命男配巽命女; if (mang == basicstring.巽 && womang == basicstring.艮) { return "絕命婚"; } if (womang == basicstring.巽 && mang == basicstring.艮) { return "絕命婚"; } // 乾命男配離命女,離命男配乾命女。 if (mang == basicstring.乾 && womang == basicstring.離) { return "絕命婚"; } if (womang == basicstring.乾 && mang == basicstring.離) { return "絕命婚"; } return "輸入不正確"; } /** 數字選宮掛 * * @param number 數字 * @param isman 男人麼 * @return 屬於宮掛 */ public Luozhuanghehun.basicstring basicsnumber(int number, sex isman) { switch (number) { case 1: return basicstring.坎; case 2: return basicstring.坤; case 3: return basicstring.震; case 4: return basicstring.巽; case 5: if (isman == sex.man) { return basicstring.坤; } else { return basicstring.艮; } case 6: return basicstring.乾; case 7: return basicstring.兌; case 8: return basicstring.艮; case 9: return basicstring.離; } return null; } /** * 男性:11-出生年橫加(也為流年玄空飛星入中宮計算公式) 女性:4+出生年橫加 * 1989年出生的男性:11-(1+9+8+9)=11-(27)=11-(2+7)=2,即本命卦為坤卦 * * @param year 輸入年份字元 * @return 過載getnumber */ public int getnumber(String year, sex isman) throws NumberFormatException { int yearnumber = Short.parseShort(year); return getnumber(yearnumber,isman); } /** * 男性:11-出生年橫加(也為流年玄空飛星入中宮計算公式) 女性:4+出生年橫加 * 1989年出生的男性:11-(1+9+8+9)=11-(27)=11-(2+7)=2,即本命卦為坤卦 * * @param year 輸入年份數字 * @return 返回結果 */ public int getnumber(int year, sex isman) { int m = ((int) (year / 1000) % 10); int h = ((int) (year / 100) % 10); int s = ((int) (year / 10) % 10); int g = year % 10; int sum = m + h + g + s; int result; if (isman == sex.man) { result = 11 - ((int) (sum / 10) % 10) - (sum % 10); } else { result = 4+ ((int) (sum / 10) % 10) + (sum % 10); } if(result>10) { result=result-9;//如果超過10,原文沒有寫怎麼做,我自己推的 } return result; } /** * @param args the command line arguments */ public static void main(String[] args) { Luozhuanghehun my = new Luozhuanghehun(); String result=my.hehun("1956", "1856"); System.out.println(my.getnumber("1956",sex.man)); System.out.println(my.basicsnumber(my.getnumber("1956",sex.man),sex.man)); System.out.println(my.getnumber("1856",sex.woman)); System.out.println(my.basicsnumber(my.getnumber("1856",sex.woman),sex.woman)); System.out.println(result); } }