Bagua (八卦)

The binary system was adopted by Ancient Chinese to represent natural phenomena and philosophic ideas. For example, there are eight trigrams in Bagua (八卦; "eight symbols"). Each trigram consists of three lines, where each line either "broken" or "unbroken," respectively representing yin or yang.

These eight trigrams are:
  • 乾 (☰) - sky
  • 兌 (☱) - rain
  • 離 (☲) - fire
  • 震 (☳) - thunder
  • 巽 (☴) - wind
  • 坎 (☵) - water
  • 艮 (☶) - mountain
  • 坤 (☷) - earth
先天八卦

To divine (卜卦) using the 8 trigrams, a fortune-teller may toss 3 coins to obtain a trigram. This is the famous "three-coin method. For example, if the first coin is Tail, while the second and the third coins are heads, you get a "wind" (巽☴) . If the first and the second coins are tails, while the third is a head, you get a "mountain" (艮☶) .
Divination Coins

In this exercise, we are going to write a program which simulates the three-coin method.
  1. The user input the number of iterations he/she wants to conduct.
  2. In each iteration, the computer simulates the tossing of three coins, print out the corresponding trigram, and record the occurrence of each trigram.
  3. For readability, every five trigrams are separated by a space, and 50 trigrams by a new line.
  4. At the end of the simulation, the program print out the totally occurrence of each trigram.

Your program may run as follows:

Input the number of iterations -- 112

☲☶☷☵☶ ☵☶☷☱☲ ☳☰☵☴☷ ☵☱☵☷☰ ☷☳☳☷☳ ☳☷☷☰☶ ☵☵☴☱☵ ☳☴☱☵☷ ☰☳☷☶☱ ☳☷☲☲☲
☰☶☷☵☰ ☰☵☷☵☴ ☵☰☷☳☱ ☲☷☲☴☶ ☵☰☲☲☷ ☱☷☲☴☴ ☴☵☷☳☶ ☷☶☵☷☷ ☱☶☶☷☲ ☷☲☱☴☲
☱☰☰☳☱ ☳☶☴☱☰ ☴☱
乾(☰) 12
兌(☱) 13
離(☲) 13
震(☳) 12
巽(☴) 11
坎(☵) 16
艮(☶) 12
坤(☷) 23