# 蜂箱的奇特生活

19

（蜂绘制由 灵光布泰维基共享资源。这个蜂窝和蜜蜂图像从而被下发布的 CC-BY-SA牢骚

• 如果一只蜜蜂的邻居少于两个，它会因孤独而死亡。
• 如果一只蜜蜂有三个以上的邻居，则会因拥挤而死亡。
• 如果一个小区在相邻小区中有两只，三只或四只活蜂，那么下一代会在那里孵化出一只新蜜蜂。

``````0
5
42
100
``````

``````6
44
1029
5296
``````

• 336 – C
• 363 – C
• 387 – C
• 389 –哈斯克尔
• 455 – C

• 230 –红宝石

Answers:

9

### 红宝石，181个163 153 146字符

``````h=[0]*4e4
[0,-200,201,202,2,3].map{|i|h[i]=1}
gets.to_i.times{h=h.map{[g=1,200,201].map{|x|g+=h[x]+h[-x]};g>5-h.rotate![-1]||g<3?0:1}}
p h.count 1
``````

7

## Python，152个字符

``````P=[0,2,3,1j,1+1j,1-1j]
for i in' '*input():Q=[p+d for d in(1,-1,1j,-1j,1j-1,1-1j)for p in P];P=set(p for p in Q if 1<Q.count(p)<5-(p in P))
print len(P)
``````

Python2.7设定了理解力
gnibbler 2011年

JulesOlléon2011年

Python2.7还设置了文字，因此您可以编写`P={0,2,3,1j,1+1j,1-1j}`然后用于`{p}<P`测试成员资格（节省1个字符）
gnibbler

5

## Python中，171 169 158个字符

``````w=300
s=w*w
x=[0]*297
h=[1,1,0]+x+[1,0,1,1]+x+[1]+x*s
exec('h=[1<sum(h[(i+x)%s]for x in[-1,-w-1,-w,1,w+1,w])<5-h[i]for i in range(s)];'*input())
print sum(h)
``````

``````w=300 # width and height of the world
s=w*w
# create initial grid
l=[1,1]+[0]*298+[1,0,1,1]+[0]*297+[1]+[0]*s

for k in range(input()):
h=l[:]

for i in range(s):

# for each point, compute the number of neighbors
n=sum(map(lambda x:h[(i+x)%s],[-1,-w-1,-w,1,w+1,w]))

# if that number verifies the conditions, put 1 here, if not put 0
l[i]=1<n<5-h[i]

print sum(l)
``````
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.