原文:http://www.javaeye.com/topic/600079
各种语言,各种算法,下面总结成python
#!/usr/bin/env python
def bl1(nums):
for i in xrange(1,len(nums) - 1):
if sum(nums[:i]) == sum(nums[i+1:]):
return i, nums[i]
return None
def bl2(nums):
total = sum(nums)
left = 0
for i in xrange(1,len(nums) - 1):
left += nums[i-1]
if (left == total - left - nums[i]):
return i, nums[i]
return None
def bl3(nums):
head_sum = 0
end_sum = 0
head = 0
end = len(nums) - 1
add_head = True
add_end = True
while head < end:
if add_head:
head_sum += nums[head]
if add_end:
end_sum += nums[end]
if head_sum < end_sum:
head += 1
add_head = True
add_end = False
elif head_sum > end_sum:
end -= 1
add_head = False
add_end = True
else:
head += 1
end -= 1
add_head = True
add_end = True
if head_sum == end_sum:
return head, nums[head]
else:
return None
test = [1,3,5,7,8,25,4,20]
print bl1(test)
print bl2(test)
print bl3(test) Copy Code
———–
post by gmail~
proxy65安装时报错:
exceptions.ImportError: No module named words.protocols.jabber
文档里只说python setup.py install就OK了
解决:
sudo apt-get install python-twisted
———–
post by gmail~
使用gsasl模拟smtp认证
gsasl -a username --service=smtp -m LOGIN --verbose -c smtp.sina.com 25
Trying `smtp.sina.com'...
220 irxd5-187.sinamail.sina.com.cn ESMTP
EHLO [127.0.0.1]
250-irxd5-187.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 83886080
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
EHLO [127.0.0.1]
250-irxd5-187.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 83886080
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
AUTH LOGIN
334 VXNlcm5hbWU6
eHh4eAo=
334 UGFzc3dvcmQ6
Enter password:
bGFuc2VkZWh1YQ==
235 #2.0.0 OK Authenticated
客户端认证完成(服务器可信)……
输入应用程序数据(用 EOF 结束输入):
^C
Copy Code
试了一下sina,163,qq,都只支持PLAIN LOGIN两种验证方式。。
———–
post by gmail~