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: 
Ruby - 66 95 92 83 chars
========================

(Alternating rows idea from Daniel's answer)
--------------------------------------------

```
def f s,m
m.each_line{|r|%w{= - =}.map{|i|s+=i==r[2*s-3]?-1:i==r[2*s-1]?1:0}}
s
end

```

92 chars

```
def f s,m
  s=s*2-2
  m.each_line{|r|%w{= - =}.each{|i|s+=i==r[s-1]?-2:i==r[s+1]?2:0}}
  1+s/2
end

```

Usage

```
map="|-| |=|-|=|
| |-| | |-|
|=| |-| | |
| | |-|=|-|"

1.upto(6) do |i|
    p f(i, map)
end

```

Output

```
6
1
3
5
4
2

```
Daniel's answer in C# - 173 chars
=================================

After seeing Daniel Vassallo's solution, I was too ashamed of mine to post it. But here's Daniel's answer ported to C# for the heck of it. One major drawback in C# was having to do bounds checking, which cost 20 characters.

```
int G(string s,int n){var l=s.Split('\n');n*=2;for(int i=0,j,c;i<l.Length;i++)
for(j=0;j<3;n+=n>2&&l[i][n-3]==c?-2:n<l[i].Length&&l[i][n-1]==c?2:0)c=j++==1?45
:61;return n/2;}

```

Formatted:

```
int G(string s, int n)
{
    var l = s.Split('\n');
    n *= 2;

    for (int i = 0, j, c; i < l.Length; i++)
        for (j = 0; j < 3; n += n > 2 && l[i][n - 3] == c ? -2 : n < l[i].Length && l[i][n - 1] == c ? 2 : 0)
            c = j++ == 1 ? 45 : 61;

    return n / 2;
}

```