# 从他的耳朵，手指和头部找到罪犯

17

• 他们的头长（`H`
• 他们的头宽（`B`
• 右耳的宽度（`E`
• 食指的长度（`F`

``````SH,LB,ME,SF
``````

``````!SH,LB,!ME,SF
``````

1. 输入：`SH,LB,ME,SF`
输出：`56`
2. 输入：`!SH,LB,!ME,SF`
输出：`58,60,61,63`
3. 输入：`SB,!MF,!LF`
输出：`1,2,3,4,5,6,7,8,9`
4. 输入：`MH,!MH`
输出：`0`

2014年

4

Level River St

1
@steveverrill我实际上是从数独模板制作的，所以有一个真相：o

6

## 红宝石1.9.3 - 173 157 143

``````x=(1..81).select{|j|\$*[0].split(?,).all?{|y|i=j-1
z='SML'
[z[i%9/3]+?H,z[i%3]+?E,z[i/27]+?B,z[i/9%3]+?F].member?(y[-2,2])^y[?!]}}
p x==[]?[0]:x``````

`select`是的缩写`find_all`。您可以通过替换`y[-2..-1]`为来修剪另外两个字符`y[-2,2]`，而使用`==[]`代替来修剪另外三个字符`.empty?`

@ThreeIfByWhiskey很棒的提示，谢谢！我已经编辑了答案。
Cristian Lupascu 2014年

2

# 斯卡拉-951

``````def m(a: List[Int]) = 0 to 8 flatMap (x => a map (_ + 9*x)) toSet
var SH = m(List(1,2,3))
var MH = m(List(4,5,6))
var LH = m(List(7,8,9))
var SE = m(List(1,4,7))
var ME = m(List(2,5,8))
var LE = m(List(3,6,9))
var SB = 1 to 27 toSet
var MB = 28 to 54 toSet
var LB = 55 to 81 toSet
def l(a: List[Int]) = 0 to 2 flatMap (x => a map (_+27*x)) toSet
var SF = l(1 to 9 toList)
var MF = l(10 to 18 toList)
var LF = l(19 to 27 toList)

var j = Map(("LH",LH),("MH",MH),("SH",SH),("LB",LB),("MB",MB),("SB",SB),("LF",LF),("MF",MF),("SF",SF),("LE",LE),("ME",ME),("SE",SE))

def f(x : String) = {
def h(i : List[String], k : Set[Int]) : Set[Int] = {
if(i isEmpty) k
else if(i.head.startsWith("!")) h(i.tail, k filterNot (j(i.head.replace("!","")) contains _))
else h(i.tail, k intersect j(i.head))
}
h(x split "," toList, 1 to 81 toSet) mkString ","
}
``````

`f("SH,LB,ME,SF")` = `56`

2

# T-SQL- 547 544

## 网格表设置-254

``````SELECT ROW_NUMBER()OVER(ORDER BY (SELECT \$))I,LEFT(Z,1)E,RIGHT(Z,1)H,LEFT(Y,1)F,RIGHT(Y,1)B INTO G FROM(VALUES('SS'),('MS'),('LS'),('SM'),('MM'),('LM'),('SL'),('ML'),('LL'))FB(Y),(VALUES('SS'),('MS'),('LS'),('SM'),('MM'),('LM'),('SL'),('ML'),('LL'))EH(Z)
``````

## 查询-293 290

``````DECLARE @S CHAR(400)='SELECT ISNULL(SUBSTRING(O,2,99),0)FROM (SELECT CONCAT('','',I)FROM G WHERE '+REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REVERSE(@i),',',' AND '),'S!','!S'),'M!','!M'),'L!','!L'),'S','=''S'''),'M','=''M'''),'L','=''L''')+' FOR XML PATH(''''))O(O)';EXEC(@S)
``````

``````DECLARE @I VARCHAR(50) = 'SB,!MF,!LF';
``````

``````DECLARE @S CHAR(400)='SELECT I FROM G WHERE '+REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REVERSE(@i),',',' AND '),'S!','!S'),'M!','!M'),'L!','!L'),'S','=''S'''),'M','=''M'''),'L','=''L''')
``````

1

# Mathematica 191 235

``````{"SH","LB","ME","SF"}
``````

“ SF”表示IndexFingerLength = 0（小）

“ SH”表示LengthOfHead = 0（小）

“ ME”表示WidthOfRightEar = 1（中）

`2001`以3为底的基数是10以55的底数。

## 码

``````c=Characters;t=Table[IntegerDigits[k,3,4],{k,0,80}];
f@i_:=1+FromDigits[#,3]&/@Intersection@@(Cases[t,#]&/@(ReplacePart[{_,_,_,_},{#}]&/@(c/@i
/.Thread[c@"BFHESML"-> {1,2,3,4,0,1,2}]/.{{"!",v_,n_}:> (n-> Except[v]),{v_Integer,n_}:> n-> v})))
/.{}:>0
``````

## 测试用例

``````f[{"SH","LB","ME","SF"}]
``````

{56}

``````f[{"!SH","LB","!ME","SF"}]
``````

{58，60，61，63}

``````f[{"SB","!MF","!LF"}]
``````

{1,2,3,4,5,6,7,8,9}

``````f[{"MH","!MH"}]
``````

0

1

# Python 3-192- 试试吧！

``````from itertools import*
S=input().split(',')
print([i+1for i in range(81)if eval('*'.join('(list(product(*["SML"]*4))[i][%d]%s="%s")'%('BFHE'.find(s[-1]),'!='[s[0]>'!'],s[-2])for s in S))]or 0)
``````

1

# Python 2-194

``````from itertools import*
n=map(set,['012']*4)
for x in raw_input().split(','):n['BFHE'.find(x[-1])]&=set(`'SML'.find(x[-2])`)^set('012'*(x<'"'))
print[1+int(''.join(x),3)for x in product(*n)]or[0]
``````

Falko的一些建议以及我本人的一些建议可以减少10个字符。

Bizangles 2014年

Bizangles 2014年

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.