text:
I-Ching pair binary computer
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 code-golf, so the shortest answer in characters wins.
Shortest by language

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

Vaguely related.

@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°

Note that currently the standard loophole regarding non-free languages applies only to [tag:cops-and-robbers] challenges.

@AlexA.Question modified: non-free language are not welcome but not forbiden, Output sample are required for non-free languages.

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

I think you can save 4 bytes with b=a+a%2

That's a loophole: there is no binary calculator!

@F.Hauri: It doesn't say there needs to be one in the question at all.

@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: 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 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 I think that this is as valid as any other submission. This does exactly what the question is asking for. Furthermore, you'd be hard-pressed to find a language that wouldn't allow this and isn't an esolang, and therefore doesn't have this Unicode table "built in".

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

You 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.

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

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

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

Ah, 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.

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


text:
Produce an XOR table
Introduction
XOR is a digital logic gate that implements an exclusive or. Most of the times, this is shown as ^. The four possible outcomes in binary:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

This can also be seen as addition modulo 2 in binary. In decimal, we need to convert the decimal to binary, 35 = 100011 and 25 = 11001.To compute the XOR value, we place them on top of each other:
100011
 11001 ^
--------
111010  = 58 in decimal

The task: When given an integer value N greater than 1, output an XOR table with the size N + 1. For example, N = 5:
 0 1 2 3 4 5
 1 0 3 2 5 4
 2 3 0 1 6 7
 3 2 1 0 7 6
 4 5 6 7 0 1
 5 4 7 6 1 0

You can see that there is one space in front of each number, because the highest amount in the table has length 1. However, if we take N = 9, we get the following grid:
  0  1  2  3  4  5  6  7  8  9
  1  0  3  2  5  4  7  6  9  8
  2  3  0  1  6  7  4  5 10 11
  3  2  1  0  7  6  5  4 11 10
  4  5  6  7  0  1  2  3 12 13
  5  4  7  6  1  0  3  2 13 12
  6  7  4  5  2  3  0  1 14 15
  7  6  5  4  3  2  1  0 15 14
  8  9 10 11 12 13 14 15  0  1
  9  8 11 10 13 12 15 14  1  0

The highest value has length 2, so the value is right-aligned to length 3 (highest length + 1).
Rules:

Leading whitespace is not mandatory, only if used (or not) consistently
You must output a table in the form shown above.
The padding between columns should be as small as possible
This is code-golf, so the submission with the least amount of bytes wins!

How much padding is allowed between columns? Only the minimal possible amount?

@MartinBüttner Yes, the minimal possible amount. I'll add that to the description.

Related http://codegolf.stackexchange.com/questions/67183/a-multiplication-table-for-the-cheela

Looking at the examples output an XOR table with the size N+1

What is the max value for N? ... (for N==1000000 the size of the table would be near 10 Terabyte)

@edc65 It should 'theoretically' work for N = 1000000, but I'll probably test up to 100

I'm looking at the diagonals of those squares now…0, 1 1, 2 0 2, 3 3 3 3, 4 2 0 2 4, 5 5 1 1 5 5…looks like there might be some interesting properties in there, à la Pascal's Triangle.

I think you need more clarification with regard to the padding. In particular, the example 9*9 grid doesn't look like it has minimal padding to me; there are two spaces between the first and second columns, and you could get away with one without even messing up alignment.

@BlacklightShining but then the columns would be of different size, I think the padding is right as is now.

Oh hey, it's my avatar!

@histocrat That looks quite nice haha :)

@edc65 Could be worded as minimal padding while keeping all columns the same width, then.

MATL, 10 bytes
0i2$:tXgZ~

The compiler (and in particular this program) now seems to work in Octave, although it still needs some refinement. You can provisionally use this GitHub commit.
Edit (Mar 30 '16): Try it online!
Example
>> matl 0i2$:tXgZ~
> 9
0  1  2  3  4  5  6  7  8  9
1  0  3  2  5  4  7  6  9  8
2  3  0  1  6  7  4  5 10 11
3  2  1  0  7  6  5  4 11 10
4  5  6  7  0  1  2  3 12 13
5  4  7  6  1  0  3  2 13 12
6  7  4  5  2  3  0  1 14 15
7  6  5  4  3  2  1  0 15 14
8  9 10 11 12 13 14 15  0  1
9  8 11 10 13 12 15 14  1  0

Explanation
0i2$:       % vector 0, 1, 2, ... up to input number
t           % duplicate
Xg          % nd-grid
Z~          % bitxor

Compiler working in Octave coming soon...

... well, hopefully. Any idea about this, anyone?

Definitely the right tool for the job. +1

After some tweaking, the compiler seems to work in Octave (4.0.0). I need to do more testing, but all the programs I've tried, including this one, work. While I post a new release, here's a link to the current GitHub commit to run this code in Octave. The language hasn't changed (it's still release 5.0.0), so it's earlier than this challenge

Bash + BSD utils, 45
eval echo \$[{0..$1}^{0..$1}]|rs -jg1 $[$1+1]

I've been waiting a long time to find a use for rs.  This seems to be a good one.  rs may need to be installed on Linux systems.  But it runs right out of the box on OS X.

$1 expands to N, and thus echo \$[{0..$1}^{0..$1}] expands to echo $[{0..N}^{0..N}]
This is then evaled:
The brace expansion expands to $[0^0] $[0^1] $[0^2] ... $[0^N] ... $[N^N]
This is a series of xor arithmetic expansions which expand to one line of terms
rs (reshape) reshapes this line to N+1 rows.  -j right justifies, and -g1 gives a gutter-width of 1.  This ensures the final output table has minimal width between columns.

I've tested up to N=1000, which took 3.8 seconds.  Large N is theoretically possible, though bash will run out of memory at some point with the (N+1)² memory usage of the brace expansion.

C, 114 128 152
Edit Simplified space counting, inspired by the work of Khaled A Khunaifer
A C function that follows the specs.
T(n){int i=0,j,x=1,d=0;while(x<=n)x+=x,++d;for(;i<=n;i++)for(j=0;j<=n;j++)printf("%*d%c",d*3/10+1,i^j,j<n?32:10);}

Try it insert n as input, default 9
Less golfed
T(n)
{
   int i=0, j, x=1,d=0;
   while(x<=n) x+=x,++d; // count the digits
   // each binary digit is approximately 0.3 decimal digit
   // this approximation is accurate enough for the task
   for(;i<=n;i++)
     for(j=0;j<=n;j++)
       printf("%*d%c",d*3/10+1,
              i^j,
              j < n ? 32:10); // space between columns, newline at end
}

91 bytes

@ceilingcat nice. Post it as an answer.

JavaScript (ES6) 120 122
Edit 2 bytes saved thx ETHproductions
An anonymous function. Note: the number in the table are limited to 7 digits, that is more than reasonable given the overall size of a table allowing for bigger numbers
Now I should find a shorter way to get the max columns size, avoiding logarithms
n=>(a=Array(n+1).fill(-~Math.log10(2<<Math.log2(n)))).map((m,i)=>a.map((z,j)=>`       ${i^j}`.slice(~m)).join``).join`
`

Test

f=n=>(a=Array(n+1).fill(-~Math.log10(2<<Math.log2(n)))).map((m,i)=>a.map((z,j)=>`       ${i^j}`.slice(~m)).join``).join`\n`

function update() {
  var v=+I.value
  O.textContent = f(v)
}

update()
N: <input id=I type=number value=9 oninput='update()'>

Awesome, love the use of ~m to capture an extra space. Using a template string can save two bytes: (z,j)=>`(7 spaces)${i^j}`.slice(~m)

@ETHproductions 1) good suggestion, thanks 2) how did you manage to put a ... (I cannot even ask it) ... a char(96) inside 2 char(96)?

Aha, you just use multiple backticks, like so: (ignore this padding) ``abc`def`` (ignore this too) Shows up like this: abc`def

C, 149 bytes
int i=0,j,n,k=2;char b[256];scanf("%d",&n);while((k*=2)<=n);k^=k-1;while(i++<=n&&putchar(10))for(j=0;j<=n;j++)printf(" %*d",sprintf(b,"%d",k),i-1^j);
---------

Detailed
#include <stdio.h>

int main()
{
    int i=0, j, n, k=2;
    char b[256] = { 0 };

    scanf("%d", &n);

    // find max xor value in the table
    while((k*=2)<=n); k^=k-1;

    printf("> %d ~ %d", k, sprintf(b,"%d",k));

    while(i++ <= n && putchar(10))
    {
        for(j = 0; j <= n;j++)
        {
            printf(" %*d", sprintf(b,"%d",k), (i-1)^j);
        }
    }

    return 0;
}

Just like your java post, there is no attempt to align correctly the columns. That's the only difficult part of this challenge. This code gives wrong output when input < 8 or > 64.

@edc65 I found out how to align, the max xor value is binary 11..1 to the significant one in the input value n, can be done by first finding the nearest power of 2, then xor it with the previous number, 0001 xor 1110 = 1111

Good, you are on the right track now. Still, you should test more: the loop with k gives wrong result for n=8 (and your short answer does not initialize the local variable i to 0)

This simpler loop should do: for(k=1;k<=n;)k*=2;k--;. Now I see that is much shorter than my C attempt to the same (mine is better for performance, but performance does not matter in this challenge)

@edc65 you need to do 2^k xor 2^k -1 for max{2^k<=n} or 2^k -1 for min{2^k>=n}. to get all 11..1 in there

In fact, no. if k is a power of 2 (like 100000 in binary) you just thave to subtract 1 to get al the ones (having 11111). Simply k has to be bigger, that's why I test k and not k*2

@edc65 you're right, while(k*2<n) should be while(k*2<=n), fixed now

132 bytes

MathCAD, 187 Bytes

MathCAD handles built in tables easily - but has absolutely no bitwise Xor, nor decimal to binary or binary to decimal converters.  The for functions iterate through the possible values.  The i, a2, Xa and Xb place hold.  The while loop actively converts to binary, and while converting to binary also performs the xor function (the little cross with the circle around it).  It stores the binary number in a base-10 number consisting of 0's and 1's.  This is then converted before being stored in the M matrix via the summation function.
This can easily be golfed down (if only by swapping out the placeholders for shorter ones), but I figured I'd post it and see if anyone can golf down the binary to decimal converter more than anything else.

C, 103 bytes
Y(n){int i,j=n++;char*f="%2u";while(j/=8)++f[1];for(;j<n;++j,puts(""))for(i=0;i<n;++i)printf(f,i^j);}

Welcome to Programming Puzzles & Code Golf! For what I can see, your answer, as unfortunately many others here, completey miss the column alignment point.

Try it with input 5 (too much space between columns) or 65 (too few)

this would be ok at last until 512, at last here...

Python 3, 133 131 bytes
import math
n=int(input())
r,p=range(n+1),print
for y in r:[p(end='%%%dd '%len(str(2**int(math.log2(n)+1)-1))%(x^y))for x in r];p()

Jelly, 7 bytes
0r©^'®G

Try it online!
How it works
0r©^'®G  Main link. Input: n (integer)

0r       Range; yield [0, ..., n].
  ©      Save the range in the register.

     ®   Yield the range from the register.
   ^'    XOR each integer in the left argument with each integer in the right one.
      G  Grid; separate rows by newlines, columns by spaces, with a fixed width for
         all columns. Since the entries are numeric, align columns to the right.

Congrats on your 1000th answer :)

R, 38 bytes
Usually R requires a lot of bytes just to format the output. In this case it's quite the opposite. outer which is usually refers to the outer product of two arrays, can when supplied a function perform this across the margins of the vectors. In this case, we apply the bitwise XOR function bitwXor.
names(x)=x=1:scan();outer(x,x,bitwXor)

CJam, 29 27 bytes
ri:X),_ff{^s2X2b,#s,)Se[}N*

Test it here.
Explanation
ri      e# Read input and convert to integer.
:X      e# Store in X.
),      e# Get range [0 1 ... X].
_ff{    e# Nested map over all repeated pairs from that range...
  ^     e#   XOR.
  s     e#   Convert to string.
  2     e#   Push 2.
  X2b,  e#   Get the length of the base-2 representation of X. This is the same as getting
        e#   getting the base-2 integer logarithm and incrementing it.
  #     e#   Raise 2 to that power. This rounds X up to the next power of 2.
  s,    e#   Convert to string and get length to determine column width.
  )     e#   Increment for additional padding.
  Se[   e#   Pad string of current cell from the left with spaces.
}
N*      e# Join with linefeeds.

Well, that was quick haha

k4, 50 bytes
{-1@" "/:'(-|//#:''x)$x:$2/:''~x=/:\:x:0b\:'!1+x;}

E.g.:
  {-1@" "/:'(-|//#:''x)$x:$2/:''~x=/:\:x:0b\:'!1+x;}9
 0  1  2  3  4  5  6  7  8  9
 1  0  3  2  5  4  7  6  9  8
 2  3  0  1  6  7  4  5 10 11
 3  2  1  0  7  6  5  4 11 10
 4  5  6  7  0  1  2  3 12 13
 5  4  7  6  1  0  3  2 13 12
 6  7  4  5  2  3  0  1 14 15
 7  6  5  4  3  2  1  0 15 14
 8  9 10 11 12 13 14 15  0  1
 9  8 11 10 13 12 15 14  1  0

Mathematica, 108 bytes
StringRiffle[Thread[Map[ToString,a=Array[BitXor,{#,#}+1,0],{2}]~StringPadLeft~IntegerLength@Max@a],"
"," "]&

Disregard the error, it's just Thread not knowing what it's doing.

Emacs Lisp, 193 bytes
(defun x(n)(set'a 0)(set'n(1+ n))(while(< a n)(set'b 0)(while(< b n)(princ(format(format"%%%ss "(ceiling(log(expt 2(ceiling(log n 2)))10)))(logxor a b)))(set'b(1+ b)))(set'a(1+ a))(message"")))

Ungolfed:
(defun x(n)
  (set'a 0)
  (set'n(1+ n))
  (while(< a n)
    (set'b 0)
    (while(< b n)
      (princ
        (format
          ;; some format string magic to get the length of the longest
          ;; possible string as a format string
          (format "%%%ss " (ceiling(log(expt 2(ceiling(log n 2)))10)))
          (logxor a b)))
      (set'b(1+ b)))
    (set'a(1+ a))
    ;; new line
    (message"")))

The output is sent to the *Message* buffer, which would be stdout if x were to be used inside a script.
(x 9)
 0  1  2  3  4  5  6  7  8  9
 1  0  3  2  5  4  7  6  9  8
 2  3  0  1  6  7  4  5 10 11
 3  2  1  0  7  6  5  4 11 10
 4  5  6  7  0  1  2  3 12 13
 5  4  7  6  1  0  3  2 13 12
 6  7  4  5  2  3  0  1 14 15
 7  6  5  4  3  2  1  0 15 14
 8  9 10 11 12 13 14 15  0  1
 9  8 11 10 13 12 15 14  1  0

Python 2, 114 bytes
It took some looking to find a way to do variable-width padding in .format() (some, not a lot) and get it right-adjusted, but I think I've got it all to spec now. Could use more golfing in that width calculation though.
N=input()+1
for i in range(N):print''.join(' {n:>{w}}'.format(w=len(`2**(len(bin(N))-2)`),n=i^r)for r in range(N))

Pyke, 8 bytes
hD]UA.&P

Explanation:
         - auto-add eval_or_not_input() to the stack
h        - increment the input
 D]      - Create a list containing [inp+1, inp+1]
   U     - Create a 2d range
    A.^  - Deeply apply the XOR function to the range
       P - print it out prettily

Try it here

Caché ObjectScript, 127 bytes
x(n)s w=$L(2**$bitfind($factor(n),1,100,-1))+1 f i=0:1:n { w $j(i,w) } f i=1:1:n { w !,$j(i,w) f j=1:1:n { w $j($zb(i,j,6),w) } }

Detailed:
x(n)
 set w=$Length(2**$bitfind($factor(n),1,100,-1))+1
 for i=0:1:n {
     write $justify(i,w)
 }
 for i=1:1:n {
     write !,$justify(i,w)
     for j=1:1:n {
         write $justify($zboolean(i,j,6),w)
     }

 }

Go, 145 bytes
A function literal which prints to STDOUT. Abuses Sprintf heavily.
import ."fmt"
func(n int){s:=Sprintf
n++
for i:=0;i<n*n;i++{Printf(s(" %%%dd",len(s("%d",1<<len(s("%b",n-1))-1))),i/n^i%n)
if-^i%n<1{Println()}}}

Try it online! - it appears the Go installation on TIO is older than on my machine, this code runs perfectly locally:

go run "xortable.go" (with n=10)
  0  1  2  3  4  5  6  7  8  9 10
  1  0  3  2  5  4  7  6  9  8 11
  2  3  0  1  6  7  4  5 10 11  8
  3  2  1  0  7  6  5  4 11 10  9
  4  5  6  7  0  1  2  3 12 13 14
  5  4  7  6  1  0  3  2 13 12 15
  6  7  4  5  2  3  0  1 14 15 12
  7  6  5  4  3  2  1  0 15 14 13
  8  9 10 11 12 13 14 15  0  1  2
  9  8 11 10 13 12 15 14  1  0  3
 10 11  8  9 14 15 12 13  2  3  0

Explanation
First, we declare the function's arguments (a single integer n) and alias Sprintf to s, as we use it many times later.

func(n int){s:=Sprintf
n++
...
}

Notice that we also increment n. Because the table goes up to n and includes, we actually want n+1 rows. Incrementing n here saves bytes later.
Next, we declare the loop; rather than using a two-dimensional loop, we can simply loop one variable i up to n*n, and use i/n and i^n to access the current coordinates.
for i:=0;i<n*n;i++{...}

Now comes the string padding. To work out the padding required, we need to find the largest entry in the table. This will be n, but with all its non-leading binary 0s changed to 1s. So, we format n into its binary representation, find its length, right-shift 1 by this amount, and decrement.
1<<len(s("%b",n-1))-1

We now format this into base 10 and find its length.
len(s("%d",...))

This, plus 1 is the width that entries should be padded to. Using %Kd pads an integer with spaces to width K, so we create the padding string by using Sprintf once again (note that using a leading space here is a byte shorter than using a +1 for the length):
s(" %%%dd",...)

Now, we print the entry in the XOR table (given by i/n^i%n) via this string format:
Printf(...,i/n^i%n)

Finally, if we have reached the end of a row, we output a newline. We check if (i+1) % n == 0 in the golfiest way possible:
if-^i%n<1{Println()}

Stax, 9 bytes
üvx`₧¥ⁿ∙√

Run and debug it

Vyxal Rj, 21 bytes
Ẋƛ÷꘍;:GSL£:L√ẇƛvS¥v↳Ṅ

Try it Online!
Ẋ                     # Cartesian product with self
 ƛ  ;                 # Map to...
  ÷꘍                  # xor
     :GSL£            # Store the largest's length in the register
          :L√ẇ        # Squareify
              ƛ       # Map to...
               vS     # Stringified
                 ¥v↳  # Padded
                    Ṅ # Joined by spaces
                      # (J flag) joined by newlines

Brachylog, 58 bytes
<L&⟦gjẋ{ḃᵐ↔ᵐz₁-ᵐ↔cẹ~ḃṫ↔}ᵐP,Ṣzztg;Pz{z₁tᵐ↔c}ᵐġ↙L{~ṇṇ₂~ṇ₁ẉ}ᵐ

Try it online!
I don't entirely regret writing this... only took one hour...
    {...}ᵐ    XOR (and do a bit of other stuff to) each pair from
   ẋ          the flat Cartesian product of
⟦gj           [0 .. input] with itself.

{                }
 ḃᵐ                 Get the binary representation of each argument
   ↔ᵐ               least significant bit first.
     z₁             Non-cycling zip.
       -ᵐ           Subtract each pair/singleton.
         ↔          Reverse back.
          cẹ        Concatenate then explode--remove signs and leading zeroes.
            ~ḃ      Convert from binary.
              ṫ     Convert to string.
               ↔    Reverse again.

P                       Let the result of that mess be P.
 ,Ṣ                     Append " ",
   zz                   cycle each element to the length of the longest,
     t                  then get just the cycled space back.
      g;Pz              Pair it with each element of P.
          {      }ᵐ     For each pair:
           z₁           non-cycling zip.
             tᵐ         take the last element of each pair or singleton,
               ↔        reverse back,
                c       and concatenate back to a string.

        ġ                 Split that result into slices of a length
<L& ...  ↙L               equal to the least integer greater than the input.
           {        }ᵐ    For each slice:
            ~ṇ            join it on newlines,
              ṇ₂          split it on newlines and spaces simultaneously,
                ~ṇ₁       join it on spaces,
                   ẉ      and print it with a trailing newline.
                          (~ṇ₁ can't be used for lists with strings which
                          already contain spaces, because they couldn't
                          result from ṇ₁--that being split on spaces

Python 2, 77 bytes
n=input()+1
t=range(n)
for i in t: print "%3d"*n % tuple([x^i for x in t])

Welcome to Programming Puzzles & Code Golf! For what I can see, your answer, as unfortunately many others here, completey misses the column alignment point.

J, 10 bytes
XOR/~@,~i.

Try it online!

Small Basic, 499 bytes
A script that takes input from the TextWindow object and outputs to the same
a=TextWindow.Read()
For y=0To a
For x=0To a
n=x
b()
z1=z
n=y
b()
l=Math.Max(Array.GetItemCount(z),Array.GetItemCount(z1))
o=0
For i=1To l
If z1[i]<>z[i]And(z[i]=1Or z1[i]=1)Then
z2=1
Else
z2=0
EndIf
o=o+z2*Math.Power(2,i-1)
EndFor
TextWindow.Write(Text.GetSubText("      ",1,Text.GetLength(Math.Power(2,Math.Ceiling(Math.Log(a)/Math.Log(2))))-Text.GetLength(o))+o+" ")
EndFor
TextWindow.WriteLine("")
EndFor
Sub b
z=0
c=0
While n>0
c=c+1
z[c]=Math.Remainder(n,2)
n=Math.Floor(n/2)
EndWhile
EndSub

Try it at SmallBasic.com Uses Silverlight and thus must be run in IE or Edge
Select the black console, then type input integer and press Enter.

Excel VBA, 95 bytes
Anonymous VBE immediate window function that takes input from range [A1] and outputs to the console.
For y=0To[A1]:For x=0To[A1]:z=x Xor y:?Spc([Len(2^-Int(-Log(A1,2)))]-Len(z))Str(z);:Next:?:Next

APL(NARS), 57 chars, 114 bytes
{∘.{⍺=0:⍵⋄k←⌈/{⌊1+2⍟⍵}¨⍺⍵⋄(2⍴⍨≢m)⊥m←↑≠/{⍵⊤⍨k⍴2}¨⍺⍵}⍨0..⍵}

(NARS2000 0.5.13) test:
  q←{∘.{⍺=0:⍵⋄k←⌈/{⌊1+2⍟⍵}¨⍺⍵⋄(2⍴⍨≢m)⊥m←↑≠/{⍵⊤⍨k⍴2}¨⍺⍵}⍨0..⍵}
  q 5
0 1 2 3 4 5
1 0 3 2 5 4
2 3 0 1 6 7
3 2 1 0 7 6
4 5 6 7 0 1
5 4 7 6 1 0
  q 1
0 1
1 0
  q 9
0 1  2  3  4  5  6  7  8  9
1 0  3  2  5  4  7  6  9  8
2 3  0  1  6  7  4  5 10 11
3 2  1  0  7  6  5  4 11 10
4 5  6  7  0  1  2  3 12 13
5 4  7  6  1  0  3  2 13 12
6 7  4  5  2  3  0  1 14 15
7 6  5  4  3  2  1  0 15 14
8 9 10 11 12 13 14 15  0  1
9 8 11 10 13 12 15 14  1  0

Perl 5 -n, 62 bytes
for$i(0..$_){printf+(" %".(0|log).d)x($_+1).$/,map$_^$i,0..$_}

Try it online!

APL, 20 bytes
 {2⊥¨∘.≠⍨↓⍉2⊥⍣¯1⍳⍵+1}

Explanation:
 ⍳⍵+1

integers from 0 to n
 2⊥⍣¯1

base 2 encoding
 ↓⍉

create nested of boolean vectors
 ∘.≠⍨

xor matrix
 2⊥¨

base 2 to base 10 conversion

⎕←{2⊥¨∘.≠⍨↓⍉2⊥⍣¯1⍳⍵+1}9 in https://tio.run/##SyzI0U2pTMzJT////1Hf1EdtE6qNHnUtPbTiUccMvUedCx71rnjUNvlRbydI9FHv4kPrDR/1bn7Uu1XbsNby/38A not result in the right matrix

https://tio.run/##SyzI0U2pTMzJT////1Hf1EdtE6qNHnUtPbTiUccMvUedCx71rnjUNvlRbydI9FHv4kPrDR/1bn7Uu1XbUBuo3tMfqMOg1vL/fwA
Forgot to say index origin is set to 0. And of course “iota omega +1” gives integers from 0 to n

i try the one with io=0 and work ok, only the first column has a different spaces than the others columns.… but if you say it is ok i reprint my solution....

Jelly, 5 bytes
Ż^þ`G

Try it online!
How it works
Ż^þ`G - Main link. Takes N on the left
Ż     - Range from 0 to N
   `  - Using this range as both arguments:
 ^þ   - Create an XOR table
    G - Format into a padded grid

I think you need a leading Ż to fit the spec.

@UnrelatedString Yep, missed that. Corrected

Vyxal, 14 bytes
ʀ:v꘍vvS:fÞGL↳⁋

Try it Online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Unvisualize Parsons code
Introduction
The Parsons code is just a simple way to describe pitch variations in a piece of music, whether a note is higher or lower than the previous one.
Even if you suck at remembering tunes, you can still pretty much remember if a note goes up or down, thus the Parsons code can help you to identify a music using a search engine.

Description
Each variation is represented by a single character, which is one of the following:

R if the note is the same than the previous one (stands for "Repeat")
U if the note is higher than the previous one (stands for "Up")
D if the note is lower than the previous one (stands for "Down")

The initial note is written as *.

Example
Here is an example of Parsons code (beginning of "Ode to Joy"):
*RUURDDDDRUURDR

You can actually visualize it, like this:
      *-*
     /   \
    *     *
   /       \
*-*         *         *-*
             \       /   \
              *     *     *-*
               \   /
                *-*

We'll call that a contour from now on.
The rules for drawing such countours are considered self-explained by the above example.

Challenge
Now comes the real challenge.
Write a program that, given a contour as input, outputs its corresponding Parsons code.
You are not asked to draw the contour, but the opposite actually.
From the contour, find the original Parsons code.

Rules

The usual rules for code golfing apply
The shortest program in number of bytes wins
The input is a contour, and the output shall be a valid Parsons code
Details about extra whitespace for the input are irrelevant, do whatever works best for you
You are not allowed to hardcode, one way or another, parts of the output and / or the program using extra whitespace because of the previous rule

Notes

This might be useful for testing
The corresponding Parsons code for * is *
An empty string is not a valid contour
A Parsons code always starts with *

Related: http://codegolf.stackexchange.com/q/58759/3808

So it must start with * which doesn't do anything?

What do you mean? when the input is just *? Nope. It should print * I suppose. I'll add this corner case.

I mean, is RUUR invalid? Or it is valid as  *RUUR?

@nicael Yes, it must start with *. Always.

Ok, that's clear.

Are we allowed to have trailing whitespace? If so, how much?

Related: http://codegolf.stackexchange.com/q/55593/42545

Can I output a list?

@Maltysen No, Parsons code.

Pyth - 28 25 27 25 bytes
2 byes saved thanks to @Jakube.
s+\*@L"RDU"-VFtBxR\*%2C.z

Try it online here.

It does not work with * as input. The output is *0 while it should be just *. An evil wild trailing zero appeared.

@HelgevonKoch fixed

You've swapped U and D by the way. Otherwise, well done.

@HelgevonKoch oops

CJam, 21 bytes
qN/:.e>(o2%:i"DRXU"f=

Fold the lines (:) by vectorizing (.) a character-wise maximum operation e>. Since there is only one non-space character in each column, this one will be the result, as space has a smaller ASCII code than all printable non-space characters.
Unshift and print the first asterisk (o, then map every other (2%) remaining char to UDR using modular indexing.
Old solution (29 bytes)
'*qN/z2%'*f#0+2ew);::-"RDU"f=

qN/ gets input lines. z transposes this character matrix. 2% drops every odd row. '*f# finds the index of the asterisk in each row. 0+2ew); gets all successive pairs of indices. ::- computes their differences, and "RDU"f= maps them to letters (via modular indexing: 0 → R, 2 → U, -2 ≡ 1 → D). The leading '* prepends the asterisk.
EDIT: I changed 2ew to 0+2ew); to work around CJam not handling ew (successive slices) on lists that are too short. This makes the code work for the input string *.
Try it here, or watch it in action:

This is really awesome to watch.

I agree! +1 for the code, wish I could +10 for the GIF.

BTW, I like the smiley at code length 17 :-p

I agree, this is awesome to watch. It does not work with * as input though. I get a nice RuntimeException instead.

Ugh, I consider that a CJam bug: [X]2ew should return [] instead of erroring out. I'll add a workaround, though.

Python 3, 129 108 98 86 bytes
There are probably several ways to golf this, but I rather like that I got it all down to one line.
Edit: Now using ''.translate()
Edit: With many thanks to wnnmaw.
Edit: I changed the input format to an array of strings instead of a newline-separated string to save bytes. Also, in the last edit, I mixed up U and R, so I fixed that.
lambda a:'*'+"".join(('UR'[j<'/']+'D')[j>'/']for l in zip(*a)for j in l if j in'-/\\')

Input must be an array of strings. For the example above, this looks something like:
["      *-*                    ","     /   \                   ","    *     *                  ","   /       \                 ","*-*         *         *-*    ","             \       /   \   ","              *     *     *-*","               \   /         ","                *-*          "]

Ungolfed:
def f(a):
    s = ''
    for c in zip(*a):           # transpose
        for d in c:             # for each letter in column c
            if e in "-/\\":     # if that letter is either -,/,\
                if e < '/':     # if < '/' (same as if == '-')
                    s += "R"
                elif e > '/':   # if > '/' (same as if == '\')
                    s += "D"
                else:           # if == '/'
                    s += "U"
        return "*" + s          # in the code we ''.join() it all together
                                # in this ungolfing, we add to an empty string

I don't want to make a new answer because I borrowed a lot from yours, but lambda s:'*'+"".join((('D','R')[j=='-'],'U')[j=='/']for l in zip(*s.split('\n'))for j in l if j in'\\/-') clocks in at 105 bytes.  Main difference is using a tuple conditional instead of translate

Thanks @wnnmaw! I think I can golf that down even further!

Nice golfing on the conditional in the front, that is super clever!

Ah shucks. Thanks for the tip @wnnmaw

Ruby, 87 bytes
Requires trailing spaces in the input so that all lines are the same length.
$><<?*+$<.readlines.map(&:chars).transpose.join.gsub(/./,{?-=>:R,?/=>:U,?\\=>:D}).strip

Surely this is malicious code, as it contains >:D.

Japt, 38 bytes 40 41 45 46 48
Saved 2 bytes thanks to @ETHproductions
'*+U·y £Yu ?"RUD"g1+(XrS c -47 g):P} q

If there was a trim command this would be only 38 bytes ;-; will add explanation when I'm done golfing. The :P is not the program trying to be funny, it's actually the program ignoring characters that aren't important.
Try it online

When I saw that there was a challenge practically requiring an array transpose, and that Doᴡɴɢᴏᴀᴛ had answered it, I knew it had to be Japt.

BTW, I'll add in a trim function at x and transpose and rotate functions at y and z (split at newlines, use the array function, join with newlines)

You could save two bytes like this: Yu ?"RUD"g1+(XrS c -47 g):P

@ETHproductions thanks, down to under 40 bytes!

Haskell, 89 bytes
import Data.List
m '/'="U"
m '-'="R"
m '\\'="D"
m _=""
('*':).(>>=(>>=m)).transpose.lines

Usage example:
*Main> ('*':).(>>=(>>=m)).transpose.lines $ "      *-*                    \n     /   \\                   \n    *     *                  \n   /       \\                 \n*-*         *         *-*    \n             \\       /   \\   \n              *     *     *-*\n               \\   /         \n                *-*          "
"*RUURDDDDRUURDR"

*Main> ('*':).(>>=(>>=m)).transpose.lines $ "*"
"*"

Transpose the input and replace the characters //-/\ with singleton strings "U"/"R"/"D". All other chars are replaced by empty strings "", which later disappear by concatenating everything. Finally, prepend the asterisk *.

Mathematica, 103 bytes
"*"<>(Differences@Position[Thread@Characters@StringSplit[#,"
"],"*"][[;;,2]]/.{-2->"U",0->"R",2->"D"})&

Quite short, considering that this is a string-processing challenge.

JavaScript (ES6) 90
An anonymous function. It scans the input string char by char, taking into accout the position in the current line. Doing this, it builds an output array subsituting U D R for / \ - at the right place
c=>[...c].map(c=>c>'*'?t[i++]=c>'/'?'D':c<'/'?'R':'U':c<' '?i=0:++i,t=['*'],i=0)&&t.join``

Matlab, 62 bytes
r=@(s)[85-(s<14)*3-(s>59)*17,''];@(p)r(sum(p(:,2:2:end)-32))

This requires the input to be a rectangular (same number of characters in each row). E.g.
    ['      *-*                    ';    '     /   \                   ';    '    *     *                  ';    '   /       \                 ';    '*-*         *         *-*    ';    '             \       /   \   ';    '              *     *     *-*';    '               \   /         ';    '                *-*          '];

Explanation
sum(p(:,2:2:end)-32)        % exctract every second column, substract 32 (spaces->zeros)
                            % and sum column wise (results in a vector of 3 different values)
[85-(s<14)*3-(s>59)*17,'']  % map each of the values to the corresponding value of the letter and convert back to characters

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Make a Unicorn interpreter
Recently, I made a made a typo and I wrote unicorn instead of unicode, I did what any normal person would do and I made an esolang out of it. In this challenge you will be writing a Unicorn interpreter.
Because Unicorn programs are horrible long, you'll have to write a short interpreter to compensate for this.
Example
These are the transpiled result, not the actual interpreted result your program should output

1

alert([x=(p=prompt())/2+Math.sqrt(p*p/4-prompt()),p-x])

"Hello, World!"

Specification

Unicorn is divided into "sections" which are space-separated
Each section represents a character
The number of unicorns () in each section is converted to it's associated character (i.e. 32 unicorns -> chr(32) -> ).
If the section contains goats (), the length of the amount of goats should be doubled, then converted to the associated character
If the section contains any other characters, the program should ignore the character.
Each section (character) should be joined to form a program
This resulting program should be evaluated in the language you have written the program in. (e.g. JavaScript's eval, Python's exec)
Unicorns are unicode U+1F984; goats are unicode U+1F410.
If you choose a compiled language, you may output/save the compiled, compiled unicorn code

 (unicorns) and  (goats) all count as one byte for this challenge.
If your language doesn't support emojis, you may identify unicorns as (u) and goats as (g). You may not support emojis and u,g

If you really want to see the unicodes unicorns, here is a picture of this post

+50 bounty: to the shortest program in (the original) Unicorn while being under 6500 chars. You must use this version, it must run on Firefox, Chrome, or Safari.

I didn't know unicorns were that shape.

@Doorknob冰 This is the era of rectangular unicorns!

@Doorknob冰 ssshhh, don't hurt the unicorn's feelings (I'll update the post)

Do you know if your bonus is possible? Meaning, have you tried to do your own bonus?

@TanMath I'm very sure it's possible. I've tried and with minimal golfing I've come close

Can you tell us the code points of those characters?

@SuperJedi224 "Unicorns are unicode U+1F984; goats are unicode U+1F410." The code points depending on which encoding and number of bytes will differ. You can use this site for the bytes across different encodings

@Doᴡɴɢᴏᴀᴛ is it absolutely necessary for me to have the unicode character show up? It does not render for me...

@Maltysen no, you'll need to execute it as a Pyth program

For those who can't see the unicorn and goat on this page, unicorn and goat.

Does evaluation of the resulting program have to be independent of the unicorn interpreter environment? E.g. in C the resulting program a) needs to provide a main function and b) gets it's own fresh global scope.

@nimi hmm, didn't consider that, if you write it in a compiled language, I guess you could output/save the compiled unicorn program. If you write it in an interpreted language, it doesn't need it's own environment but it's fine if it does

@insertusernamehere that depends on your language, if your language can handle Unicode characters within the code then sections may be as long as unicode supports. If your language supports ASCII only characters within the code, sections will never be longer than 127 unicorns.

@nimi the character

Could you include a few test cases? I get a6er:[<=8=8rom8:))/2+Ma:4.sqr:8*8/-8rom8:))8-<]) for your diamond code.

@Dennis sure give me a minute (or 5) to write some up

@Maltysen I mean the transpiled code, not the end result.

I can see the goats, but not the unicorns.  Are they hiding, or are the goats not letting me see the unicorns?

@RikerW The goats must of scared the unicorns away :( I'll add a picture of the post

Thanks.  If I didn't believe in unicorns I would wonder why my browser shows goats but not unicorns.

On my computer, this language should be called "Funny Unicode Boxes".

Oh, wait, people already made jokes to that effect, never mind.

nice unicorns B)

I'm pretty sure 6500 chars is impossible unless you go for the ug approach which still will take a lot

"This resulting program should be evaluated in the language you have written the program in." So no self-hosting Unicorn interpreter, then? It'd be Unicorn all the way down...

In fact they are invisible pink unicorns.

You did ask for the length of the amount of goats, doubled, correct?

No compiled languages? Sad. :(

Can we include rainbows and sparkles in the unicorn code?

Does each section contain only goats or only unicorns? If not, if we have section uugg that's \x06, right?

I did what any normal person would do and I made an esolang out of it.  I love it haha

Can we use the latest version of Unicorn with the rainbows and more for the bounty?

@TanMath no you must use the specified version

Can we use Unicorn => Pyth?

@BlockCoder1392 for the bonus? No, you must use JavaScript Unicorn

I thought so. I was just making sure

https://www.youtube.com/watch?v=T3U9hFaPl5w

Pyth - 23 17 bytes
.vsmC+/d\y/d\cz

Try it online.
It works by splitting the input by spaces, then for each section counting the number of unicorns and number of goats * 2 then adding them, then taking the char at the code point. It finished by summing the char array and pyth-evaling.

Unicorn (ES6), 5934 5278 bytes
Under the custom encoding, this is 5278 bytes (1 byte per char); but with UTF-8, it would 4 bytes per char (though only 1 for a space), or 20869 total.
(too many Unicorns and Goats to reasonably display here)

Instead, here's a pastebin. This Unicorn code transpiles to this JS snippet:
s=>eval(s.replace(/\S+ ?/g,c=>String.fromCharCode(c.length>>1<<c.charCodeAt()%2)))

Now, this isn't the shortest possible version; this is shorter:
s=>eval(s.replace(/\S+ ?/g,c=>String.fromCharCode(c.length>>1<<("">c))))

However, the one unicorn in there would transpile to 56034 goats, thus multiplying the score by roughly 11.
Here's the function I used to transpile to Unicorn:

function g(s){return s.replace(/./g,function(c){i=c.charCodeAt();return(i%2?"".repeat(i):"".repeat(i/2))+" "}).slice(0,-1)}
<textarea id=O cols=100></textarea><button id=P onclick="Q.value=g(O.value);R.innerHTML=(Q.value.length+Q.value.split(' ').length-1)/2">Run</button>
<textarea id=Q rows=10 cols=100>Output appears here.</textarea>

Length: 0

Note: I haven't actually tested the program, as there isn't an online interpreter that I could find (although I suppose I could hook up the .js file to HTML...?)

How is it that this answer with over 5KB is voted higher than the answer with 17 bytes?

@OldBunny2800 Because unicorns.

Python 179 176 bytes
EDIT: I just learnt s.split(' ')=s.split()
Here is the second "actual" programming language Unicorn interpreter. I call this version of Unicorn "UnicornPy" pronounced as "unicorn pie". I am making this much too official!
s=raw_input()
s=s.replace('','')
s=s.replace('','u')
for i in s:
    if i not in "ug ":
        s=s.replace(i,'')
s=s.split()
for i in s:
    s[s.index(i)]=chr(len(i))
exec(''.join(s))

For some reason, it needs me to convert the unicorn and goat emojis to u and g. I do not know why.
Try it here!

Dennis' website is called "Try it online!" and the phrase isn't copyrighted...

@AlexA. it was a joke!

Javascript uses UTF-16 (I think), so the unicorn and goat are actually 2 characters each.

@12Me21 no one in the history of PPCG has counted javascript as UTF-16.

I meant that strings in JS are stored as UTF-16

Don't you mean s.split(" ") === s.split()? :)

Ruby, 78 Bytes
eval ARGV[0].gsub(/[^ug ]/,'').split.map{|b|(b.size*(b[0]=='u'?1:2)).chr}.join

It basically reads the first command line argument, splits it at every space character, maps the size of the block to the appropriate character and joins it all together.
Edit: Forgot the requirement that all other characters should be ignored

Now it does... thank you for mentioning!

Unicorn ES6 (Invalid), 3379 bytes
This is invalid because it uses the latest version of Unicorn with rainbows, sun with clouds, and sparkles. Thanks to @ETHproductions for the JS code to interpret unicorn.
code is in the paste bin below

Pastebin: http://pastebin.com/raw/Q9Kd4ixA

This is only 3379 bytes if sparkles, sun/clouds, and rainbows also are 1 byte.

PHP, 83 80 86 87 bytes
Now Unicorn-ready
For the cost of 3 bytes I made this unicorn ready:
$a=mb_substr_count;foreach(explode(" ",$argv[1])as$b)echo chr($a($b,)+2*$a($b,));

Takes an input from command line, like:
$ unciorns.php " "

This will output 32.
Demo
Try before buy

Unfortunately OS X 10.10.5 doesn't support is hiding Unicorns. Here's the alternative ug-approach (80 bytes):
$s=substr_count;foreach(explode(' ',$argv[1])as$c)echo chr($s($c,u)+2*$s($c,g));

Takes an argument from command line, like:
$ php unicorns.php "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuug uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"

Try the ug-version

Edits

Saved 1 byte due to massive refactoring. This version is already discarded again, since I managed to golf the original even further:

Demo discarded version (86 bytes)
for($_=$argv[1].' ';$c=$_[$i++];)$t+=u==$c?1:(g==$c?2:(' '==$c?-$t+!print chr($t):0));

Saved 6 bytes by replacing for with foreach
Added 3 bytes making it Unicorn-ready.

Mathematica, 118 bytes
a=StringCount;ToExpression@FromCharacterCode[If[#~StringTake~1=="u",#~a~"u",2IntegerLength[#~a~"g"]]&/@StringSplit@#]&

Performs exactly as described in the specification. I couldn't use emoji in Mathematica string literals without the interpreter exploding, so I used u and g.

Rust, 426 bytes
use std::io::Write;macro_rules!c{($n:expr,$a:expr)=>(println!("{}",std::str::from_utf8(&std::process::Command::new($n).arg($a).output().unwrap().stdout).unwrap());)}fn main(){let d:String=std::env::args().skip(1).next().unwrap().split(' ').map(|s|s.chars().fold(0u8,|a,c|a+match c as char{''=>1,''=>2,_=>0}) as char).collect();std::fs::File::create("o").unwrap().write_all(d.as_bytes()).unwrap();c!("rustc","o");c!("o","");}

This probably can be golfed the hell down, but type safety and checked errors are quite verbose.
Since Rust is a compiled language, this program outputs the decoded program to a file and invokes the compiler on said file, then executes the resulting binary.
Ungolfed:
use std::io::Write;

macro_rules! command {
    ($name:expr,$argument:expr) => (println!("{}", std::str::from_utf8(
        std::process::Command::new($name)
                              .arg($argument)
                              .output()
                              .unwrap()
    ));)
}

fn main() {
    let decoded: String = std::env::args()
        .skip(1) //ignore program name
        .next().unwrap().split(' ') //get first arg split on spaces
        //transform every section in a char
        .map(|section| section.chars()
            .fold(0u8, |accumulator, chr| accumulator + match chr as char {
            '' => 1,
            '' => 2,
            _ => 0
        }) as char)
        //convert iterator to string
        .collect();

    std::fs::File::create("o").unwrap()
        .write_all(decoded.as_bytes()).unwrap();
    command!("rustc", "o");
    command!("o", "");
}

Actually, the emoji are 4 bytes each in UTF-8.

@LegionMammal978 I mistakenly used char-count instead of byte count :P

The entire program is 394 bytes.

@LegionMammal978 It just increased even more. What tool do you use to count bytes?

I use this.

Actually, for this challenge the emjoi count as one byte so the char count is thr same as the byte count.

Python 3, 94 86 bytes
This is a simple parser that works even if you mix u and g in one section.
s=input().split();exec(''.join(chr(sum([[0,2][j<"u"],1][j>"g"]for j in i))for i in s))

As an example (using u and g in separate sections):
gggggggggggggggggggggggggggggggggggggggggggggggggggggggg ggggggggggggggggggggggggggggggggggggggggggggggggggggggggg uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu ggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggg uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

should parse to
print(1)

Ruby, 75 characters
A nifty ruby interpreter that replaces all  with ' ' (a space) and all  with '  ' (two spaces), and gets the length of each segment.
I call this version of Unicorn RubyUnicorn Rubycorn.
->s{eval s.split(a=' ').map{|r|r.gsub('',a).gsub('',a*2).size.chr}.join}

Rubycorn, possibly?

@Kroltan that is a cooler name.

RProgN, 25 bytes
~`''R'(+)%s*'{Lc}R do

Explained
~                             # Zero Space Segment
 `                         # The String literal ""
   ''                   # The String literal ""
       R                     # Replace, turning all goats into twonicorns
        '(+)%s*'          # The pattern string "(+)%s*", which is "A fewnicorns, then as much whitespace as possible, or none.
                 {Lc}R      # Replace with the result of the function, which converts the captured subgroup to it's Length, then to a char.
                       do   # Straight up do it.

Once again, RProgN falls into the trap of being consistently okay.
Try it online!

Racket, 200 bytes
(define(f s)(eval(read(open-input-string(list->string(map integer->char(map(λ(x)(foldl(λ(y a)(case y[(#\u)(add1 a)][(#\g)(+ a 2)]))0 x))(map string->list(string-split s)))))))(make-base-namespace)))

Ungolfed:
(define(f s)
  (eval(read(open-input-string
             (list->string ;;back to string
              (map integer->char ;;back to char
                   (map(λ(x)
                         (foldl(λ(y a)
                                 (case y
                                   [(#\u)(add1 a)]
                                   [(#\g)(+ a 2)]))
                               0 x))
                       (map string->list (string-split s))))))) ;;splitting by space, converting to list of chars
       (make-base-namespace)))

It starts by splitting the string into list of strings by spaces, then creates a list of chars per splitted string. Then each list of chars is reduced into a number by adding 1 if unicorn, 2 if goat. Finally, each list containing the sum is made a list of chars, then a string which is passed to eval.
Try it online!

Welcome to the site! One of the mods on the site has made a website to run programs online (the Racket page: https://tio.run/nexus/racket). You can paste your code in there (maybe adding to header or footer if Racket needs anything extra to make a complete program out of a function) and then get a link that you can add to this answer. This is not necessary but it is nice for people who want to test your code.

@1000000000 I have just added it, thanks for the tip!

JavaScript, 140 154 141 bytes
var s='';i.split(" ").forEach((e)=>{s+=String.fromCharCode((e.split("").length-1)+2*(e.split("").length-1));});console.log(eval(s));

It splits the input string in an array of strings, using space as a needle. It then proceeds to count the amount of unicorns and goats*2 and concatenate the summed result to what will be evaluated.
More readable:
var s = '';
i.split(" ").forEach((e) => {
    s+=String.fromCharCode((e.split("").length-1)+2*(e.split("").length-1));
});
console.log(eval(s));

Edit:
Updated code to accept an argument from CLI, use:
node unicorn.js " "
var s='';process.argv[2].split(' ').forEach((e)=>{s+=String.fromCharCode((e.split('').length-1)+2*(e.split('').length-1));});console.log(eval(s));

Ungolfed:
var s = '';
process.argv[2].split(' ').forEach((e) => {
    s+=String.fromCharCode((e.split('').length-1)+2*(e.split('').length-1));
});
console.log(eval(s));

Edit 2:
Edited to accept input as a function parameter, use node unicorn.js
i=>{var s='';i.split(' ').forEach((e)=>{s+=String.fromCharCode((e.split('').length-1)+2*(e.split('').length-1));});return eval(s);};

Ungolfed:
i =>{
    var s = '';
    i.split(' ').forEach((e) => {
        s+=String.fromCharCode((e.split('').length-1)+2*(e.split('').length-1));
    });
    return eval(s);
};

Try it online!

Welcome to Programming Puzzles & Code Golf! We require all answers to be either full programs (e.g. taking input through prompt()) or functions (taking input through a function parameter: i=>{var s='';...}).

Edited my answer to accept the input as an argument

Perl 6, 67 bytes
{use MONKEY-SEE-NO-EVAL;EVAL [~] .words».&{chr m:g/\/+2*m:g/\/}}

SmileBASIC, 125 bytes
INPUT S$WHILE LEN(S$)R=ASC(POP(S$))IF R-32THEN C=C+!(R-117)+2*!(R-103)ELSE O$=CHR$(C)+O$C=0
WEND
SAVE"TXT:@",CHR$(C)+O$EXEC"@

Using PRGEDIT to execute the code without saving would have been a lot nicer, but also a lot longer.
code:
INPUT CODE$ 'making the user type 1000s of characters just so I could save 2 or 3
WHILE LEN(CODE$)
 CHAR$=POP(CODE$) 'I convert the code backwards, since POP( is shorter than SHIFT(
 IF CHAR$==" " THEN
  UNSHIFT OUT$,CHR$(CHAR)
  CHAR=0
 ELSE
  INC CHAR,(CHAR$=="u")+(CHAR$=="g")*2
 ELSE
WEND
SAVE "TXT:@",CHR$(CHAR)+OUT$
EXEC "TXT:@"

Stax, 14 bytes
ü┴(gÇ%╩[↑÷>7♫░

Run and debug it


text:
What's a half on the clock?
In my room, I have this geeky clock (click for full size):

Most of these are not difficult to figure out, but the one for 4-o-clock is particularly tricky:

Normally, a fraction like 1/2 doesn't make sense in modular arithmetic since only integers are involved. The correct way, then, is to see this as the inverse of 2, or to put it another way,  is that number  where . Put this way, a moment's thought will reveal that  because .
However, simply finding the multiplicative inverse would be far too easy as a challenge. So let's bump up the difficulty to exponentiation, or in other words, finding the modular logarithm or discrete logarithm of 2. In this case, 3 is the modular logarithm of 2 with respect to 7. For those of you with number theory/abstract algebra background, this means calculating the multiplicative order of 2 modulo n.
The Challenge
Given a positive odd integer n greater than 1, output the smallest positive integer x where .
Examples
n x
3 2
5 4
7 3
9 6
11 10
13 12
15 4
17 8
19 18
21 6
23 11
25 20
27 18
29 28
31 5
33 10
35 12
37 36
39 12
41 20
43 14
45 12
47 23
49 21
51 8
53 52
55 20
57 18
59 58
61 60
63 6
65 12
67 66
69 22
71 35
73 9
75 20
77 30
79 39
81 54
83 82
85 8
87 28
89 11
91 12
93 10
95 36
97 48
99 30
101 100
103 51
105 12
107 106
109 36
111 36
113 28
115 44
117 12
119 24
121 110
123 20
125 100
127 7
129 14
131 130
133 18
135 36
137 68
139 138
141 46
143 60
145 28
147 42
149 148
151 15
153 24
155 20
157 52
159 52
161 33
163 162
165 20
167 83
169 156
171 18
173 172
175 60
177 58
179 178
181 180
183 60
185 36
187 40
189 18
191 95
193 96
195 12
197 196
199 99
201 66

Follow-up challenge: calculate that dot chart value thingy

@CᴏɴᴏʀO'Bʀɪᴇɴ: That's just binary.

Graphical input!

https://oeis.org/A002326

Regarding the clock, most of these make sense to me, but not 1, 4, or 5. Your explanation for 4 just confirms what I suspect: it's really a one-way hash function: if you know the value, you can confirm it with the formula.  The explanation (assuming it is the correct one) yields multiple possible values for x. Is it 4 o'clock or 11 o'clock?

@Otheus: 1 is apparently supposed to be Legendre's constant, but in a strange notation, and 5 is due to phi. Regarding the multiple possible values for x, 11 is equivalent to 4 modulo 7, so they're really the same.

We all know (1/2)%7=1/2.

@SuperJedi224 Who said that that 2^-1 == 1/2?

@Dennis Properties of exponents. Unless that's bitwise XOR, of course.

x^-1 means multiplicative inverse of x, i.e., the number y such that xy = 1. In the field of real numbers, 2^-1 = 0.5. In the ring of integers modulo 7, 2^-1 = 4.

Modular arithmetic is weird.

@SuperJedi224 Modular arithmetic is weird, and yet you probably do it at least once a day without realizing it. If you use 12 hour time, and someone asks you to call them in two hours, and it's 11:00 and you decide to call them at 1:00, you just did modular arithmetic. I find it neat that one of the numbers on this clock is expressed in a way that is sometimes called "clock arithmetic".

"Regarding the multiple possible values for x, 11 is equivalent to 4 modulo 7, so they're really the same". Ugh, so it's a 5 hour clock. :P

Jelly, 6 bytes
R2*%i1

Try it online!
How it works
R2*%i1  Input: n

R       Range; yield [1, ..., n].
 2*     Compute [2**1, ..., 2**n].
   %    Hook; take all powers modulo n.
    i1  Get the index of the first 1.
        Indices are 1-based, so index k corresponds to the natural number k.

Pyth - 9 8 bytes
f!t.^2TQ

Test Suite.
filters from default of 1 till it finds some x such that modular exponentiation with 2 and the input equals 1.

Python, 32 bytes
f=lambda n,t=2:t<2or-~f(n,2*t%n)

Starting with 2, doubles modulo n until the result is 1, recursively incrementing each time, and ending with a count of 1 for the initial value of 2.

Mathematica, 24 bytes
2~MultiplicativeOrder~#&

I just used a built-in for this.

Of course Mathematica has a built-in for this. :P

@El'endiaStarman Of course Mathematica has an ungolfable built-in for this. :-{D

APL, 8 bytes
1⍳⍨⊢|2*⍳

This is a monadic function train that accepts an integer on the right and returns an integer. To call it, assign it to a variable.
Explanation (calling the input x):
      2*⍳    ⍝ Compute 2^i for each i from 1 to x
   ⊢|        ⍝ Get each element of the resulting array modulo x
1⍳⍨          ⍝ Find the index of the first 1 in this array

Note that the result may be incorrect for large inputs since the exponential gets rounded.

Also 8: ⍴∘∪⊢|2*⍳.

Pyth, 14 bytes
VQIq%^2hNQ1hNB

Explanation:
VQIq%^2hNQ1hNB

                # Implicit, Q = input
VQ              # For N in range(0, Q)
  Iq      1     # If equals 1
    %^2hNQ      # 2^(N + 1) % Q
           hN   # Print (N + 1)
             B  # Break

Try it here

I get 66\n132\n198 for an input of 201.

@El'endiaStarman sorry, wrong link :p

Oh, haha, it's good now. :)

JavaScript (ES6), 28 bytes
f=(n,t=2)=>t<2||-~f(n,2*t%n)

Based on @xnor's brilliant recursive approach.

Do you have a link I can test this at? Doesn't seem to work in the console on Chrome. (SyntaxError due to =>, I think.)

@El'endiaStarman Here ya go..

@CᴏɴᴏʀO'Bʀɪᴇɴ: I can't figure out how to test it.

@El'endiaStarman This code defined a function which can be called like f(3). For some stupid reason, that website won't let you use this function unless you declare it with let or var. Try this.

Oh, okay. Thanks! Looks good.

Additionally, it would be nice to see a full test suite passed at a glance, e.g.: https://jsbin.com/jebetevume/1/edit?js,console

@Pavlo I know lambdas are accepted, but this function needs to be named so it can call itself. I'll add a test suite link when I get back to my computer.

05AB1E, 11 bytes
Code:
DUG2NmX%iNq

Explanation:
DUG2NmX%iNq

D            # Duplicates the stack, or input when empty
 U           # Assign X to last item of the stack
  G          # For N in range(1, input)
   2Nm       # Calculates 2 ** N
      X      # Pushes X
       %     # Calculates the modulo of the last two items in the stack
        i    # If equals 1 or true, do { Nq }
         N   # Pushes N on top of the stack
          q  # Terminates the program
             # Implicit, nothing has printed, so we print the last item in the stack

10 bytes

Julia, 25 24 bytes
n->endof(1∪2.^(1:n)%n)

This is simple - 2.^(1:n)%n finds the powers of 2 within the set, ∪ is union, but serves as unique and returns only one of each unique power (and because it's an infix operator, I can union with 1 to save a byte over the ∪(2.^(1:n)%n) approach). Then endof counts the number of unique powers, because once it hits 1, it'll just repeat the existing powers, so there'll be as many unique values as the power that produces 1.

Seriously, 14 bytes
1,;╗R`╙╜@%`Míu

Hex Dump:
312c3bbb5260d3bd4025604da175

Try It Online
Explanation:
 ,;╗           Make 2 copies of input, put 1 in reg0
    R          push [0,1,...,n-1]
     `    `M   map the quoted function over the range
      ╙        do 2^n
       ╜@%     modulo the value in reg0
1           íu Find the 1-index of 1 in the list.

Haskell, 30 bytes
n%1=1
n%t=1+n%(2*t`mod`n)
(%2)

Helper argument t is doubled modulo n each step until it equals 1.

How might I test this?

See here

Japt, 17 bytes
1oU f@2pX %U¥1} g

Try it online!
This would be three bytes shorter if Japt had a "find the first item that matches this condition" function. Starts work on one
How it works
1oU f@2pX %U¥1} g   // Implicit: U = input number
1oU                 // Generate a range of numbers from 1 to U.
                    // "Uo" is one byte shorter, but the result would always be 0.
    f@        }     // Filter: keep only the items X that satisfy this condition:
      2pX %U¥1      //  2 to the power of X, mod U, is equal to 1.
                g   // Get the first item in the resulting list.
                    // Implicit: output last expression

Julia, 33 26 bytes
n->findfirst(2.^(1:n)%n,1)

This is a lambda function that accepts an integer and returns an integer. To call it, assign it to a variable.
We construct an array as 2 raised to each integer power from 1 to n, then we find the index of the first 1 in this array.
Saved 7 bytes thanks to Glen O!

No need for the map command, just use 2.^(1:n)%n.

@GlenO That works perfectly, thanks!

CJam, 15 bytes
2qi,:)f#_,f%1#)

Peter Taylor saved a byte. Neat!

Rather than 1fe| you could :) and then ) after doing the #.

2qi,:)f#_,f%1#)

Ohh, of course. Thank you.

PARI/GP, 20 bytes
n->znorder(Mod(2,n))

Perl 5, 29 bytes
$n=<>;{2**++$_%$n-1?redo:say}

Hat tip.

MATL, 13 bytes
it:Hw^w\1=f1)

Runs on Octave with the current GitHub commit of the compiler.
Works for input up to 51 (due to limitations of the double data type).
Example
>> matl it:Hw^w\1=f1)
> 17
8

Explanation
i             % input, "N"
t:            % vector from 1 to N
Hw^           % 2 raised to that vector, element-wise
w\            % modulo N
1=            % true if it equals 1, element-wise
f1)           % index of first "true" value

Unicorn, 1307 1062 976 bytes
( ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨  (     2 )    ✨✨✨✨✨✨✨✨✨✨ 2    ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ (   2 ✨✨✨✨✨✨✨    ) ) (  ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨     ( ) )

I'm attempting to make unicorn a serious golfing language but that's a bit difficult...
Hopefully I'll find a way to retain the "unicorn-ness" of the language while making much less bytes

Picture:

Uses a custom encoding.
This answer is non-competing because it uses a version of Unicorn made after this language

The rainbows and unicorns are strong with this one...

Somebody come up with UnicornRLE

Am I the only one getting ((2)2(2))(()) out of the code with @Downgoat's interpreter?

, 11 chars / 22 bytes
↻2ⁿḁ%ï>1)⧺ḁ

Try it here (Firefox only).
Uses a while loop. This is one of the few times a while loop is better than mapping over a range.
Explanation
          // implicit: ï = input, ḁ = 1
↻2ⁿḁ%ï>1) // while 2 to the power of ḁ mod input is greater than 1
  ⧺ḁ      // increment ḁ
          // implicit output

Prolog, 55 bytes
Code:
N*X:-powm(2,X,N)=:=1,write(X);Z is X+1,N*Z.
p(N):-N*1.

Explained:
N*X:-powm(2,X,N)=:=1, % IF 2^X mod N == 1
     write(X)         % Print X
     ;Z is X+1,       % ELSE increase exponent X
     N*Z.             % Recurse
p(N):-N*1.            % Start testing with 2^1

Example:
p(195).
12

Try it online here

Japt -æ, 9 bytes
©2pU %N¶1

Try it

Python 3, 37 bytes
f=lambda n,x=1:2**x%n==1or 1+f(n,x+1)

Try it online!
Thanks Maria Miller for saving me 1 byte.

37 bytes

C (gcc), 35 bytes
i;f(n){for(i=1;(1<<i++)%n-1;);--i;}

Gives accurate results up to \$x=31\$, otherwise the result is 32.
Try it online!


text:
Electrostatic potential of a simple system
In physics, like electric charges repel, and unlike charges attract.
The potential energy between two unit charges separated by a distance d is 1/d for like charges and -1/d for unlike charges. The potential energy of a system of charges is the sum of the potential energies between all pairs of charges.
Challenge
Determine the potential energy of a system of unit charges represented by a string.
This is code-golf, so the shortest solution in bytes wins.

Input
A nonempty multiline string, consisting of only +, -,   and newlines, with each line a constant width. The + and - represent charges of +1 and -1 respectively. For example, the following string:
    + -
 +

(considering the top-left to be the origin) represents a system with positive charges at (4,0) and (1,-1) and a negative charge at (6,0).
Alternatively, you may take input as a list of lines.
Output
A signed real number representing the potential energy of the system of charges. Output should be correct to four significant figures or 10-4, whichever is looser.
Test cases:
   -

Should output 0. There are no pairs of charges to repel or attract, and the whitespace doesn't change anything.
+
  -

There are only two charges; they are 1 unit away in the vertical direction and 2 units away in the horizontal direction, so their distance is sqrt(5). Output should be -1/sqrt(5)=-0.447213595.
+       -
-       +

Should give -2.001930531.
 - -- -+ - - -+-++-+
 +-- + +-- + ++-++ -
---++-+-+- -+- - +-
-- - -++-+  --+  +
-   + --+ ++-+  +-
--  ++- + +  -+--+
+ +++-+--+ +--+++ +
-+- +-+-+-+  -+ +--+
- +-+- +      ---+
-     - ++ -+- --+--

Should give -22.030557890.
---+--- ++-+++- -+ +
-+ ---+++-+- +- +  +
---+-+ - ----  +-- -
 -   + +--+ -++- - -
--+ - --- - -+---+ -
+---+----++ -   +  +
-+ - ++-- ++-  -+++
 +----+-   ++-+-+  -
++- -+ -+---+  -- -+
+-+++ ++-+-+ -+- +-

Should give 26.231088767.

Plus points for implementing periodic boundary conditions and computing the Madelung energy.

@AndrasDeak That would be interesting.

Pyth, 34 bytes
smc*FhMd.atMd.cs.e+RkCUBxL" +"b.z2

Demonstration
First, we convert each character to +1 for +, -1 for -, and 0 for . Then, each number is annotated with its position in the matrix. At this point, we have a matrix that looks like:
[[[-1, 0, 0], [-1, 1, 0], [-1, 2, 0], [1, 3, 0], [-1, 4, 0], [-1, 5, 0], [-1, 6, 0]],
 [[1, 0, 1], [1, 1, 1], [-1, 2, 1], [-1, 3, 1], [0, 4, 1], [1, 5, 1], [0, 6, 1]]]

The code that reaches this point is .e+RkCUBxL" +"b.z
Then, we flatten this matrix into a list and take all possible pairs, with .cs ... 2.
Then, he find the distance between the pair with .atMd, and the sign of the potential with *FhMd, divide, and sum.

CJam, 51 chars
Counting all pairs, filtering Inf/NaN out and dividing by two:
q_N#:L;N-" +"f#ee2m*{z~:*\Lfmd2/:.-:mh/}%{zL<},:+2/

Alternatively, filtering coordinates first so we count each pair once and don't run into Inf/NaN:
q_N#:L;N-" +"f#ee2m*{0f=:<},{z~:*\Lfmd2/:.-:mh/}%:+

Explanation (old)
q                        Get all input.
 _N#:L;                  Store the line width in L.
       N-                Flatten it into one long line.
         :i              Get all ASCII values.
           :(3f%:(       Map space to 0, + to 1, - to -1.
                  ee     Enumerate: list of [index, sign] pairs.
                    2m*  Get all possible pairs.

{                        }%     For each pair:
 e_~                              i1 s1 i2 s2
    @*                            i1 i2 s        (multiply signs)
      \aa@aa+                     s [[i2] [i1]]  (put indices in nested list)
             Lffmd                s [[x2 y2] [x1 y1]]  (divmod by L)
                  :.-             s [xD yD]      (point diff)
                     :mh          s d            (Euclidean dist.)
                        /         s/d            (divide)

{zL<},                   Filter out infinite results.
      :+2/               Sum all charges, and divide by two.
                           (We counted each pair twice.)

So explanation is TBA? :P

Did you write this while it was sandboxed, or are you just really fast?

I'm quite fast :) The first version was "the simplest thing that worked", which took me only a couple of minutes to write, so I immediately posted that, then golfed it down over the next half hour.

Haskell, 149 144 bytes
z=zip[0..]
g n|f<-[(x,y,c)|(y,r)<-z$lines n,(x,c)<-z r,c>' ']=sum[c%d/sqrt((x-i)^2+(y-j)^2)|a@(x,y,c)<-f,b@(i,j,d)<-f,a/=b]/2
c%d|c==d=1|1<2= -1

Usage example:
*Main> g " - -- -+ - - -+-++-+\n +-- + +-- + ++-++ -\n---++-+-+- -+- - +- \n-- - -++-+  --+  +  \n-   + --+ ++-+  +-  \n--  ++- + +  -+--+  \n+ +++-+--+ +--+++ + \n-+- +-+-+-+  -+ +--+\n- +-+- +      ---+  \n-     - ++ -+- --+--"
-22.030557889699853

f is a list of all triples (x-coord, y-coord, unit charge). g calculates the potential energy for all combinations of two such triples which are not equal, sums them and divides the result by 2.

Lua, 293 255 246 228 Bytes
e=0l={}p={}i=1while l[i-1]~=""do l[i]=io.read()for k=1,#l[i]do c=l[i]:sub(k,k)if(c>" ")then for h,v in ipairs(p)do e=e+(v.s==c and 1 or-1)/math.sqrt((v.y-i)^2+(v.x-k)^2)end table.insert(p,{s=c,x=k,y=i})end end i=i+1 end print(e)

Ouch, 228 bytes...I can probably golf this significantly, but I'll post it here for now. Probably update it later tonight with a few more musings and (hopefully) some improvements to the length.
Ungolfed
e=0l={}p={}i=1
while l[i-1]~=""do
    l[i]=io.read()
    for k=1,#l[i]do
        c=l[i]:sub(k,k)
        if(c>" ")then
            for h,v in ipairs(p) do
                e=e+(v.s==c and 1 or-1)/math.sqrt((v.y-i)^2+(v.x-k)^2)
            end
            table.insert(p,{s=c,x=k,y=i})
        end
    end
    i=i+1
end

print(e)

Update 255 Bytes: Removed old bottom two for loops, processing is now done as strings are added to string array.
Update 246 Bytes: Replaced c=="+"or"-"==c with c>" " as per nimi's suggestion. Great idea, thanks!
Update 228 Bytes: If statement could be removed completely by inserting in table after the for loop, saving quite a few bytes.

MATL, 39 42 bytes
`jt]N$v'- +'FT#m2-I#fbbhtZPwt!**1w/XRss

Works in current release (5.1.0). The compiler runs on Matlab or Octave.
Each line is a separate input. End is signalled by inputting an empty line.
Examples
>> matl
 > `jt]N$v'- +'FT#m2-I#fbbhtZPwt!**1w/XRss
 >
> +       -
> -       +
>
-2.001930530821583

>> matl
 > `jt]N$v'- +'FT#m2-I#fbbhtZPwt!**1w/XRss
 >
>  - -- -+ - - -+-++-+
>  +-- + +-- + ++-++ -
> ---++-+-+- -+- - +-
> -- - -++-+  --+  +
> -   + --+ ++-+  +-
> --  ++- + +  -+--+
> + +++-+--+ +--+++ +
> -+- +-+-+-+  -+ +--+
> - +-+- +      ---+
> -     - ++ -+- --+--
>
-22.03055788969994

Explanation
`jt]           % keep inputting lines until an empty one is found
N$v            % concatenate all inputs vertically. This removes the last empty line
'- +'FT#m      % replace '-', ' ', '+'  by numbers 1, 2, 3
2-             % transform into -1, 0, 1 for '-', ' ', '+'
I#f            % find rows, columnss and values of nonzeros
bbh            % concatenate rows and columns into 2-col matrix or coordinates
tZP            % compute pair-wise distances for those coordinates
wt!*           % generate matrix of signs depending on signs of charges
*              % multiply distances by signs, element-wise
1w/            % invert element-wise
XR             % keep part over the diagonal
ss             % sum along colums, then rows
               % (output is implicitly printed)

Ruby, 133
->n{t=i=j=0.0
c=[]
n.tr(' ',?,).bytes{|e|e-=44
z="#{j}+#{i}i".to_c
i+=1
e<-1?i=0*j+=1:(c.map{|d|t+=d[0]*e/(d[1]-z).abs};c<<[e,z])}
t}

Maintains an array of previous charges in the form of tuples [charge, location(complex number)] and compares each new charge with this list, before appending it to the list.
All spaces in the input are replaced with commas. This enables the following assignment by subtracting 44 from their ascii code:
symbol  charge (internal representation)
+        -1
,         0
-        +1

The fact that the program considers + to be -1 and - to be +1 makes no difference to the final result. The fact that the program goes to the effort of calculating the influence of the charges of 0 for the spaces makes no difference, apart from slowing it down a bit :-)
Ungolfed in test program
g=->n{
  t=i=j=0.0                           #t=total potential; i and j are coordinates of charge.
  c=[]                                #array to store tuples: charge + location (complex number).
  n.tr(' ',?,).bytes{|e|              #replace all spaces with commas, then iterate through characters.
    e-=44                             #subtract 44 from ascii code: + -> -1; comma -> 0; - -> 1
    z="#{j}+#{i}i".to_c               #position of current character as complex number
    i+=1                              #advance x coordinate to next character.
    e<-1?i=0*j+=1:                    #if current character is newline, set i to zero and advance j instead,
    (c.map{|d|t+=d[0]*e/(d[1]-z).abs};#else add up the contribution for interaction of the current charge with all previous charges,
    c<<[e,z])}                        #and append the current charge to the list of previous charges.
t}                                    #return t

p g[
'+       -
-       +'
]

p g[
' - -- -+ - - -+-++-+
 +-- + +-- + ++-++ -
---++-+-+- -+- - +-
-- - -++-+  --+  +
-   + --+ ++-+  +-
--  ++- + +  -+--+
+ +++-+--+ +--+++ +
-+- +-+-+-+  -+ +--+
- +-+- +      ---+
-     - ++ -+- --+--'
]

Mathematica 223 bytes
Still golfing to do.
f[{{c1_,p1_},{c2_,p2_}}]:=N[(c1 c2)/EuclideanDistance[p1,p2],13];
h[charges_]:=Tr[f/@Subsets[DeleteCases[Flatten[Array[{r[[#,#2]],{#,#2}}&,Dimensions[r=Replace[Characters[charges],{"+"-> 1,"-"->-1," "->0},2]]],1],{0,_}],{2}]]

Last test case:
h[{" - -- -+ - - -+-++-+", " +-- + +-- + ++-++ -",
  "---++-+-+- -+- - +- ", "-- - -++-+  --+  +  ",
  "-   + --+ ++-+  +-  ", "--  ++- + +  -+--+  ",
  "+ +++-+--+ +--+++ + ", "-+- +-+-+-+  -+ +--+",
  "- +-+- +      ---+  ", "-     - ++ -+- --+--"}]

-22.030557890


text:
The Kimberling Sequence
Introduction
Of course, we've got a lot of sequence challenges, so here is another one.
The Kimberling sequence (A007063) goes as following:
1, 3, 5, 4, 10, 7, 15, 8, 20, 9, 18, 24, 31, 14, 28, 22, ...

This is produced by shuffling the normal iteration:
[1] 2  3  4  5  6  7  8

The first term of the sequence is 1. After that, we reshuffle the sequence until all the terms on the left are used. The shuffling has the pattern right - left - right - left - .... Since there are no terms at the left of the 1, there is no shuffling. We get the following:
 2 [3] 4  5  6  7  8  9

On the ith iteration, we discard the ith item and put that in our sequence. This is the 2nd iteration, so we discard the 2nd item. The sequence becomes: 1, 3. For our next iteration, we are going to shuffle the current iteration with the pattern above. We take the first unused item at the right of the ith item. This happens to be 4. We will append this to our new iteration:
 4

Now we're going to take the first unused item at the left of the ith item. This is 2. We will append this to our new iteration:
 4  2

Since there are no items left at the left of the ith item, we'll just append the rest of the sequence to the new iteration:
 4  2 [5] 6  7  8  9  10  11  ...

This is our 3rd iteration, so we'll discard the 3rd item, which is 5. This is the third item in our sequence:
 1, 3, 5

To get the next iteration, just repeat the process. I've made a gif if it isn't clear:

The gif took me longer than writing the actual post
Task

Given an non-negative integer n, output the first n terms of the sequence
You may provide a function or a program
This is code-golf, so the submission with the least amount of bytes wins!

Test cases:
Input: 4
Output: 1, 3, 5, 4

Input: 8
Output: 1, 3, 5, 4, 10, 7, 15, 8

Input: 15
Output: 1, 3, 5, 4, 10, 7, 15, 8, 20, 9, 18, 24, 31, 14, 28

Note: The commas in the output are not necessary. You may for example use newlines, or output a list, etc.

I'm working on a method using stack rotation

@Cyoce Good luck :)

it's looking like I'll need it

Pyth, 22 bytes
JS*3QVQ@JN=J.i>JhN_<JN

Try it online: Demonstration
Simply performs the shuffling technique described in the OP.
Explanation:
JS*3QVQ@JN=J.i>JhN_<JN
JS*3Q                    assign the list [1, 2, ..., 3*input-1] to J
     VQ                  for N in range(Q):
       @JN                  print J[N]
            .i              interleave
              >JhN             J[N+1:] with
                  _<JN         reverse J[:N]
          =J                assign the resulting list to J

Julia, 78 71 bytes
n->[(i=j=x;while j<2i-3 j=i-(j%2>0?1-j:j+2)÷2;i-=1end;i+j-1)for x=1:n]

This is an unnamed function that accepts an integer and returns an integer array. To call it, assign it to a variable.
The approach here is the same as that described on OEIS.
Ungolfed:
# This computes the element of the sequence
function K(x)
    i = j = x
    while j < 2i - 3
        j = i - (j % 2 > 0 ? 1 - j : j + 2)÷2
        i -= 1
    end
    return i + j - 1
end

# This gives the first n terms of the sequence
n -> [K(i) for i = 1:n]

Saved 7 bytes thanks to Mauris!

Mathematica 130 bytes
(n=0;s={};Nest[(n++;AppendTo[s,z=#[[n]]];Flatten[TakeDrop[#,1+2(n-1)]/.{t___,z,r___}:>
Riffle[{r},Reverse@{t}]])&,Range[3*#],#];s)&

We begin with a list consisting of the range from 1 to 3x, where x is the desired number of Kimberling sequence terms.
At each step, n, TakeDrop breaks the  the current list into a front list of 2n+1 terms (where the work is done) and rear list (which will be later joined with the reworked front list).   The front list is matched with the following pattern, {t___,z,r___} where z is the Kimberling term at the center of the front list.  r is Riffle'd with the reverse of t and then the rear list is appended. z is removed and appended to (AppendTo) the growing Kimberling sequence.
n is incremented by 1 and the current list is processed by the same function via Nest.

Example
(n=0;s={};Nest[(n++;AppendTo[s,z=#[[n]]];Flatten[TakeDrop[#,1+2(n-1)]/.{t___,z,r___}:>
Riffle[{r},Reverse@{t}]])&,Range[3*#],#];s)&[100]

{1, 3, 5, 4, 10, 7, 15, 8, 20, 9, 18, 24, 31, 14, 28, 22, 42, 35, 33,
46, 53, 6, 36, 23, 2, 55, 62, 59, 76, 65, 54, 11, 34, 48, 70, 79, 99,
95, 44, 97, 58, 84, 25, 13, 122, 83, 26, 115, 82, 91, 52, 138, 67,
90, 71, 119, 64, 37, 81, 39, 169, 88, 108, 141, 38, 16, 146, 41, 21,
175, 158, 165, 86, 191, 45, 198, 216, 166, 124, 128, 204, 160, 12,
232, 126, 208, 114, 161, 156, 151, 249, 236, 263, 243, 101, 121, 72,
120, 47, 229}

APL, 56 44 bytes
{⍵<⍺+⍺-3:(⍺-1)∇⍺-4÷⍨3+(1+2×⍵)×¯1*⍵⋄⍺+⍵-1}⍨¨⍳

This is an unnamed monadic train that accepts an integer on the right and returns an array. It's roughly the same approach as my Julia answer.
The innermost function is a recursive dyadic function that returns the nth term in the Kimberling sequence, given n as identical left and right arguments.
{⍵<⍺+⍺-3:                                    ⍝ If ⍵ < 2⍺ - 3
         (⍺-1)∇⍺-4÷⍨3+(1+2×⍵)×¯1*⍵           ⍝ Recurse, incrementing a and setting
                                             ⍝ ⍵ = ⍺ - (3 + (-1)^⍵ * (1 + 2⍵))/4
                                   ⋄⍺+⍵-1}   ⍝ Otherwise return ⍺ + ⍵ - 1

With that in hand, we're able to get individual terms of the sequence. However, the problem then becomes that this is a dyadic function, meaning it requires arguments on both sides. Enter the ⍨ operator! Given a function f and an input x, f⍨x is the same as x f x. So in our case, referring to the aforementioned function as f, we can construct the following monadic train:
f⍨¨⍳

We apply f to each integer from 1 to the input, yielding an array.
Saved 12 bytes thanks to Dennis!

Python 2, 76 bytes
for a in range(input()):
 b=a+1
 while-~b<2*a:b=a-(b^b%-2)/2;a-=1
 print a+b

Explanation
This is the OEIS formula after many golf-y transformations! It worked out beautifully. The original code was
i=b=a+1
while b<2*i-3:b=i-(b+2,1-b)[b%2]/2;i-=1
print i+b-1

I first got rid of i, replacing it with a+1 everywhere and expanding the expressions:
b=a+1
while b<2*a-1:b=a+1-(b+2,1-b)[b%2]/2;a-=1
print a+b

Then, rewrote b<2*a-1 as -~b<2*a to save a byte of whitespace, and moved the +1 into the selection, division by 2, and negation:
while-~b<2*a:b=a-(b,-b-1)[b%2]/2;a-=1

Then, -b-1 is just ~b, so we can write (b,~b)[b%2]. This is equivalent to b^0 if b%2 else b^-1 using the XOR operator, or alternatively, b^b%-2.
while-~b<2*a:b=a-(b^b%-2)/2;a-=1

Pyth, 29 25 bytes
VQ+.W<hHyN-~tN/x%Z_2Z2hNN

Jakube saved 4 bytes, but I have no clue how to read the code anymore.
Here is the old solution:
VQKhNW<hKyN=K-~tN/x%K_2K2)+KN

Translation of my Python answer. I'm not very good at Pyth, so maybe there's still ways to shorten this.
VQ                              for N in range(input()):
  KhN                             K = N+1
     W<hKyN                       while 1+K < 2*N:
           =K-~tN/x%K_2K2)         K = (N--) - (K%-2 xor K) / 2
                          +KN     print K + N

You can use .W to golf off 4 bytes: VQ+.W<hHyN-~tN/x%Z_2Z2hNN.

That's cool -- could you roughly explain how it works?

.W has the form: .W<condition><apply><start-value>. I used the start value hN, like you did in KhN. .W changes  this value as long as the <condition> is true. I used the same condition as you <hHyN. The condition is a lambda-function with the parameter H, so the current value (in your code K) is H. And I also used the same <apply> statement as you, I only replaced K with Z, because the <apply> statement is a lambda-function with parameter Z. We can ignore the =K, .W handles this. It replaces the old value with the calculated one. At the end print +...N


text:
Binary Run-Length Encoding
Overview

Run-length encoding — sequences in which the same data value occurs in many consecutive data elements are stored as a single data value and count

When using run-length encoding:
Input:  ABBBCCACB
Output: 1A3B2C1A1C1B

This sample has an output that is larger than the input.

Instead, it can be simplified for binary inputs by removing the data value in the result,
Input:  10001110101
Output: 1331111

which is significantly smaller. This works because, logically, if the there is a "next subset" then it must be of a different data value than the current subset. Since there are only two possible values (1 and 0), you always know the "next" data value subset.

Challenge
Implement binary run-length encoding demonstrated above.

Take input through STDIN or suitable alternative.
Output to STDOUT or suitable alternative.

Examples
In:  101011101011000011
Out: 11113111242

In:  01001010001
Out: 11211131

In:  000000000
Out: 9

You may assume that no subsets will be longer than 9 characters (there won't be 10 adjacent zeroes).

There is an error in your first example's output! The 1 digit after the first B shouldn't be there.

@AlexA.: I don't see where conversion to binary will actually happen, and besides, I think that the shortest way to run-length encode a binary string will be appreciably different from regular run-length encoding. There might be some tricks or the like available w.r.t. binary that isn't there for other inputs.

@El'endiaStarman Answers from the other challenge can be copied verbatim and be valid for this challenge, making this a duplicate.

So it's not encoded whether the string starts with 0 or 1?

For the purposes of this challenge, no. @xnor

@AlexA.: Answers from the linked duplicate wouldn't be valid here; they print the values as well as the counts.  For example, the top answer in sh is built around uniq -c with space-separated outputs. Dropping every other character of its output would take extra code, or motivate a different approach.  It's a very similar challenge (and not very practical because of the impossibility of encoding a run longer than 9 bits, unless you allow a 0 count?), but your argument for it being a duplicate seems totally flawed.

Pyth - 5 bytes
hMrz8

Test Suite.

Ruby, 37 29 bytes
->s{s.gsub(/0+|1+/){$&.size}}

Test:
->s{s.gsub(/0+|1+/){$&.size}}["10001110101"]
=> "1331111"

You can save a few bytes with global variable magic: ->s{s.gsub(/0+|1+/){$&.size}}

Ah, of course! Neat, thanks :)

Stuck, 5 bytes
soT]y

Takes a binary string as input and outputs an array.
Explanation
soT]y

s       get input string
 o      run-level encoding
  T     zip
   ]    flatten
    y   pops the data values off

CJam, 6 bytes
le`s2%

Try it here.

Haskell, 39 bytes
import Data.List
(show.length=<<).group

Unfortunately group is in Data.List, so I need the import.
Usage example: (show.length=<<).group $ "101011101011000011" ->
"11113111242".