Where's the 0xBEEF?

92

14

This challenge was inspired by this Wendy's commercial from 1984.

Where's the beef?

Illustration by T S Rogers

Your task is to find a hexadecimal 0xBEEF on a binary bun.

The 'beef' consists of the following pattern:

1 0 1 1  (0xB)
1 1 1 0  (0xE)
1 1 1 0  (0xE)
1 1 1 1  (0xF)

And the 'bun' consists of a 12x12 binary matrix, such as:

1 1 1 0 0 1 1 1 1 1 1 0
1 1 0 1 0 0 1 0 0 0 0 0
0 1 0 0 0 1 1 1 1 1 0 1
1 0 0 1 0 0 1 0 0 1 0 0
1 0 0 1 0 1 1 0 0 1 1 1
1 1 1 1 1 1 0 0 0 0 1 0
1 1 0 1 1 1 0 0 0 0 0 1
1 0 0 1 1 1 1 0 0 0 0 1
1 0 0 1 1 1 0 1 1 1 1 1
1 1 1 1 1 0 0 1 1 1 1 1
1 0 0 0 0 1 0 1 0 1 1 1
1 1 0 0 1 1 0 0 0 0 1 1

Input

Your program or function will take the binary matrix as input. The matrix format is very flexible, but it must be clearly described in your answer.

For instance:

  • a single binary string, with or without separators between the rows:

    "111001111110 110100100000..."

    or:

    "111001111110110100100000..."

  • an array of binary strings:

    ["111001111110", "110100100000", ...]

  • an array of numbers (each number describing a row once converted back to binary and left-padded with zeros):

    [3710, 3360, ...]

Output

The coordinates (X, Y) of the 'beef', (0, 0) being the top left corner of the bun.

Alternatively, you may use 1-based coordinates (but not a mix of both formats, like 0-based for X and 1-based for Y).

For the above example, the expected answer is (3, 4) (0-based) or (4, 5) (1-based):

   00 01 02 03 04 05 06 07 08 09 10 11 
00  1  1  1  0  0  1  1  1  1  1  1  0
01  1  1  0  1  0  0  1  0  0  0  0  0
02  0  1  0  0  0  1  1  1  1  1  0  1
03  1  0  0  1  0  0  1  0  0  1  0  0
04  1  0  0 [1  0  1  1] 0  0  1  1  1
05  1  1  1 [1  1  1  0] 0  0  0  1  0
06  1  1  0 [1  1  1  0] 0  0  0  0  1
07  1  0  0 [1  1  1  1] 0  0  0  0  1
08  1  0  0  1  1  1  0  1  1  1  1  1
09  1  1  1  1  1  0  0  1  1  1  1  1
10  1  0  0  0  0  1  0  1  0  1  1  1
11  1  1  0  0  1  1  0  0  0  0  1  1

Again, any reasonable format would work as long as it is specified in your answer. Please also mention if you're using 0-based or 1-based coordinates.

Rules

  • You can safely assume that there is always exactly one 'beef' on the bun. Your code is not required to support cases with more than one beef or no beef at all.
  • The beef pattern will always appear as described. It will never be rotated or mirrored in any way.
  • This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.

Test cases

In the following test cases, each row of the matrix is expressed as its decimal representation.

Input : [ 3710, 3360, 1149, 2340, 2407, 4034, 3521, 2529, 2527, 3999, 2135, 3267 ]
Output: [ 3, 4 ]

Input : [ 1222, 3107, 1508, 3997, 1906, 379, 2874, 2926, 1480, 1487, 3565, 633 ]
Output: [ 3, 7 ]

Input : [ 2796, 206, 148, 763, 429, 1274, 2170, 2495, 42, 1646, 363, 1145 ]
Output: [ 6, 4 ]

Input : [ 3486, 3502, 1882, 1886, 2003, 1442, 2383, 2808, 1416, 1923, 2613, 519 ]
Output: [ 1, 1 ]

Input : [ 3661, 2382, 2208, 1583, 1865, 3969, 2864, 3074, 475, 2382, 1838, 127 ]
Output: [ 8, 8 ]

Input : [ 361, 1275, 3304, 2878, 3733, 3833, 3971, 3405, 2886, 448, 3101, 22 ]
Output: [ 0, 3 ]

Input : [ 3674, 2852, 1571, 3582, 1402, 3331, 1741, 2678, 2076, 2685, 734, 261 ]
Output: [ 7, 7 ]

Arnauld

Posted 2016-10-23T15:53:55.743

Reputation: 111 334

Is using 1-based indices allowed (where the top left is (1,1))? – Doorknob – 2016-10-23T16:07:45.093

@Doorknob Yes, if it's the same format for both X and Y (question updated accordingly). – Arnauld – 2016-10-23T16:12:24.500

36Bonus points if we also output wether the 0xBEEF is 0xDEAD? :P – TuxCrafting – 2016-10-23T16:21:49.887

11This challenge is really random and kinda silly. But it's actually a pretty great challenge still. +1 – James – 2016-10-23T16:38:06.383

Can I output y, x (i.e. reverse order)? – Luis Mendo – 2016-10-23T22:31:05.697

@LuisMendo Yes, that's OK. – Arnauld – 2016-10-23T22:32:37.887

Can input be a "binary" matrix containing 1, -1 instead of 1, 0? – Luis Mendo – 2016-10-23T22:58:28.750

@LuisMendo No, I expect either numbers or some "standard binary" representation made of zeros and ones. – Arnauld – 2016-10-23T23:12:35.550

Can I return the output as a string, e.g., '34'? – Dennis – 2016-10-24T01:47:32.213

@Dennis - Yes. (Provided that it means (3, 4) and not the 34th position.) – Arnauld – 2016-10-24T06:21:40.460

Yes, that's what I had in mind. Thanks for clarifying. – Dennis – 2016-10-24T06:30:02.803

Is the "bun" always exactly 12x12? – JDL – 2016-10-24T13:50:48.433

@JDL Yes it is. – Arnauld – 2016-10-24T14:19:06.267

@DJMcMayhem: it is not really random : http://www.catb.org/jargon/html/D/DEADBEEF.html . see also : https://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_debug_values

– Olivier Dulac – 2016-10-25T12:12:15.710

Mmm I want someone to 0xFEED me some 0xDEAD 0xBEEF – FireCubez – 2018-09-24T18:24:48.407

Answers

30

Jelly, 20 17 16 bytes

ṡ€4ḄZw€“¿ÇÇБĖUṀ

Input is in form of a Boolean matrix, output is the 1-based index pair (Y, X).

Try it online! or verify all test cases.

How it works

ṡ€4ḄZw€“¿ÇÇБĖUṀ  Main link. Argument: M (2D array of Booleans)

ṡ€4               Split each row into 9 chunks of length 4.
   Ḅ              Convert these chunks from base 2 to integer.
    Z             Zip/transpose. This places the columns of generated integers
                  into the rows of the matrix to comb through them.
       “¿ÇÇБ     Push the array of code points (in Jelly's code page) of these
                  characters, i.e., 0xB, 0xE, 0xE, and 0xF.
     w€           Window-index each; in each row, find the index of the contiguous
                  subarray [0xB, 0xE, 0xE, 0xF] (0 if not found).
                  Since the matrix contains on one BEEF, this will yield an array
                  of zeroes, with a single non-zero Y at index X.
             Ė    Enumerate; prefix each integer with its index.
              U   Upend; reverse the pairs to brings the zeroes to the beginning.
               Ṁ  Take the maximum. This yields the only element with positive
                  first coordinate, i.e., the pair [Y, X].

Dennis

Posted 2016-10-23T15:53:55.743

Reputation: 196 637

15I don't get it... how can you code something that is not human readable?? – L3n – 2016-10-23T17:46:01.963

13Jelly is by far easier to write than to read. :P – Dennis – 2016-10-23T18:54:43.990

46@l3n you seem to imply that Dennis is a human. While it is a possibility, given the kind of tricks that routinely pulls out, I wouldn't discount other ... let's say, more cyberpunk alternatives ;-) – Francesco – 2016-10-23T19:36:01.710

1You could output (x,y) with ṡ4Z€Ḅw€“Ье‘ĖUṀ – Jonathan Allan – 2016-10-24T02:04:56.283

2@JonathanAllan Nice. There's also ṡ€4ḄZjw“¿ÇÇБ’d24 with 0-based indexing, but it is, unfortunately, one byte longer. – Dennis – 2016-10-24T02:10:18.540

This is 16 characters, but 35 bytes (in UTF-8). – Useless – 2016-10-27T14:11:21.160

1@Useless The bytes link in the header points to Jelly's code page, which encodes each of the 256 characters it understands as a single byte. – Dennis – 2016-10-27T14:48:37.707

Very ingenious! – Useless – 2016-10-27T15:22:21.803

40

vim, 126 80 77 76

/\v1011\_.{9}(1110\_.{9}){2}1111<cr>:exe'norm Go'.join(getpos('.'))<cr>xxdawhPXXd{

Expects input in the form

111001111110
110100100000
010001111101
100100100100
100101100111
111111000010
110111000001
100111100001
100111011111
111110011111
100001010111
110011000011

And outputs (with 1-based indices) as

4 5
/                      regex search for...
\v                     enable "very magic" mode (less escaping)
1011\_.{9}             find the first line ("B"), followed by 8 chars + 1 \n
(1110\_.{9}){2}        find the second and third lines ("EE")
1111<cr>               find the fourth line ("F")
:exe'norm Go'.         insert at the beginning of the file...
join(getpos('.'))<cr>  the current position of the cursor
xxdawhPXX              do some finagling to put the numbers in the right order
d{                     delete the input

Thanks to Jörg Hülsermann for indirectly saving 46 bytes by making me realize my regex was super dumb, and to DJMcMayhem for 3 more bytes.

Doorknob

Posted 2016-10-23T15:53:55.743

Reputation: 68 138

1A couple tips: 1) Yp is better than yyp (even though I know you object to Y :P) 2) the whitespace in exec 'norm Go' is unnecessary. And 3) kd{ is shorter than kdgg. (Haven't tested that though) – James – 2016-10-23T17:02:25.487

1@DJMcMayhem Oh, I always forget about Y because I have it rebound in my vimrc. :P In fact, the kdgg was equivalent to just d{, which, surprisingly, does not delete the current line. – Doorknob – 2016-10-23T17:21:42.990

Oh interesting. How convenient! – James – 2016-10-23T17:39:50.053

I'm always confused when things such as { turn out to be a character movement; so I have do something like {d'' instead to delete whole lines. – Neil – 2016-10-23T17:40:31.280

@Neil You could do dV{ instead – James – 2016-10-23T20:29:28.457

@DJMcMayhem I learned vi in the old days, so I'm not used to all these new options such as visual mode! – Neil – 2016-10-23T23:03:23.017

While you actually encoded B your comment says D. – Loren Pechtel – 2016-10-24T05:05:08.773

@LorenPechtel Whoops, thanks for pointing that out. – Doorknob – 2016-10-24T20:26:32.010

1You could use echo instead of printing into the buffer, I don't think there's anything preventing this in the challenge. That would shave off around 10 bytes. – Christian Rondeau – 2016-10-25T13:01:29.750

22

JavaScript (ES6), 63 60 56 bytes

s=>[(i=s.search(/1011.{9}(1110.{9}){2}1111/))%13,i/13|0]

Takes input as a 155-character space-delimited string of 12 12-digit binary strings, returns zero-indexed values. Edit: Saved 3 bytes thanks to @JörgHülsermann. Saved 4 bytes thanks to @ETHproductions.

Neil

Posted 2016-10-23T15:53:55.743

Reputation: 95 035

Could you possibly use s.search(r) instead of r.exec(s).index? – ETHproductions – 2016-10-24T02:39:21.510

1@ETHproductions Of course I could. I must have been half asleep yesterday... – Neil – 2016-10-24T07:32:52.693

For me, using nodejs to execute, it is not working unless i change s=>[ to (s,i)=>[, because you need to define i somewhere :/ – Mijago – 2016-10-25T19:37:17.717

@Mijago Odd, it worked in Node 4 when I tried it (I normally use the Spidermonkey JS shell). Mind you a typo had crept into the code so some good came out of it! – Neil – 2016-10-25T20:38:50.980

I think this fails for 000010110010110011100011100011100011100011110011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 – Taemyr – 2016-10-26T08:41:42.077

@Taemyr Actually it works for your case but if fails if I change the first 1 to a 0, so I fixed my code (fortunately that didn't cost me any bytes). – Neil – 2016-10-26T10:49:01.923

@Neil I am happy my last comment on the Retina solution got in before your fix. – Taemyr – 2016-10-26T10:50:06.807

@Neil It was my "use static"; i use everywhere which forces me to define every variable. Mystery solved! – Mijago – 2016-11-03T08:37:10.343

14

C, 146 177 173 163 bytes

Thanks to Numberknot for fixing the code (shifting the lower three rows).

Saving 4 bytes by replacing >>=1 with /=2 in 4 places. Saving 10 more bytes by letting x and y be global and default int thanks to MD XF

#define T(i,n)(A[y+i]&15)==n
x,y;b(int A[12]){for(x=9;x--;){for(y=0;++y<9;A[y]/=2)if(T(0,11)&&T(1,14)&&T(2,14)&&T(3,15))return(x<<4)+y;A[9]/=2;A[10]/=2;A[11]/=2;}}

Ungolfed:

int b(int A[12]) {
 for (int x=8; x>=0; --x) {
  for (int y=0; y<9; ++y) {
   if ((A[y]&15)==11 && (A[y+1]&15)==14 && (A[y+2]&15)==14 && (A[y+3]&15)==15) { 
    return (x<<4) + y; 
   }
   A[y]/=2;
  }
  A[9]/=2; A[10]/=2; A[11]/=2;
 }
}

Returns x,y (0-based) in the high and low nibble of a byte.

Usage:

int temp=b(array_to_solve);
int x=temp>>4;
int y=temp&15;
printf("%d %d\n",x,y);

Karl Napf

Posted 2016-10-23T15:53:55.743

Reputation: 4 131

1you can change your define to #define T(i,n)if((A[y+i]&15)==n) and the if section to T(0,11)T(1,14)T(2,14)T(3,15)return to save 6 bytes. Also change the function signature to int b(int*A) to 4 more bytes saved. – Lince Assassino – 2016-11-01T13:27:10.383

163 bytes – MD XF – 2018-01-19T04:02:46.670

9

MATL, 22 21 bytes

Eq[ODDH]B~EqZ+16=&fhq

Input is a binary matrix, with ; as row separator. Output is 1-based in reverse order: Y X.

Try it online! Or verify all test cases with decimal input format.

Explanation

The pattern is detected using 2D convolution. For this,

  • The matrix and the pattern need to be in bipolar form, that is, 1, -1 instead of 1, 0. Since the pattern has size 4×4, its occurrence is detected by an entry equal to 16 in the convolution output.
  • The convolution kernel needs to be defined as the sought pattern reversed in both dimensions.

Also, since the convolution introduces an offset in the detected indices, this needs to be corrected for in the output.

Eq      % Implicitly input binary matrix. Convert to bipolar form (0 becomes -1)
[ODDH]  % Push array [0 8 8 2]
B       % Convert to binary. Each number gives a row
~Eq     % Negate and convert to bipolar. Gives [1 1 1 1; 0 1 1 1; 0 1 1 1; 1 1 0 1]
        % This is the "BEEF" pattern reversed in the two dimensions. Reversal is
        % needed because a convolution will be used to detect that patter
Z+      % 2D convolution, keeping original size
16=&f   % Find row and column indices of 16 in the above matrix
h       % Concatenate horizontally
q       % Subtract 1. Implicitly display

Luis Mendo

Posted 2016-10-23T15:53:55.743

Reputation: 87 464

8

Mathematica, 62 bytes

BlockMap[Fold[#+##&,Join@@#]==48879&,#,{4,4},1]~Position~True&

Returns all positions of the BEEF matrix, 1-indexed. The input must be a matrix of binary digits. The x and y in the output are switched, though.

JungHwan Min

Posted 2016-10-23T15:53:55.743

Reputation: 13 290

No worries about x and y being switched. – Arnauld – 2016-10-23T22:33:13.993

7

PHP, 87 Bytes

binary string as input without separators, returns zero-indexed values.

preg_match("#1011(.{8}1110){2}.{8}1111#",$argv[1],$c,256);echo($s=$c[0][1])%12,$s/12^0;

array of numbers as input 128 Bytes

<?foreach($_GET[a]as$a)$b.=sprintf("%012b",$a);preg_match("#1011(.{8}1110){2}.{8}1111#",$b,$c,256);echo($s=$c[0][1])%12,$s/12^0;

14 Bytes saved by @Titus Thank You

Jörg Hülsermann

Posted 2016-10-23T15:53:55.743

Reputation: 13 026

Use , instead of . in the echo and you can remove the parentheses. (-4) – Titus – 2016-10-30T20:13:47.180

In the comments, Arnauld allows output without a delimiter. (-4) – Titus – 2016-10-30T20:20:29.100

Use flag PREG_OFFSET_CAPTURE: append ,256 to the preg_match parameters, remove ^(.*) from the regex, $c[0][1] instead of strlen($c[1]) (-6) – Titus – 2016-10-30T20:44:46.057

@Titus nice and done – Jörg Hülsermann – 2016-10-30T20:58:34.737

7

Slip, 28 bytes

27 bytes of code, +1 for p option.

(?|1011)(\(?|1110)){2}\1111

Requires input as a multiline rectangle of 1's and 0's without spaces. Try it here (with third testcase as input).

Explanation

Slip is a language from the 2-D Pattern Matching challenge. Sp3000 could say a lot more about it than I can, but basically it's an extended form of regex with some directional commands that let you match in two dimensions. The above code uses the eponymous "slip" command \, which doesn't change the match pointer's direction but moves it sideways by one character. It also uses "stationary group" (?|...), which matches something and then resets the pointer to its previous location.

The code breaks down as follows:

(?|1011)                     Match 1011; reset pointer to beginning of match
        (         ){2}       Do the following twice:
         \                     Slip (moves pointer down one row)
          (?|1110)             Match 1110; reset pointer to beginning of match
                      \1111  Slip and match 1111

This matches the 0xBEEF square. The p option outputs the coordinates of the match, 0-indexed.

DLosc

Posted 2016-10-23T15:53:55.743

Reputation: 21 213

1Nice :) Weirdly, for block patterns sometimes it's golfier to just walk around in a spiral: 1011>001>1(11>){3}1>1 – Sp3000 – 2016-10-24T23:00:06.063

@Sp3000 Ha! Spiral was the shortest method in SnakeEx, but I didn't think of trying it in Slip. Really nice trick with the 1(11>){3}. – DLosc – 2016-10-25T19:48:27.207

5

Java 7,182 177 bytes

I ported Karl Napf C answer to JAVA And Thanks to Karl Napf for saving 5 bytes by reminding me Bit magic.(Btw i came up with this idea too but @KarlNapf return part idea was yours not mine).Sorry if i displeased you.

(0-based)

int f(int[]a){int x=9,y,z=0;for(;x-->0;){for(y=0;y<9;a[y++]/=2) if((a[y]&15)==11&(a[y+1]&15)==14&(a[y+2]&15)==14&(a[y+3]&15)==15)z=(x<<4)+y;a[y]/=2;a[10]/=2;a[11]/=2;}return z;}

Ungolfed

class Beef {

    public static void main(String[] args) {
        int x = f(new int[] { 1222, 3107, 1508, 3997, 1906, 379, 2874, 2926, 1480, 1487, 3565, 633 });
        System.out.println(x >> 4);
        System.out.println(x & 15);
    }

    static int f(int[] a) {
        int x = 9,
            y,
            z = 0;

        for (; x-- > 0; ) {
            for (y = 0; y < 9; a[y++] /= 2)
                if ((a[y] & 15) == 11 
                  & (a[y + 1] & 15) == 14
                  & (a[y + 2] & 15) == 14 
                  & (a[y + 3] & 15) == 15)
                    z = (x << 4) + y;

            a[y] /= 2;
            a[10] /= 2;
            a[11] /= 2;
        }
        return z;
    }

}

Numberknot

Posted 2016-10-23T15:53:55.743

Reputation: 885

2What are those four spaces there between a[y++]>>=1) and if((a[y]&15)==. Btw, I count 182 bytes instead of 183? :S – Kevin Cruijssen – 2016-10-24T07:23:53.113

@KevinCruijssen fixed . – Numberknot – 2016-10-24T07:29:17.910

1Everything alright ;-) – Karl Napf – 2016-10-24T15:34:40.560

1You can still remove the space between ...a[y++]/=2) and if((a[y]&15)==.... – Kevin Cruijssen – 2017-06-29T11:47:54.490

5

Retina, 47 bytes

I'd like to preface this with an apology. I think this is probably terrible and a bad example of how to use the language, but since I used a Regex for my Perl answer, I thought I'd try Retina. I'm not very good. :( The snippets on github helped me greatly though!

Thanks to @wullzx for his comment on my Perl answer for -3 bytes and to @Taemyr for pointing out an issue with my method!

Expects input as a space-separated binary string and outputs co-ordinates space separated.

(.{13})*(.)*1011(.{9}1110){2}.{9}1111.*
$#2 $#1

Try it online!

Verify all tests at once.

Dom Hastings

Posted 2016-10-23T15:53:55.743

Reputation: 16 415

1Fails for '000010110010110011100011100011100011100011110011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' Your (.)* needs to be (.){0,8} – Taemyr – 2016-10-26T08:41:03.500

Is this countered by You can safely assume that there is always exactly one 'beef' on the bun. Your code is not required to support cases with more than one beef or no beef at all.? It can be resolved with ungreedy modifiers if necessary though (.{12})*?(.)*?. – Dom Hastings – 2016-10-26T09:50:00.337

1Look again, there is only one beef in that input - and it's not at the point where your program indicates. The problem would not be resolved by using eager modifers, since I can switch the fake beef with the real beef. the problem is that your regex matches a "beef" that starts less than 4 bits from the end of a matrix row. – Taemyr – 2016-10-26T10:36:59.080

You could also resolve this by changing the {8}'s to {9} and asking for the lines in the input to be space seperated, for a zero byte cost fix. – Taemyr – 2016-10-26T10:46:19.917

@Taemyr Ahhh! I see! I misunderstood your point... You are indeed correct. My Perl solution potentially falls foul of this as well. Will get that changed ASAP. Thank you for your comments and suggestion! – Dom Hastings – 2016-10-26T11:31:15.013

4

Scala, 90 bytes

("1011.{8}(1110.{8}){2}1111".r.findAllMatchIn(_:String).next.start)andThen(i=>(i/12,i%12))

Explanation:

(
  "1011.{8}(1110.{8}){2}1111" //The regex we're using to find the beef
  .r                          //as a regex object
  .findAllMatchIn(_:String)   //find all the matches in the argument thats going to be passed here
  .next                       //get the first one
  .start                      //get its start index
)                             //this is a (String -> Int) function
andThen                       //
(i=>                          //with the found index
  (i/12,i%12)                 //convert it to 2d values
)                             

(a -> b) andThen (b -> c) results in a (a -> c) function, it's like the reverse of compose, but requires fewer type annotations in scala. In this case, it takes a string of the binary digits as input and returns a tuple of zero-based indices.

corvus_192

Posted 2016-10-23T15:53:55.743

Reputation: 1 889

4

Python 2, 98 95 92 bytes

lambda x:'%x'%(`[''.join('%x'%int(s[i:i+4],2)for s in x)for i in range(9)]`.find('beef')+15)

Input is a list of strings, output is the string XY (1-based indices).

Test it on Ideone.

Dennis

Posted 2016-10-23T15:53:55.743

Reputation: 196 637

Might this mistakenly find a "beef" across the boundary where two lines are concatenated? – xnor – 2016-10-24T23:59:00.493

Yeah, I think so. I'll roll the edit back until I can test it properly. – Dennis – 2016-10-25T00:01:34.037

2That's what happens when you use a toroidal bun. – mbomb007 – 2016-10-27T13:46:30.070

4

Perl, 54 bytes

53 bytes code + 1 for -n. Uses -E at no extra cost.

Uses 0-based indices. Expects input as a string of 1s and 0s and outputs space separated co-ordinates.

Thanks to @wullxz and @GabrielBenamy for helping me save 9 bytes, and to @Taemyr's comment on my Retina answer for pointing out an issue!

/1011.{9}(1110.{9}){2}1111/;say$-[0]%13,$",$-[0]/13|0

Usage

perl -nE '/1011.{9}(1110.{9}){2}1111/;say$-[0]%13,$",$-[0]/13|0' <<< '111001111110 110100100000 010001111101 100100100100 100101100111 111111000010 110111000001 100111100001 100111011111 111110011111 100001010111 110011000011
010011000110 110000100011 010111100100 111110011101 011101110010 000101111011 101100111010 101101101110 010111001000 010111001111 110111101101 001001111001
101011101100 000011001110 000010010100 001011111011 000110101101 010011111010 100001111010 100110111111 000000101010 011001101110 000101101011 010001111001
110110011110 110110101110 011101011010 011101011110 011111010011 010110100010 100101001111 101011111000 010110001000 011110000011 101000110101 001000000111
111001001101 100101001110 100010100000 011000101111 011101001001 111110000001 101100110000 110000000010 000111011011 100101001110 011100101110 000001111111
000101101001 010011111011 110011101000 101100111110 111010010101 111011111001 111110000011 110101001101 101101000110 000111000000 110000011101 000000010110
111001011010 101100100100 011000100011 110111111110 010101111010 110100000011 011011001101 101001110110 100000011100 101001111101 001011011110 000100000101'
3 4
3 7
6 4
1 1
8 8
0 3
7 7

Dom Hastings

Posted 2016-10-23T15:53:55.743

Reputation: 16 415

1You can save 3 characters by combining the regex for the binary EE: (.{8}1110){2} instead of .{8}1110.{8}1110 – wullxz – 2016-10-24T13:01:32.870

1You can also save another 3 bytes by changing length$\`` into$-[0]` – Gabriel Benamy – 2016-10-24T17:49:42.327

@wullxz Of course! I tried \1 but had no luck, didn't think to try {2}! Thanks! – Dom Hastings – 2016-10-25T07:01:32.060

@GabrielBenamy Amazing, thank you very much! Updated! – Dom Hastings – 2016-10-25T07:01:45.970

@GabrielBenamy What does $-[0] do? – User112638726 – 2016-10-25T08:07:59.000

2

@User112638726 "$-[0] is the offset of the start of the last successful match. $-[n] is the offset of the start of the substring matched by n-th subpattern, or undef if the subpattern did not match." from: http://perldoc.perl.org/perlvar.html (look for @-)

– Dom Hastings – 2016-10-25T08:16:59.963

@DomHastings Thanks! I'll have a look – User112638726 – 2016-10-25T08:42:06.330

4

J, 31 29 bytes

[:($#:I.@,)48879=4 4#.@,;._3]

The input is formatted as a 2d array of binary values, and the output is the zero-based coordinates as an array [y, x].

The flattening and base conversion to find the index is something I learned from this comment by Dennis.

Usage

   f =: [:($#:I.@,)48879=4 4#.@,;._3]
   ] m =: _12 ]\ 1 1 1 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1
1 1 1 0 0 1 1 1 1 1 1 0
1 1 0 1 0 0 1 0 0 0 0 0
0 1 0 0 0 1 1 1 1 1 0 1
1 0 0 1 0 0 1 0 0 1 0 0
1 0 0 1 0 1 1 0 0 1 1 1
1 1 1 1 1 1 0 0 0 0 1 0
1 1 0 1 1 1 0 0 0 0 0 1
1 0 0 1 1 1 1 0 0 0 0 1
1 0 0 1 1 1 0 1 1 1 1 1
1 1 1 1 1 0 0 1 1 1 1 1
1 0 0 0 0 1 0 1 0 1 1 1
1 1 0 0 1 1 0 0 0 0 1 1
   f m
4 3
   f (#:~2#~#) 3710 3360 1149 2340 2407 4034 3521 2529 2527 3999 2135 3267
4 3
   f (#:~2#~#) 1222 3107 1508 3997 1906 379 2874 2926 1480 1487 3565 633
7 3
   f (#:~2#~#) 2796 206 148 763 429 1274 2170 2495 42 1646 363 1145
4 6
   f (#:~2#~#) 3486 3502 1882 1886 2003 1442 2383 2808 1416 1923 2613 519
1 1
   f (#:~2#~#) 3661 2382 2208 1583 1865 3969 2864 3074 475 2382 1838 127
8 8
   f (#:~2#~#) 361 1275 3304 2878 3733 3833 3971 3405 2886 448 3101 22
3 0
   f (#:~2#~#) 3674 2852 1571 3582 1402 3331 1741 2678 2076 2685 734 261
7 7

Explanation

[:($#:I.@,)48879=4 4#.@,;._3]  Input: 2d array M
                            ]  Identity. Get M
                 4 4    ;._3   For each 4x4 subarray of M
                       ,         Flatten it
                    #.@          Convert it to decimal from binary
           48879=              Test if equal to 48879 (decimal value of beef)
[:(       )                    Operate on the resulting array
         ,                       Flatten it
      I.@                        Find the indices where true
    #:                           Convert from decimal to radix based on
   $                               The shape of that array
                               Returns the result as coordinates [y, x]

miles

Posted 2016-10-23T15:53:55.743

Reputation: 15 654

1

Scala, 318 Bytes

This solution could be further improved... but I kept it readable and allowed for the input to be the multi-line spaced matrix.

Actual Solution if Array of binary String

def has(s: String, t: String): Int = s.indexOf(t)
val beef = List("1011", "1110", "1110", "1111")
l.zipWithIndex.map{case(e,i)=>l.drop(i).take(4)}.map{_.zip(beef)}.map{_.collect{case e=>has(e._1,e._2)}}.zipWithIndex.filterNot{e => e._1.contains(-1) ||  e._1.distinct.length > 1}.map{e=>s"(${e._1.head},${e._2})"}.head

Sample Working

val bun = 
"""1 1 1 0 0 1 1 1 1 1 1 0
1 1 0 1 0 0 1 0 0 0 0 0
0 1 0 0 0 1 1 1 1 1 0 1
1 0 0 1 0 0 1 0 0 1 0 0
1 0 0 1 0 1 1 0 0 1 1 1
1 1 1 1 1 1 0 0 0 0 1 0
1 1 0 1 1 1 0 0 0 0 0 1
1 0 0 1 1 1 1 0 0 0 0 1
1 0 0 1 1 1 0 1 1 1 1 1
1 1 1 1 1 0 0 1 1 1 1 1
1 0 0 0 0 1 0 1 0 1 1 1
1 1 0 0 1 1 0 0 0 0 1 1
""".replaceAll(" ","")
def has(s: String, t: String): Int = s.indexOf(t)
val beef = List("1011", "1110", "1110", "1111")
val l = bun.split("\n").toList
l.zipWithIndex.map{case(e,i)=>l.drop(i).take(4)}
.map{_.zip(beef)}
.map{_.collect{case e=>has(e._1,e._2)}}.zipWithIndex
.filterNot{e => e._1.contains(-1) ||  e._1.distinct.length > 1}
.map{e=>s"(${e._1.head},${e._2})"}.head

Trevor Sibanda

Posted 2016-10-23T15:53:55.743

Reputation: 31

1

Ruby, 62 bytes

def f(a);a=~/1011(.{8}1110){2}.{8}1111/;$`.size.divmod(12);end 

It expects a string of 0 and 1 and returns an array of Y and X, zero-based.

Try at ideone.

undur_gongor

Posted 2016-10-23T15:53:55.743

Reputation: 191

1

Python, 137 bytes (according to Linux (thanks ElPedro))

def f(s,q=0):import re
 i=s.index(re.findall('1011.{8}1110.{8}1110.{8}1111',s)[q])+1
 x=i%12
 y=(i-x)/12
 if x>8:x,y=f(s,q+1)
 return x,y

Not exactly a competitive bytecount, but the algorithm is a bit interesting. Takes input as a string of binary values.

penalosa

Posted 2016-10-23T15:53:55.743

Reputation: 505

If you sue single spaces instead of 4 and check it on Linux it's 137 – ElPedro – 2016-10-24T18:42:39.630

1I think you need a newline and space before the import (I get an IndentError in Python 2 without it) which costs 2 bytes but you can then put i=..., x=... and y=... on the same line as and separate with ; to lose 1 byte for 136 – ElPedro – 2016-10-24T18:59:39.180

@elpedro I'm using Python 3, and it's fine with the import being on the same line. – penalosa – 2016-10-24T19:02:34.363

Fully understood :) – ElPedro – 2016-10-24T19:03:10.957

Jeez, just reread my comments and I'm making so many typos tonight. Good thing I'm not trying to write any code... – ElPedro – 2016-10-24T19:09:00.843

1

Dyalog APL, 29 27 bytes

Takes a 12x12 binary array as user input and returns the coordinates in reverse order, the indexes start at 1.

Thanks to @Adám for saving many bytes. -2 Bytes because I'm dumb and left everything in a function for no reason.

0~⍨∊{⍵×⍳⍴⍵}⎕⍷⍨~0 8 0 6⊤⍨4/2

Zacharý

Posted 2016-10-23T15:53:55.743

Reputation: 5 710

Save 2 by replacing ~2 8 12∊⍨4 4⍴⍳16 with 15 7 15 9⊤⍨4/2. Note that 0~⍨∊{⍵×⍳⍴⍵} can be replaced with from version 16.0 (your code only works in Dyalog APL). – Adám – 2016-10-26T13:23:51.360

Yeah, Dyalog has characters that differ from GNU. Or is it something else? – Zacharý – 2016-10-26T21:56:26.233

Well, is being added from v16, I've been unable to find a list of GNUAPL primitives. – Adám – 2016-10-26T22:59:41.297

I've got GNU APL running, it's mostly just codepoint differences. – Zacharý – 2016-10-26T23:08:40.133

From what I've noticed. – Zacharý – 2016-10-26T23:13:09.337

⍸⎕⍷⍨15 7 15 9⊤⍨4/2 – Adám – 2016-10-27T00:41:55.060

Does ⍸ work in GNU APL? – Adám – 2016-10-27T00:42:12.413

No, and what does that index char do? – Zacharý – 2016-10-27T11:07:30.647

ISn't that evaluated input? – Zacharý – 2016-10-27T11:08:15.510

From Dyalog APL version 16, is {⍵/⍳⍴⍵}, i.e. the indices of the ones in a Boolean vector. – Adám – 2016-10-27T13:58:41.873

is indeed evaluated input. This allows the user to directly enter a matrix 12 12⍴... or enter the name of a predefined variable containing the data. The entire line is the body of a tradfn. – Adám – 2016-10-27T13:59:36.547

This whole sequence of exchanges somehow led me to believe v16 was released. Wow, I was just dumb. – Zacharý – 2017-04-16T20:36:59.833

1

F# - 260 bytes

Full program, including the required EntryPoint designator (so count fewer if you wish I suppose).

Input: each row as separate string: "111001111110" "110100100000" "010001111101" "100100100100" "100101100111" "111111000010" "110111000001" "100111100001" "100111011111" "111110011111" "100001010111" "110011000011"

Code:

[<EntryPoint>]
let main a=
 let rec f r:int=
  let b=a.[r].IndexOf"1011"
  if(b>0)then if(a.[r+1].[b..b+3].Equals"1110"&&a.[r+2].[b..b+3].Equals"1110"&&a.[r+3].[b..b+3].Equals"1111")then r else f(r+1)
  else f(r+1)
 printfn"%d%d"(a.[f 0].IndexOf"1011")(f 0);0

Not the most elegant solution most likely, but i wanted to keep with strings, so this is how i did it. I almost got it to be a single line and smaller using pipes, but there is something with the double if block that was getting me that i couldn't resolve. So oh well!

I thought too about porting Karl's answer into F# as it's a good one, and may still do that for fun as another approach, but wanted to stick with this one to be different.

magumbasauce

Posted 2016-10-23T15:53:55.743

Reputation: 21

0

Element, 130 bytes

_144'{)"1-+2:';}144'["1-+19:~?1+~?!2+~?3+~?12+~?13+~?14+~?15+~?!24+~?25+~?26+~?27+~?!36+~?37+~?38+~?39+~?16'[&][12%2:`\ `-+12/`]']

Try it online!

Takes input as one long string of 1s and 0s without any delimiters. Outputs like 3 4 (0-based indexing).

This works by placing the input data into an "array" (basically a dictionary with integer keys) and then, for each possible starting value, tests the bits at particular offsets (all 16 of them in a very laborious process).

PhiNotPi

Posted 2016-10-23T15:53:55.743

Reputation: 26 739