Official Ruby Inspector
Ruby 2.0, 69 bytes
#!ruby -Kn0rdigest
p'×ñF<ìX‚ɲŸ_'.index Digest::MD5.digest(gets)[0]
Hexdump (to faithfully show the binary data in the string):
00000000 23 21 72 75 62 79 20 2d 4b 6e 30 72 64 69 67 65 |#!ruby -Kn0rdige|
00000010 73 74 0a 70 27 d7 f1 46 3c 1f ec 58 82 c9 b2 9f |st.p'..F<..X....|
00000020 5f 02 27 2e 69 6e 64 65 78 20 44 69 67 65 73 74 |_.'.index Digest|
00000030 3a 3a 4d 44 35 2e 64 69 67 65 73 74 28 67 65 74 |::MD5.digest(get|
00000040 73 29 5b 30 5d |s)[0]|
Explanation:
- The
-Kn
option reads the source file asASCII-8BIT
(binary). - The
-0
option allowsgets
to read in the whole input (and not just one line). - The
-rdigest
option loads thedigest
module, which providesDigest::MD5
. - The code then does an MD5 of the input, takes the first byte of the digest, and gets its index in the given binary string.
CJam, 27 23 bytes
F7EC5ZV4DI8G6]qBb67%J%#
Convert base 11, take mod 67, take mod 19 of the result then find the index of what you have in the array
[15, 7, 14, 12, 5, 3, 0, 4, 13, 18, 8, 16, 6]
Magic!
Try it online.
Julia, 90 59 bytes
Definitely not the shortest, but the fair maiden Julia takes great care in the inspection of the royal rubies.
s->search(s[vec([18 10 16 24 25 26 19 11 9 15 32 34])],' ')
This creates a lambda function which accepts a string s
and returns the corresponding ruby defect number. To call it, give it a name, e.g. f=s->...
.
Ungolfed + explanation:
function f(s)
# Strings can be indexed like arrays, so we can define d to
# be a vector of indices corresponding to potential defect
# locations
d = vec([18 10 16 24 25 26 19 11 9 15 32 34])
# Check the specified locations for defects, returning the
# defect number as the index where a space was found and
# was not expected. If no spaces are found, 0 is returned.
search(s[d], ' ')
end
Examples:
julia> f(" ___
/\\ /\\
/_/ \\_\\
\\ \\_/ \/
\\/_\\/")
2
julia> f(" ___
/\\_/\\
/_/ \\_\\
\\ \\_/ \/
\\/_\\/")
0
Note that backslashes have to be escaped in the input. I confirmed with @Calvin'sHobbies that it's okay.
Let me know if you have any questions or suggestions!
Edit: Saved 31 bytes with help from Andrew Piliser!