I-Ching pair binary computer

10

Introduction

I Ching is an ancient divination text and the oldest of the Chinese classics. It uses a type of divination called cleromancy, which produces apparently random numbers.

The basic unit of the Zhou yi is the hexagram (卦 guà), a figure composed of six stacked horizontal lines (爻 yáo). Each line is either broken or unbroken. The received text of the Zhou yi contains all 64 possible hexagrams

The King Wen sequence present the 64 hexagrams, grouped into 32 pairs. For 28 of the pairs, the second hexagram is created by turning the first upside down (i.e. 180° rotation). The exception to this rule is for symmetrical hexagrams that are the same after rotation. Partners for these are given by inverting each line: solid becomes broken and broken becomes solid.

 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
    1        2        3        4            5        6        7        8   

 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
    9       10       11       12           13       14       15       16   

 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
   17       18       19       20           21       22       23       24   

 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
   25       26       27       28           29       30       31       32   

 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
   33       34       35       36           37       38       39       40   

 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
   41       42       43       44           45       46       47       48   

 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
   49       50       51       52           53       54       55       56   

 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄      ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
 ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
 ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
   57       58       59       60           61       62       63       64   

Request

The goal of this is to create a little tool that compute pair for a given hexagram value.

  • For translating this into binary, I use: broken line = 0, unbroken line = 1, so hexagram Number 1 has binary value 63.

  • The tool take exactly one argument, a number between 1 to 64, as hexagram pair request and produce two exagram containing requested number and his oposite (explanation: if arg is odd, the output must contain hexagram from arg and arg + 1, but if arg is even, the output must contain hexagram from arg - 1 and arg).

  • The tool have to rotate by 180° requested hexagram while not symetric, or invert them when symetric.

  • No map are authorized except this one, wich could be stored in any form you'll find usefull

     {  1:63,    3:34,    5:58,    7:16,    9:59,   11:56,   13:47,   15: 8,  
       17:38,   19:48,   21:37,   23: 1,   25:39,   27:33,   29:18,   31:14,  
       33:15,   35: 5,   37:43,   39:10,   41:49,   43:62,   45: 6,   47:22,  
       49:46,   51:36,   53:11,   55:44,   57:27,   59:19,   61:51,   63:42 }
    

    This map hold binary value of each 1st exagram from pairs. So for each pair, 1st has to be taken from this map, but second have to be computed conforming to previous rule.

  • Ouput must contain two hexagram and his numbers. Sample:

    iChingHexaPair 1
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
        1        2   
    
    iChingHexaPair 14
     ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄ ▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
     ▄▄▄ ▄▄▄  ▄▄▄▄▄▄▄
     ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄
       13       14   
    
  • Standard loophole applies

  • Please avoid non-free language or post output for full test cases.

This is a , so the shortest answer in characters wins.

Shortest by language

<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = document.referrer.split("/")[4]; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 0; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "//api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "//api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(42), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

F. Hauri

Posted 2015-12-27T12:40:52.167

Reputation: 2 654

Vaguely related. – Martin Ender – 2015-12-27T12:54:13.517

@MartinBüttner Yes, thanks! Maybe could we add a tag: [tag:I-Ching] (I did not foud them while searched for I-Ching, hexagram and so) But my question if more about rotating binary by 180° – F. Hauri – 2015-12-27T13:27:51.053

2Note that currently the standard loophole regarding non-free languages applies only to [tag:cops-and-robbers] challenges. – Alex A. – 2015-12-27T21:59:39.733

@AlexA.Question modified: non-free language are not welcome but not forbiden, Output sample are required for non-free languages. – F. Hauri – 2015-12-28T05:59:34.720

Answers

4

Python 2, 65 61

Generates unicode I-Ching hexagram pairs

def t(a):
 b=a+a%2
 for c in b-1,b:
  print unichr(19903+c),c

(saved 4 thanks to @Sherlock9)

Example input and output:

>>> t(1)
䷀ 1
䷁ 2
>>> t(14)
䷌ 13
䷍ 14

Willem

Posted 2015-12-27T12:40:52.167

Reputation: 1 528

1I think you can save 4 bytes with b=a+a%2 – Sherlock9 – 2015-12-29T17:17:15.893

That's a loophole: there is no binary calculator! – F. Hauri – 2015-12-29T17:30:13.843

@F.Hauri: It doesn't say there needs to be one in the question at all. – Deusovi – 2015-12-30T06:43:02.113

@Deusovi (1) In the title, (2) in the first line of request, (3) At least, it break fourth rule: 1st has to be taken from this map! – F. Hauri – 2015-12-30T07:32:02.023

1@F: You say the goal is to compute the pair but then you just have to output the hexagram pairs. The 'table' is built into Unicode instead of in a text file - what's wrong with that? – Deusovi – 2015-12-30T07:39:39.047

@Deusovi I said *The goal is to compute*!! The table in unicode is not the table I submit: It's two time bigger! (and built-in -> loophole!!) – F. Hauri – 2015-12-30T08:00:47.447

3

Python 2, 252 245 244

Now including binary computation (saving 8 chars thanks to @Sherlock9):

d='?":\x10;8/\x08&0%\x01\'!\x12\x0e\x0f\x05+\n1>\x06\x16.$\x0b,\x1b\x133*'
k=lambda l:'\n'.join("{:06b}".format(l)).replace('1',u'▄▄▄▄▄▄▄').replace('0',u'▄▄▄ ▄▄▄')
def t(a):
 j=a+a%2-1;m=ord(d[j/2]);b=k(m);r=b[::-1];print b,j,'\n\n',r if r!=b else k(63-m),j+1

Example input and output:

>>> t(1)
▄▄▄▄▄▄▄
▄▄▄▄▄▄▄
▄▄▄▄▄▄▄
▄▄▄▄▄▄▄
▄▄▄▄▄▄▄
▄▄▄▄▄▄▄ 1 

▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄ 2
>>> t(3)
▄▄▄▄▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄▄▄▄▄
▄▄▄ ▄▄▄ 3 

▄▄▄ ▄▄▄
▄▄▄▄▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄ ▄▄▄
▄▄▄▄▄▄▄ 4

Willem

Posted 2015-12-27T12:40:52.167

Reputation: 1 528

1You can change j=a+a%2-1 to j=a-1, since you're using integer division, but you'll need to use j+1 and j+2 in the print statement at the end. That still saves you 2 bytes. Also using m=ord(d[j/2]); and m in the two places you call k() will save 6 bytes. Also, is the first 0 in "{0:06b}".format(l) strictly necessary? If not, that's another byte. Finally, if you switch to Python 3, you can get rid of the us in front of ▄▄▄▄▄▄▄, but print will need parentheses, so that's only one more byte. I'll keep you posted on anything else I think up. – Sherlock9 – 2015-12-30T04:27:48.337

Unfortunately I can't change j=a+a%2-1 to j=a-1 as it should output the pairs 13 and 14 when I input 14. Thanks for your suggestions – Willem – 2015-12-30T06:12:45.290

Ah, you're right. Incidentally, I'm having trouble running this code in Ideone. Can you take a look? http://ideone.com/GdWu4e

– Sherlock9 – 2015-12-30T10:33:38.017

@Sherlock9 Ideone seems to be having problems with the unicode characters http://ideone.com/FeK1rK

– Willem – 2015-12-30T12:00:25.307

1Ah, thanks. To save another byte, I'd write def t(a):j=a+a%2-1;etc.. Put it all one line, essentially. And you can write k=lambda l: to save another byte. – Sherlock9 – 2015-12-31T10:43:27.610

2

Pure bash 252

u=(▅▅▅{' ',▅}▅▅▅);m=_yWgXUL8CMB1Dxief5HaN@6mKAbIrjPG;s=$[($1-1)/2];r=$[64#${m:s:1}];for i in {0..5};do echo ${u[(r>>i)&1]} ${u[((r>>5)%2==r%2)&((r>>4)%2==(r>>1)%2)&((r>>3)%2==(r>>2)%2)?1^(r>>i)&1:(r>>(5-i))&1]};done;echo $[s*2+1] $[s*2+2]

with 2 more linebreak:

u=(▅▅▅{' ',▅}▅▅▅);m=_yWgXUL8CMB1Dxief5HaN@6mKAbIrjPG;s=$[($1-1)/2];r=$[64#${m:s
:1}];for i in {0..5};do echo ${u[(r>>i)&1]} ${u[((r>>5)%2==r%2)&((r>>4)%2==(r>>
1)%2)&((r>>3)%2==(r>>2)%2)?1^(r>>i)&1:(r>>(5-i))&1]};done;echo $[s*2+1] $[s*2+2]

Tests:

for k in 1 15 28 34;do set -- $k;echo request: $k;
u=(▅▅▅{' ',▅}▅▅▅);m=_yWgXUL8CMB1Dxief5HaN@6mKAbIrjPG;s=$[($1-1)/2];r=$[64#${m:s
:1}];for i in {0..5};do echo ${u[(r>>i)&1]} ${u[((r>>5)%2==r%2)&((r>>4)%2==(r>>
1)%2)&((r>>3)%2==(r>>2)%2)?1^(r>>i)&1:(r>>(5-i))&1]};done;echo $[s*2+1] $[s*2+2]
done;echo $[s*2+1] $[s*2+2]; done
request: 1
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
1 2
request: 15
▅▅▅ ▅▅▅ ▅▅▅ ▅▅▅
▅▅▅ ▅▅▅ ▅▅▅ ▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅ ▅▅▅ ▅▅▅ ▅▅▅
▅▅▅ ▅▅▅ ▅▅▅ ▅▅▅
15 16
request: 28
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
27 28
request: 34
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅ ▅▅▅
▅▅▅▅▅▅▅ ▅▅▅▅▅▅▅
▅▅▅▅▅▅▅ ▅▅▅▅▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
▅▅▅ ▅▅▅ ▅▅▅▅▅▅▅
33 34

F. Hauri

Posted 2015-12-27T12:40:52.167

Reputation: 2 654