92
14
This challenge was inspired by this Wendy's commercial from 1984.
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 ]
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 of1
,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.460Yes, 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.710Mmm I want someone to
0xFEED
me some0xDEAD 0xBEEF
– FireCubez – 2018-09-24T18:24:48.407