[Question]
  [
Given a rectangular haystack of size at least 2x2 composed of all the same printable ASCII characters, output the location (counting from the top-left) of the needle which is a different character.
For example, if the following haystack is input:
```
#####
###N#
#####
#####
```
The output should be `3,1` when zero-indexed (what I'll be using in this challenge) or `4,2` when one-indexed.
The haystack can be composed of any printable ASCII character:
```
^^^
^^^
^N^
^^^
^^^
^^^
```
output: `1,2`
and the needle will be any *other* printable ASCII character:
```
jjjjjj
j@jjjj
jjjjjj
```
output `1,1`
It's also possible to have a needle in the corner:
```
Z8
88
```
output `0,0`
```
88
8Z
```
output `1,1`
or to have the needle at the edge:
```
>>>>>>>>>>
>>>>>>>>>:
>>>>>>>>>>
```
output `9,1`
### Rules and Clarifications
* Input and output can be given by [any convenient method](http://meta.codegolf.stackexchange.com/q/2447/42963). This means you can take input as a list of list of characters, as a single string, etc.
* You can print the result to STDOUT or return it as a function result. Please state in your submission what order the output is in (i.e., horizontal then vertical, as used in the challenge, or vice versa).
* Either a full program or a function are acceptable.
* You do *not* get to pick which characters to use. That's the challenge.
* The haystack is guaranteed to be at least 2x2 in size, so it's unambiguous which is the needle and which is the hay.
* There is only ever one needle in the input, and it's only ever one character in size.
* [Standard loopholes](http://meta.codegolf.stackexchange.com/q/1061/42963) are forbidden.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so all usual golfing rules apply, and the shortest code (in bytes) wins.
  
[Answer]
# [R](https://www.r-project.org/), ~~49~~ ~~47~~ 44 bytes
```
function(m,`?`=which)m==names(?table(m)<2)?T
```
[Try it online!](https://tio.run/##TY3BTsMwDIbveQprvcRSuWwIVWilHDlMO3HaoVrI3DVTk1aJgfL0JW3Fwi/Z/h1/jv3UwP5haj6dZtM7afNzdS6/W6NbtGXplKUgK1YfHUmL@y1W71P2Rt1AHv6WgHvwpC7ALQFTYNAqUADlLqB790WeZ0SBVezNKK7l/dyIQQ1D9yMD@zB0huX80cG4eDUfMd9sMNcoRCOv8hFRZLPmfMySj3kBniJQ1/Uaxzr5GAuwi8Btkbi9rmXtluk2Tk@FKIrURl@c0u7LXck@/3udfgE "R – Try It Online")
Takes input as a matrix, returns 1-indexed coordinates
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~41 38~~ 37 bytes
*3 bytes saved thanks to @nwellnhof.*
*1 byte saved thanks to Jo King.*
```
{map {[+] ^∞Z*!<<.&[Z~~]},$_,.&[Z]}
```
[Try it online!](https://tio.run/##RUxbCoMwEPzPKbZRilrxs0h90BN4gKgpWhQqaqWxHyL63VP0cL2IjYmYgdmZ2R22K171eWkGOJYQLGOTdTDGpxTo7/Ml1sH3nWNM5jmdbP1mrz6dFg@xdw59wXpDZyaMwLIBdOYJLfnOqR9twRz@zLCc@7PJ@YL1ppyyhgOJpE1aDBNC4h3WViDOSExtm9j0tgKlFAlGm0qqQiWAqqsUAXUlLnJdFV0eiYrhDrS7i7Lh2lz@ "Perl 6 – Try It Online")
## Explanation
It takes the input as a list of lists of characters and returns list of length 2 containing zero-based X and Y coordinates of the needle.
It works by applying the block `{[+] ^∞ Z* !<<.&[Z~~]}` on the input and on its transpose. `.&[Z~~]` goes through all columns of the argument and returns `True` if all the elements are the same, `False` otherwise. We then negate all the values (so we have a list with one bool per column, where the bool answers the question "Is the needle in that column?"), multiply them element-wise with a sequence 0,1,2,... (`True = 1` and `False = 0`) and sum the list, so the result of the whole block is the 0-based number of the column where the needle was found.
# Nwellnhof's better approach, [Perl 6](https://github.com/nxadm/rakudo-pkg), 34 bytes
```
{map *.first(:k,*.Set>1),.&[Z],$_}
```
[Try it online!](https://tio.run/##RUxBCoMwELznFSGKGJFALyUoSl/gpTdrLVoiaNWKSQ8ivj2NiZiBmdnZHXZic3@VwwK9BiZyHaoJBqRpZy786BMG5M5EesEh8R75M3Rfm4wB/9VQMFVwOYYr5NUCXR5rb9SO9O3IOFGf/IC8v0OtFlxgo6aGEoNiLEYENwD0O@TsAIqZVudQhOOjUJYl0MwON7SFTgN0N2Ma9ppTQKmNVMXcxvQEOKfIjunelH8 "Perl 6 – Try It Online")
## Explanation
Generally the same approach, just more effective. It still uses a block on the array and its transpose, but now the block converts all *rows* into`Sets` and checks for the number of elements. The `first` function then gives index (due to the `:k`) of the first row that contained more than 1 element. Because of that, the order of `$_` and `.&[Z]` needed to be swapped.
[Answer]
# [Python 2](https://docs.python.org/2/), 57 bytes
```
lambda m:[map(len,map(set,a)).index(2)for a in zip(*m),m]
```
**[Try it online!](https://tio.run/##TY5BCoMwEEX3OcWAiyQldeFKBEtP4AGsDaSoNGJi0CBtL28zcaEPkvk/8yHfff17stnWl802KvNqFZjiYZRjY2cFzqXzQnGeatt2H5bxfppBgbbw045dDBfmuflu8QuUwCilDUkQvKvk0EkSdkRATEgp91PJQ0t5SgwRMtz3ETmt65zk@cnnwdfoOSFYEAthx1isIBBYQz@06eJG7RmPj5idMbjuIcTN2nqYyaFpUNcbFdCzlYcfG0u3Pw "Python 2 – Try It Online")**
---
A port of this to **[Python 3](https://docs.python.org/3/)** can be **62 bytes**:
```
lambda m:[[len(set(v))for v in a].index(2)for a in(zip(*m),m)]
```
The list comprehension, `[len(set(v))for v in a]`, is shorter than the double map by two bytes now as it would need to be cast to a list like `list(map(len,map(set,a)))`
[Try it online!](https://tio.run/##TVBLCoMwFNznFA9cJCnWRbsRwdITeAA/AYtKIxpFQ2h7@TQvWehA8mbmDWTI@tXvRd3tkNd2audX18KcVdXUK7b3mhnOh2UDA1JB2yRSdf2H3bzXOo/95MouM49n3ljd73qHHBiltCYRAu8iOngUuR2JwSeEEOEU4uBCnBKjBxmfYXic1mVK0vSkU6dL1JwQbIiFsLgvlhFwMK4fymRfJ6kZ9yZmNwyaEEKsm1SabSEQBHXs@qAxDO5b3JO1otz@AQ "Python 3 – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 20 bytes
```
c≡ᵍ∋Ȯ&;I∋₎;J∋₎gȮ∧I;J
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/P/lR58KHW3sfdXSfWKdm7QmkHzX1WXtB6PQT6x51LPe09vr/P1pJGQSUdEC0H5RWRtCx/6MA "Brachylog – Try It Online")
Outputs `[I,J]`, where `I` is the row index and `J` the column index, both 0-indexed.
Stupidely long, but getting indexes in Brachylog is usually very verbose.
### Explanation
```
c                       Concatenate the Input into a single string
 ≡ᵍ                     Group identical characters together
   ∋Ȯ                   Ȯ is a list of One element, which is the needle character
     &;I∋₎              Take the Ith row of the Input
          ;J∋₎          Take the Jth character of the Ith row
              gȮ        That character, when wrapped in a list, is Ȯ
                ∧I;J    The output is the list [I,J]
```
[Answer]
# [PHP](https://php.net/), ~~99~~ 85 bytes
Using string without newlines and the width (or height) `('########N###########', 5`) as input.
* -5 bytes by removing chr() call, props to @Titus
* -9 bytes by taking input as two function args, also props to @Titus
```
function($a,$l){return[($p=strpos($a,array_flip(count_chars($a,1))[1]))%$l,$p/$l|0];}
```
[Try it online!](https://tio.run/##ZZDBS8MwGMXv/Ss@tkgS@MBWUYq16kXwIHPnlayE2tLO2IYkPcjc317TrbQHf4fwHu/xSKJrPTw@61oDqdKh6tvCNV3LiESi@NGUrjdtxohOrTO6s2MgjZE/eaUazYqub11e1NKck4jzLBKcXxGFRF8T9RuK5DQkxJXWWUghCwAyup7YrBco3gk8p/sLm/0MxdspO1x4OcxQvJ@yXRzHFG8m581ucU//eVgkxSgUgUiCoOpMKYuawXRjab0CDke/AmVRd1DUffuVW60ax4jLQoH@9G9GoBlFaL616j5LtsIV@h8dh@aO3xlrwte2b9v89eN9FklwGv4A "PHP – Try It Online")
Ungolfed:
```
function need_hay( $a, $l ) {
    // identify the "needle" by counting the chars and 
    // looking for the char with exactly 1 occurrence
    // note: this is 1 byte shorter than using array_search()
    $n = array_flip( count_chars( $a, 1 ) )[1];
    // find the location in the input string
    $p = strpos( $a, $n );
    // row is location divided by row length, rounded down
    $r = floor( $p / $l );
    // column is remainder of location divided by row length
    $c = $p % $l;
    return array( $c, $r );
}
```
Output:
```
#####
###N#
#####
#####
[3,1]
^^^
^^^
^N^
^^^
^^^
^^^
[1,2]
jjjjjj
j@jjjj
jjjjjj
[1,1]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~9~~ 6 bytes
Saved 3 bytes switching input format.
Input is taken as a string and a row-length.  
Output is a zero-based list of the form `[y, x]`
```
D.mks‰
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fRS83u/hRw4b//@0wgRWCyWVoAAA "05AB1E – Try It Online")
or as a [Test Suite](https://tio.run/##yy9OTMpM/W/m9t9FLze7@FHDhv86/5WhwE8ZAbhMueIgwC8ODriMubIgwCELDrjMuKIsLCy4jLiAZBSQssMEVggml6EBAA)
**Explanation**
```
D           # duplicate the input string
 .m         # get the least frequent character
   k        # get its index in the string
    s       # swap the row length to the top of the stack
     ‰      # divmod the index of the least frequent char with the row length
```
[Answer]
# [Python 3](https://docs.python.org/3/) + [NumPy](https://docs.scipy.org/doc/numpy-1.16.1/reference/), ~~75~~ 66 bytes
-9 bytes thanks to [@ASCII-only](https://codegolf.stackexchange.com/users/39244/ascii-only)
```
lambda x:where(x.view('i')-median(x.view('i')))
from numpy import*
```
[Try it online!](https://tio.run/##nZJNDsIgFIT3nOJFFwVT3bhpmmg8QQ9QfxJMIWKEEqTaxnj2itaFFrWNJLNg3jfDW6Aru8vVtOazVX2gcptRKOPzjhmGy8lJsDMOREDGkmWCqleLEMRNLkEVUlcgpM6NHdVC6cIeYQYYgTvUGFrh5TIYBmFL6/BBPM87kXQSw77EmoTvm2yc36id/j1J/sh0Trzt9s731W64u4te1Icu783U@ZGXjhrXo6OvdPqBnju/W@22Pqn4r9T8viMiCPHcQAlCQfNj40eVNkJZXJKXCx8kjGUHBuII1MKFu/F1slIDUt8A "Python 3 – Try It Online")
This assumes that the input is a NumPy array. The output is zero-indexed, and first vertical, then horizontal.
It converts the input from `char` to `int` then calculates the median of the array, which will be the haystack character. We subtract that from the array, which makes the needle the only non-zero element. Finally, return the index of that element with `numpy.where()`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
Outputs **[height, width]** (1-indexed).
```
ŒĠLÐṂ
```
[Try it online!](https://tio.run/##y0rNyan8///opCMLfA5PeLiz6f/h9kdNa9yA2P3//@hodWUQUNdRADH8YAxlJEasDpdCtHpcXBxICEb5ofAQFERxFhiAxLIc4CyIGERBlAVIyMICyrWAcKOgXDs4AAnDOVYoPDv12FgA "Jelly – Try It Online")
```
ŒĠLÐṂ – Monadic link / Full program. Takes a list of strings M as input.
ŒĠ    – Group the multidimensional indices by their values (treating M as a matrix).
  LÐṂ – And retrieve the shortest group of indices (those of the unique character).
```
---
### [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
ŒĠḊÐḟ
```
[Try it online!](https://tio.run/##y0rNyan8///opCMLHu7oOjzh4Y75/w@3P2pa4wbE7v//R0erK4OAuo4CiOEHYygjMWJ1uBSi1ePi4kBCMMoPhYegIIqzwAAkluUAZ0HEIAqiLEBCFhZQrgWEGwXl2sEBSBjOsULh2anHxgIA "Jelly – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Maybe this could've just been a comment for Mr. Xcoder it is pretty similar...
```
ŒĠEƇ
```
A monadic link accepting the matrix of characters which yields a list of one item, the 1-indexed (row, column) co-ordinate from top-left.  
(...As a full program given an argument formatted such that parsing results in a list of lists of characters -- that is a list of strings in Python format -- the single coordinate is printed.)
**[Try it online!](https://tio.run/##y0rNyan8///opCMLXI@1////P1pdXT0LDIAMLh0QzwGFB5eLBQA "Jelly – Try It Online")**
### How?
```
ŒĠEƇ - Link: matrix, M
ŒĠ   - multi-dimensional indices grouped by Value
     -  ...due to the 2*2 minimum size and one needle this will be a list of two lists one
     -     of which will have length one (the needle coordinates as a pair) and the other
     -     containing all other coordinates as pairs
   Ƈ - filter keeping those for which this is truthy:
  E  -   all equal?
     -   ... 1 for the list of length 1, 0 for the list of at least 3 non-equal coordinates
```
[Answer]
# JavaScript (ES6), 55 bytes
Takes input as \$(s)(w)\$, where \$s\$ is a string and \$w\$ is the width of the matrix. Returns \$[x,y]\$.
```
s=>w=>[(i=s.indexOf(/(.)\1+(.)/.exec(s+s)[2]))%w,i/w|0]
```
[Try it online!](https://tio.run/##jY7fCoIwFIfvfYpBRDtozj8UJig9Qd1rCaEzlHDRNLvo3c3pEIuwzsX4nbPzfVt@up94fMuu5bJgCW1Sr@GeX3t@iDOP61mR0Mc@xQTrcDDV9iQ6fdAYc5VDaB0B5rWWkfppHJuYFZxdqH5hZ5xihAhBrCqvVekiWzMVhBYzUQukyrwb5dl7VgCvAJQJpalZYj2KIgmO0u7L7C21entK39q7D@ddSTDfjpv@phWtJ0WGZoj1wJGc4wjG@udxZ2CC38ymZ/yhJDv07ufAF1LTAGhe "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), ~~65~~ 64 bytes
*Saved 1 byte thanks to @Neil*
Takes input as a matrix of characters. Returns \$[x,y]\$.
```
m=>m.some((r,y)=>r.some((c,x)=>!m[p=[x,y],~y&1].includes(c)))&&p
```
[Try it online!](https://tio.run/##lY/dCoIwGIbPvYqFYBuspXViwkZX0AUoCrI0FHXiT@RJt25WasvC6Dt73u15vy32z37JiyivVpk4Bm1I25SylJQiDSAscIMoK3ri@NLRInVy6lxw4@JroxkuiTKe1MeghBwhpGl5y0VWiiQgiTjBEDpgvQairvK6ssAWGwoADiFkqd5n6WKJDxNWv7DiIqTMbDDwZjA8z5P8CR1mzj5pfmu3dPxW/BjJj/fToL/xo1PH@mDYpqSb5j/PMd9U@6e6e6lsHKlizKxvIXv2tzc "JavaScript (Node.js) – Try It Online")
### How?
We look for the first character \$c\$ located at \$(x,y)\$ which does not appear anywhere in another row \$r[Y]\$. We can perform this test on any row, as long as \$Y\ne y\$. Because the input matrix is guaranteed to be at least \$2\times 2\$, we can simply use \$Y=0\$ if \$y\$ is odd or \$Y=1\$ if \$y\$ is even.
[Answer]
# Java 8, ~~132~~ 111 bytes
```
m->{int c=m[0][0],i=0,j;for(c=m[1][0]!=c?m[1][1]:c;;i++)for(j=m[i].length;j-->0;)if(m[i][j]!=c)return i+","+j;}
```
-8 bytes (and -13 more implicitly) thanks to *@dana*.
Input as character-matrix.
[Try it online.](https://tio.run/##xZBfa4MwFMXf@ynu7EvEP7Rv0qDb2PN82ZtiIUttm0xjiWlHKX52l9iu7GE6WoRdJMT7u5dzTjg5EI@vPlpakLqGV8LEaQLAhMrlmtAcYvML8KYkExugiG6JTLM0g9LGmjQTfdSKKEYhBgEhtKUXnfQ@0LBMZ5n@XBbOXI7XlUSmNze9h5A@dtd5tqAYM8exDeeas8wvcrFRW8w9L5phm62R6abcbNkyV3spgDmWazkcNy02Fnb790JbuDg5VGwFpc6Czr61XWJfghxrlZd@tVf@TiNVCCR8ikT@Cd/RzoMA1tSU5avqRZNnKckR2e4PGA/B6XiwY43dPfhtCZbLZZ/QEIrv2roF3R@Jd9WnxJ8G6W@791tJgj6hIBhNJOgXScYTSf41STKeSHStPrHrwOLPiWjAVjNp2i8)
**Explanation:**
```
m->{                    // Method with char-matrix parameter and String return-type
  int c=m[0][0],        //  Character to check, starting at the one at position 0,0
      i=0,j;            //  Index integers
  for(c=m[1][0]!=c?     //  If the second character does not equal the first:
         m[1][1]        //   Use the character at position 1,1 instead
        :c;             //  Else: keep the character the same
      ;i++)             //  Loop `i` from 0 indefinitely upwards:
    for(j=m[i].length;j-->0;)
                        //   Inner loop `j` in the range (amount_of_columns, 0]:
      if(m[i][j]!=c)    //    If the `i,j`'th character doesn't equal our character to check:
        return i+","+j;}//     Return `i,j` as result
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~12~~ 8 bytes
```
tX:XM-&f
```
[Try it online!](https://tio.run/##y00syfn/vyTCKsJXVy3t//9oBXV9dQV1RXUwbQ0iwCwYqRALAA "MATL – Try It Online")
Using the `mode` function as the majority-detector. Returns 1-based indices. 
```
 t           % duplicate the input
  X:         % turn the copy into a linear array
    XM       % find the arithmetic mode of that (the 'haystack' character)
      -      % Subtract that from the original input
       &f    % find the position of the non-zero value in that result
```
*-4 characters thanks to @LuisMendo*
[Answer]
# Wolfram Language ~~37~~ 58 bytes
My earlier entry did not correctly handle the case where the "odd character out" was at the upper left corner of the matrix. This does.
```
#~Position~Keys[TakeSmallest[Counts@Flatten@#,1]][[1]]&
```
---
`Counts@Flatten@#` lists how many of each character are in the array, `#`.
`TakeSmallest[...,1]` returns the least frequent count, in the form of an association rule such as `<| "Z"->1|>`
`Keys...[[1]]` returns the "key" to the only item in the association, that of the least used character. ("Z" in the present case)
`#~Position~...` returns then position of the key in the original matrix, `#`.
[Answer]
# Perl 5 `-p00`, ~~52~~ 45 bytes
```
/^(.)(\1*
)*(\1*)|^/;$_=$&=~y/
//.$".length$3
```
[45 bytes](https://tio.run/##K0gtyjH9/18/TkNPUyPGUItLUwtEadbE6VurxNuqqNnWVepz6evrqSjp5aTmpZdkqBj//68MAlxA7AcmlWEkF1dcXBwE@8Uh2EDMxZUFBlxZDhAKwuPiirLgsrAA0kDCIgpI28EBgmmFLPovv6AkMz@v@L@ur6megeF/3ZwCAwMA)
[52 bytes](https://tio.run/##K0gtyjH9/1@fS99apdxWyUFbyVo/TkNPUyPGsIZLU7smDigeDxZXVSnXU1HSy8wrAfH0Vcr//1cGAS4g9gOTyjCSiysuLg6C/eIQbCDm4soCA64sBwgF4XFxRVlwWVgAaSBhEQWk7eAAwbRCFv2XX1CSmZ9X/F/X11TPwPC/bk6BgQEA)
How
* `-p00` : like `-n` but also print, paragraph mode
* `/^(.)(\1*
)*(\1*)|^/` : matches either
	+ from start `$1`: first character, `$2`: repetition (not used), `$3`: characters before the "needle" in the line, `$&` whole match
	+ or null string (position 0) no capture.
* `$_=` : to assign the default input/argument variable
* so `$&=~y/
//` the number of newlines of `$&`
* `.$".` : concatenate with `$"` (space character by default) and concatenate
* `length$3` : the length of `$3`
[Answer]
# [R](https://www.r-project.org/) 42 bytes
```
function(m)which(ave(m,m,FUN=length)==1,T)
```
[Try it online!](https://tio.run/##lY9RS8MwFIXf8ysCPtwEsmHbKWXYsZcNfFEQ9yJ9KaW1Gc21tDfaf18jsZtlbLhLHkJO7jnfaYeSP8z4UFrMSX@gMPKr0nklss9CGGXUdveU1AW@UyWTJFCvcmA3fNNnpqkLHrA8IwEpbvo5D1JMESQzP4aw97PeHwa8YrHWHYmO2q6pNbkQAPm7ZTJqde@eeKT4vRzdH7GxtPTmLv3F4jH52dJBLB09Y6MCfr8tGgEzUIs7l/KHPRz/efpwQr86neXxem2T4PZSlfB8lf81iaZNokmTtziOr@IN3bmEG53DHb4B)
**Input:** a haystack matrix `m`
**Output:** `(row,col)` vector - index starting at `1`
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~109~~ ~~108~~ 107 bytes
First() => Last() for -1 byte
currying for -1 byte thanks to Embodiment of Ignorance
```
a=>w=>{var d=a.Where(b=>b!=a[0]).Select(b=>a.IndexOf(b));return d.Count()>1?(0,0):(d.Last()%w,d.Last()/w);}
```
[Try it online!](https://tio.run/##dVHva8IwEP3c/hW3ukGCWdYqG2JtNxAGgrgPDgRFobZRKy4daVyF0r@9S1p/bWPvwzW9e/fyLhem92Eal697HvZSKWK@JlD9xFwSQFVUAfs@rFQavDLw/Mzz869AQOQFdLJhgqGl5y9vvGBmzzEdsx0LpU4FdMAjdnhboSXGrmByLzhEtJ/suUTYd56RTWzcRREdBqnK3GXkdHzIsFuUrqmvkSyV/SBlKXjAWQYInZxqZ9cu8WyemwhZjSNGjQssAo@YGAagNgEHY6KJixqjxRmK1laamucQaB152xov2zMU76mWcy5y006nY@kuLaBrNgH7WFOl6Y9a3Ve4prlKhJ4BYjWg7apP7zIzHTK@lhuVbTaxmZtGP@FpsmN0ImLJ0K2Vx0UXLOyahn4rUb2SXhU6S8ziOR1I9uHUEf9XaZ1E1kkSKZU/tJb76/phzLUFdvhUG2cR5LqTvifjaj8IF0RpSciVq@usdluU3w "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 22 bytes
```
$#:(i.~.{~1 i.~#/.~)@,
```
[Try it online!](https://tio.run/##ZYxNC4JAFEX3/opLRk/BJj8qbEQxAiEQidy5cCOJ2aJFixaBf92eaUp0hmFm3px763YmqIQvQTBgQvJeChzOcdTOValdRSNejQU@1ZVo9NBodUUpqpsvoC1lqS@ClfKo7k9@X4rqHmoGNIr2x5g8Ou3TlHS8GnCAY50HCw48rLHBHKQOJOoE9Z7Npoct2@zlPUk@Qt@2znLYY6vuCeuRwTJ5edxod1bmuu5PepjzOBvnu0@rZXYfwT9yupLSvgE "J – Try It Online")
NB. returns answer in (row, column) format.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~53~~ 47 bytes
```
lambda s,w:divmod(s.find(min(s,key=s.count)),w)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaFYp9wqJbMsNz9Fo1gvLTMvRSM3M0@jWCc7tdK2WC85vzSvRFNTp1zzf0FRZl6JQpqGkjIU@CkjgJKOgqnmfwA "Python 2 – Try It Online")
Call as `f("########N###########", 5)` (allowed in a [comment](https://codegolf.stackexchange.com/questions/179351/find-the-needle-in-the-haystack#comment432444_179351)). Outputs `(y, x)`.
Erik saved 6 bytes, suggesting rearranging the output + using `divmod`. Thanks!
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~107~~ ~~98~~ ~~82~~ 77 bytes
```
$l=@{}
$args|%{if($_-10){$l.$_+=$x++,+$y}else{$x=0;++$y}}
$l|% v*|? c*t -eq 2
```
[Try it online!](https://tio.run/##XZBRboMwDIbfc4ooNSs0KYLuhXVizQl6gD6AEEvXdZHWAduoAmdnDhTY9kt27N@fFcmX929VlCeldQdHGlPTgY6laQlkxUvZOOb16EK6DgPPgPYh5THUnAsO11bpUhmo4@CR2xZXdOPQr1Wzo/mqomv1QTddS4h0CRGuXJIkSYbYJ3ONsZQiFBvvRvlWNu/8ucaM1L0IR2phZfN@MdeY/1LnXuQsh2fo@u8m5BCRKLJeIILRQyM6/OOeJs3l9reL@EOPe7ShDjWEouCUXcsqy98EqPqi8ko945EhHYaFKj91hcYd3l6OaD9j4LLbnOEl2bTOvO24yEjb/QA "PowerShell – Try It Online")
Takes a splatted string with LFs. Returns zero-indexed location x,y. Unrolled:
```
$locations=@{}                      # make a hashtable. key=char, value=location array
$args|%{
    if($_-10){                      # if current char is not LF
        $locations.$_+=$x++,+$y     # add $x,$y to hashtable value and move $x to next pos
    }else{
        $x=0;++$y                   # move $x,$y to next line
    }
}
$locations|% Values|? Count -eq 2   # find and output location array with 2 elements (x,y)
```
[Answer]
# [Scala](http://www.scala-lang.org/), 98 bytes
Golfed version. [Try it online!](https://tio.run/##hZHBToQwEIbv@xST7qWN2oMnQsJGH2DxQLysiqlsWUugYNsQdd1nx6EB2SUhTgLlm/@fTunYTJSiq98KmTnYCqXhuALYyxwqBCrMwYZwb4z4ekqcUfrwwkJ41MpB5J0ArSjBSessZhL5QX0SgBCy7mNAgB@E@BLXc8QibrFNs8XGSl9Pe6VpOnkvIV5UZrC8e@FjMhd3M/axXL8LJm8QLPuCc99u5vMS8@@uH0BOqxAv9O/eo4o7I7Rtait5JRr6yl2dSMet@paMK72Xnw85vWVhWP2jx6rs@j5@bjyvjRTZOxw9Q7QZDtlPtsWp9llum1I5Sp41YaM8FtIGD@hKPQoDUoLfNxsgcIX/0jJcpvLTqn9Oq@4X)
```
def f(m:Seq[String])=m.transpose.map(_.toSet.size).indexOf(2)::m.map(_.toSet.size).indexOf(2)::Nil
```
Ungolfed version. Try it online!
```
object Main {
  def main(args: Array[String]): Unit = {
    val tests = Seq(
      """#####
        |###N#
        |#####
        |#####""".stripMargin,
      """^^^
        |^^^
        |^N^
        |^^^
        |^^^
        |^^^""".stripMargin,
      """jjjjjj
        |j@jjjj
        |jjjjjj""".stripMargin,
      """Z8
        |88""".stripMargin,
      """88
        |8Z""".stripMargin
    )
    
    val f: Seq[String] => Seq[Int] = m => m.transpose.map(_.toSet.size).indexOf(2) :: m.map(_.toSet.size).indexOf(2) :: Nil
    tests.foreach { test =>
      val v = test.split("\n")
      v.foreach(println)
      println("   -> " + f(v) + "\n")
    }
  }
}
```
[Answer]
# [Julia](https://julialang.org), 78 bytes
```
s->(n=argmin(x->count(x,'
's),s);q=split(s);~=findlast;b=~(n.∈q);(n~q[b],b))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=hVAxDoJAEIztvuKiBXfJYQQtLpIjvoAHaCQBBQPBU7wjsaL2DzY0FD5JS18icooNiZPMzhYzO8le67TIkqC6iSjaZhHiqC5UbLK7J00XCx6cdvtE4LPpbg6FUPhMDTAkoZI4OZfHLFG4WUseJ2KbBVI5IS-xGD8vl5w4WJT5KlzTkBB99TEwABaBlNFJId2IYTh6Axp67Rx95hAI4hzhGbVJT8r3fWjpfVTzm7LptC-VtoB0oaXFL9JbtGTA2NdjUavPwxrP8s8dtwN02_y3ul3FpMnrf1WV1hc)
This function takes input as a single string, which probably isn't the most efficient approach. The output is 1-indexed.
-19 bytes thanks to MarcMush: add a newline to the haystack to guarantee that the needle is always the least frequent character, even in a 2x2 haystack.
Interestingly, concatenating a character literal with a string variable doesn't require an operator in Julia. Apparently, it's parsed just like [numeric literal coefficients with variables](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/#man-numeric-literal-coefficients). This saves a byte here, which is the best thing to come out of [Julia's choice of concatenation operator](https://docs.julialang.org/en/v1/manual/faq/#Why-does-Julia-use-*-for-string-concatenation?-Why-not-or-something-else?).
[Answer]
# [Lua](https://www.lua.org/), 103 91 bytes
```
s,l=...s:gsub('.',load'c=...b=b or not s:find(c..c,1,1)and s:find(c,1,1)')print(b%l-1,b//l)
```
[Try it online!](https://tio.run/##RchBCoAgEADArwgRKmwrHroEfaE/uEoRLBpZ798oouY4fAaRCjwiYh2WepLRqIFLSDreSSOpsqtcDlWHec3JRMQIHrwNOX33hLbbvubDUMudB3KOrYg0r6n5SX8B "Lua – Try It Online")
Ungolfed version:
```
s,l=...                                           --Take in haystack and line width as args
s:gsub('.',function (d)                           --For each character in s
    b=b or not s:find(c..c,1,1)and s:find(c,1,1)  --If there is only one instance of c, store location
end)
print(b%l-1,b//l)                                 --Print results
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 15 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
this can probably be golfed down a bit as there's a lot of register shenanigans i'm not a huge fan of. takes an array of a single string with a width
```
Ç║æ░·╝;J╕╤¢ⁿÿì<
```
[Try it online! (With test cases)](https://staxlang.xyz/#p=80ba91b0fabc3b4ab8d19bfc988d3c&i=%5B5,%22%23%23%23%23%23%23%23%23N%23%23%23%23%23%23%23%23%23%23%23%22%5D%0A%5B2,+%22Z888%22%5D%0A%5B2,+%22888Z%22%5D%0A%5B10,+%22%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3A%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%22%5D%0A%5B6,+%22jjjjjjj%40jjjjjjjjjj%22%5D%0A%5B3,+%22%5E%5E%5E%5E%5E%5E%5EN%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%22%5D&m=2)
This is Packed Stax, which unpacks to the following:
# [Stax](https://github.com/tomtheisen/stax), 17 bytes
```
Nc|!IYxhX%yx/2l|u
```
[Run and debug it](https://staxlang.xyz/#c=Nc%7C%21IYxhX%25yx%2F2l%7Cu&i=%5B5,%22%23%23%23%23%23%23%23%23N%23%23%23%23%23%23%23%23%23%23%23%22%5D%0A%5B2,+%22Z888%22%5D%0A%5B2,+%22888Z%22%5D%0A%5B10,+%22%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3A%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%22%5D%0A%5B6,+%22jjjjjjj%40jjjjjjjjjj%22%5D%0A%5B3,+%22%5E%5E%5E%5E%5E%5E%5EN%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%22%5D&m=2)
```
N                 # get the string
 c|!              # get the rarest element
    I             # get the first index in the string of this
     Y            # store that in register Y
      xh          # get the width
        X         # and store this value in register x
         %        # modulo with what was stored in register Y
          yx      # register y and register x from above
            /     # divide them
             2l   # create an array of the top two elements on the stack
               |u # and put it in a format which can be printed
```
[Answer]
# [Python 3](https://docs.python.org/3/), 93 bytes
```
def f(s):x=s.find("\n")+1;return[(i%x,i//x)for i,c in enumerate(s)if s.count(c)<2and" "<c][0]
```
[Try it online!](https://tio.run/##TVBbCoMwEPzfUywpBUPFvn7EVukJPIBWQTShKW0sSQRL6dltYu1jYHZnmQR29nY3p1Zuh6FhHLmnadTHOuBCNh45SkIX651iplMy98S898Vy2VPeKhR@jUIik92Vqcow@1Nw1EHddtJ4Nd1vKtkQJPu6yFfFoI3SGGNOCJk5gGU61tlUreNblmUJI9Opvzm55xFwPrzbiMnKQgjDj84g@@jkC/iq6CcT@6QAcJG0C@QWjQAtbkrYJJr@DZykjDUXhkJjZfDh7vUM3JmGFw "Python 3 – Try It Online")
Input is taken as a multiline string. Output is 0-indexed
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 40 bytes
```
@(x){[r,c]=find(x-mode(+x(:))) [c,r]}{2}
```
Port of [@sundar's MATL answer](https://codegolf.stackexchange.com/a/179361/36398). Output is a two-element vector with 1-based column and row indices.
[Try it online!](https://tio.run/##y08uSSxL/f/fQaNCszq6SCc51jYtMy9Fo0I3Nz8lVUO7QsNKU1NTITpZpyi2ttqo9n@agq1CYl6xNVeaRrS6MgioWyuAGH4whjISI1bzPwA "Octave – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 41 bytes
```
s`(?=(.)+\1)(.*?¶)*(.*)(?!\1|¶).+
$.3,$#2
```
[Try it online!](https://tio.run/##K0otycxL/P@/OEHD3lZDT1M7xlBTQ0/L/tA2TS0gralhrxhjWAPk6WlzqegZ66goG/3/rwwCXEDsByaVoSQA "Retina 0.8.2 – Try It Online") 0-indexed. Explanation:
```
s`
```
Allow `.` to match newlines. This costs 3 bytes (3rd byte is the `?` before the `¶`) but saves 6 bytes.
```
(?=(.)+\1)
```
Look ahead for two identical characters. `\1` then becomes the hay.
```
(.*?¶)*
```
Count the number of newlines before the needle.
```
(.*)
```
Capture the hay to the left of the needle.
```
(?!\1|¶)
```
Ensure that the needle isn't hay or a newline.
```
.+
```
Match the rest of the hay so that the result replaces it.
```
$.3,$#2
```
Output the width of the left hay and the number of newlines.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 82 bytes
```
x=>w=>{int y=x.IndexOf(x.GroupBy(c=>c).Last(g=>g.Count()<2).Key);return(y%w,y/w);}
```
Thanks to dana for shaving off 6 bytes!
[Try it online!](https://tio.run/##bYvbCsIwDIbvfQpRhARmPaEMtxZRUETRS8ELQWo3uosqXcdWxGef9YCC84OEJP8XnrZ5Kst5pniYGi1V7D1nqYwHj@YKGYtoWVCWU3Z1e93SgizVSRTbCAqy0OfsMrXAKeNI1sfUQExZTGbnTBnAsI9kJSwGWphMK7Ct3LOdHINbGdR2WhqxlkpABI3mm03zSwNhiPgjHl5sDh@cNqhoyYtJ8sFpo4q2933fBf1K4O77vwGrMv6O7qXXdT/lHQ "C# (Visual C# Interactive Compiler) – Try It Online")
# Old solution, 106 bytes
```
n=>m=>{var z=n.Distinct();int d=n.IndexOf(n.Count(c=>c==z.First())>1?z.Last():z.First());return(d%m,d/m);}
```
Both take input as a string and an integer specifying the amount of columns.
[Try it online!](https://tio.run/##bYtdC4IwFIbv@xWRBBuYfVGIthUUQSB1GXghyNRY4Am2GWH02@2UkYQ9sPHynucVeiC0rLYFiIU2SsLJfmcJxiavDx/lPGMVMJ4zfr/GqlsycDZSGwnCEOqj0k2w2kGS3g4ZAWd9KcAQwbhgrHS2Umn0KB8vSyeIX9lrWl@lplBAkn5uJ8Oc@o/K7xyVNGkgISUZ6Vkf9lZDj5IZbn/FqGYffUFt2tLONavzF9TmLS10XRcPk9YB@/DvgbfxmoiT8Qg31RM "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), 74 bytes
```
h(char*s,z,x){for(s+=z--;*s==*--s|*s==s[-1];)z--;printf("%d,%d",z%x,z/x);}
```
[Try it online!](https://tio.run/##jZLbaoNAEEDf9ysWg7DaWeolinQx9AvyAQmxiDbV0JjgmiJav93uVhOwXug8LWfmzAzLRDT6DLOPtk1IlIS5zqGCUquPl5zwJ7@ilOnc93VK@bd88D01D0yT/JqnWXEkihqDGitQqSVUz6XGmhbLTpi/mfsD9nGtnH5DQXgYyul1hnf1DfubQffOVt85CIKxPg23/66cgw3DswvZ/UIrGWNdwO00Xs3ipXHrftzOG9uet6g6vepNqbtF1e3VzSPGLR6pl4Xc5j4Goa9LGuMz0errrZBjiGmIE0JI3BY@h2lGNFyjbouEiJMC0wNXE5chHNYxSzJ7yGywDHCGbA1rsIbIGSMXbAPkEqj7iPy9uOUZNhhq2h8 "C (clang) – Try It Online")
DEGOLF
```
int h(char*s,int z,int x){// z = string size, x = row size
 for(s+=z--;
 // move pointer just over the end of the string 
 // and move z counter to the end of string
*s-*--s?   ==>  *s==*--s|  @ceilingcat suggestion 
 // if the previous element is different we will check if the next element is also different
 // if not the result is 1 and the iteration continue
 // in the first iteration it will be different because the pointer is just  over the end
 *s-s[-1]? ==> changed to *s==s[-1]   @ceilingcat suggestion 
 // the second check returns 0 if the char changed again so it was the needle
 // if not it's because in the first iteration the first check finded a difference just because the pointer was just over the end
 /*0:1*/   :1;)z--;
 printf("%d,%d",z%x,z/x);
}
```
[Answer]
Java 8, 104 Bytes
```
(x,w)->{int i=0,p=x.length;for(;i<p;i++)if(x[i]!=x[(i+1)%p]&&x[i]!=x[(i+2)%p])break;return i/w+","+i%w;}
```
Input is array of char, and integer indicating row width.
Output is zero-based, vertical then horizontal (i.e., row number then column number)
Explanation:
```
(x,w)->{
    int i=0, p=x.length;
    for (;i<p;i++)          //iterate through characters in x
      if (x[i]!=x[(i+1)%p] && x[i]!=x[(i+2)%p])    //compare x[i] with the two subsequent characters in array, wrapping around if necessary
        break;
    return i/w+","+i%w;}  //return row number then column number, zero-based
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~93~~ ~~89~~ ~~85~~  58 bytes
Complete rewrite taking input as `concatenated string, width`:
```
lambda g,w:divmod(g.index({g.count(c):c for c in g}[1]),w)
```
[Try it online!](https://tio.run/##ZY9NCoMwEIXXzSmGdJMUEVPpRvAk1sWYtDFYE1FbK6Vnt7FYQfpgZuCbH940Y186G09Vep5uWBcKQQdDosyjdorp0Fh1ebKXDqW7255Jnki4uhYkGAv6nYmcBwOfShy7HmXVQQoZYTRaJeZEAzjxwHNELHygB8cZAA3/tF@qnxHxd0tEG/2uAd1ysTRyQmaL5WxxNZaQXdMa/0LFDiXn0wc "Python 3 – Try It Online")
---
Original answer:
```
def k(g):t=''.join(g);return divmod(t.index({t.count(c):c for c in t}[1]),len(g[0]))
```
EDIT: Saved 4 bytes by swapping linebreak/indent for semicolons. Saved another 4 bytes by using `divmod`(thanks @JonathanFrech).
[Try it online!](https://tio.run/##dU9BDoIwEDzbV2zwQJuQhsYbhpc0HGoLUtGWQDES49uRVjAcdC8zuzObybSjq605TJMqK2jwmWQuj2N6sdrMy7Er3dAZUPp@swo7qo0qH/jpqLSDcViSTEJlO5CgDbgXZwVJruX8ytOCEDTVYuydkE0POXDEIUr9RCjZMhZYkSBvECLcxOkDYoVFptsJWmD79bLY2I@YdBuT/jEwbygQ8qVqX@rbIEO7ttNz6QbXhExv "Python 3 – Try It Online")
I know this could be a lot shorter, but I just wanted to try an approach around this `dict` comprehension.
]