Question: The challenge
-------------

The shortest code by character count that will output the numeric solution, given a number and a valid string pattern, using the [Ghost Leg](http://en.wikipedia.org/wiki/Ghost_Leg) method.

Examples
--------

```

Input: 3,
"| | | | | | | |
 |-| |=| | | | |
 |-| | |-| |=| |
 | |-| |-| | |-|"

Output: 2

Input: 2,
"| | |=| |
 |-| |-| |
 | |-| | |"

Output: 1

```

Clarifications
--------------

1. Do not bother with input. Consider the values as given somewhere else.
2. Both input values are valid: the column number corresponds to an existing column and the pattern only contains the symbols `|`, `-`, `=` (and [space], [LF]). Also, two adjacent columns cannot both contain dashes (in the same line).
3. The dimensions of the pattern are unknown (min 1x1).

Clarifications #2
-----------------

1. There are two invalid patterns: `|-|-|` and `|=|=|` which create ambiguity. The given input string will never contain those.
2. The input variables are the same for all; a numeric value and a string representing the pattern.
3. Entrants must produce a function.

Test case
---------

```

Given pattern:
"|-| |=|-|=|LF| |-| | |-|LF|=| |-| | |LF| | |-|=|-|"

|-| |=|-|=|
| |-| | |-|
|=| |-| | |
| | |-|=|-|

Given value : Expected result
 1 : 6
 2 : 1 
 3 : 3
 4 : 5
 5 : 4
 6 : 2

```

**Edit: corrected expected results**

Answer: 
AWK - 68 77 79 chars
--------------------

Pretty much a translation of Daniel's solution (we love ya man ;)

```
{for(i=0;i<3;){s=++i-2?"=":"-";if(s==$x)x--;else if(s!=$++x)x--}}END{print x}

```

But we can do away with `if/else` and replace it with `?:`

```
{for(i=0;i<3;){s=++i-2?"=":"-";s==$x?x--:s!=$++x?x--:x}}END{print x}

```

Run it with the starting position defined as the x variable:

```
$ for x in `seq 6`; do echo $x\ ;awk -F\| -vx=$x -f ghost.awk<<__EOF__
|-| |=|-|=|
| |-| | |-|
|=| |-| | |
| | |-|=|-|
__EOF__
done

1 6
2 1
3 3
4 5
5 4
6 2

```
Perl, ~~92~~ 91 chars
=====================

```
sub g{for$s(pop=~/.+/g){map$_[0]-=1-abs(index substr(" $s",$_[0]*2-2,3),$_),qw[= - =]}pop}

```

Another approach, ~~98~~ ~~97~~ ~~95~~ ~~94~~ ~~93~~ 92 chars
-------------------------------------------------------------

```
sub g{map{for$s(qw[= - =]){pos=$_[0]*2-2;$_[0]+=/\G((?<=$s)|.$s)/&&$&cmp$"}}pop=~/.+/g;pop}

```

Test suite
----------

```
$s=<<'__PATTERN__';
|-| |=|-|=|
| |-| | |-|
|=| |-| | |
| | |-|=|-|
__PATTERN__

for $n (1..6) {
    print g($n,$s);
}

```