Discussion

BaZi – Deterministic life-charting from the Chinese calendar

  I've been fascinated by BaZi (八字), a Chinese calendrical system that maps
  birth date/time to Five Element interactions. Unlike Western astrology, it's
  essentially a deterministic lookup + combinatorial analysis — same inputs
  always produce the same chart.

  The core algorithm converts Gregorian dates to the Chinese Sexagenary cycle
  (天干地支), then derives Four Pillars (year/month/day/hour), each a pair of
  Heavenly Stem + Earthly Branch. From there it computes element balances,
  "Ten Gods" relationships, and luck period progressions.

  I built a web tool that runs this calculation and layers AI interpretation
  on top for plain-English explanations:

  https://xuanseal.com

  Some interesting technical challenges:

  - The Sexagenary cycle conversion requires handling the solar term calendar
    (节气), which doesn't align with Gregorian months. I ended up using
    astronomical algorithms rather than lookup tables for accuracy.

  - BaZi has ~30 named element interaction patterns ("Clash," "Combine,"
    "Punishment," etc.) that need to be evaluated across all four pillars
    simultaneously. Getting the combinatorial logic right was the trickiest part.

  - Separating deterministic calculation from AI interpretation was a deliberate
    design choice — the chart itself is math, the reading is LLM-generated.
    Users can verify the chart independently.

  Stack: Next.js 16, React 19, TypeScript, Drizzle/PostgreSQL, Tailwind v4.
  Three-locale i18n (en/zh/zh-hant) via next-intl.

  Happy to discuss the calendrical math or the Five Element system if anyone
  is curious.
2 points chenzige 8 months ago 0 comments

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton