计算机语言大战 [英] Computer Language Shootout

查看:57
本文介绍了计算机语言大战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们没有为一个程序提供Python实现,而且我们所做的几个Python程序显示错误。

http://shootout.alioth.debian.org/是... n& lang2 = python



程序。


请按照FAQ说明
http://shootout.alioth.debian.org/faq.php#contribute


祝福,艾萨克

We don''t have Python implementations for one program, and a
couple of the Python programs we do have show Error.

http://shootout.alioth.debian.org/be...n&lang2=python

Please contribute missing Python programs or faster more-elegant Python

programs.

Please follow the FAQ instructions
http://shootout.alioth.debian.org/faq.php#contribute

best wishes, Isaac

推荐答案

这是D代码的直接翻译,也许它不是更快的实现,而且肯定是'不是短的。但是Psyco

让它更快(Psyco喜欢低级风格代码)。

ShedSkink(几乎)能够编译它,产生一个非常快的

可执行文件(带有一些智能注意,这个SS版本仅变为

比给定n = 11的D版本慢17%(26.66秒而不是

PIII 500 MHz总运行时间22.70秒))。

! import sys



! def fannkuch(n):

! perm = [0] * n

! perm1 = range(n)

! count = [0] * n

! m = n - 1

! r = n

! maxFlipsCount = 0



!而真:

!而r!= 1:

!算[r-1] = r

! r - = 1



! #SS v.0.0.5这行有问题:

!如果不是(perm1 [0] == 0或perm1 [m] == m):

! #perm = list(perm1)

! #不产生记忆垃圾

! for x in xrange(n):

!烫发[i] = perm1 [i]



! i =烫发[0]

!翻转= 0

!而我:

! temp = perm [i]

!烫发[i] =我

!我= temp

! j = 1

! k = i - 1

!而j < k:

! temp =烫发[j]

!烫发[j] =烫发[k]

!烫发[k] = temp

! j + = 1

! k - = 1

!翻转+ = 1



!如果翻转> maxFlipsCount:

! maxFlipsCount =翻转



!而真:

!如果r == n:

!返回maxFlipsCount

! temp = perm1 [0]

!我= 0

!而我< r:

! j = i + 1

! perm1 [i] = perm1 [j]

!我= j

! perm1 [r] = temp



! count [r] - = 1

!如果计数[r]> 0:

!打破

! r + = 1





! #import psyco

! #psyco.bind(fannkuch)



!如果len(sys.argv)> 1:

! n = int(sys.argv [1])

!否则:

! n = 1

! printPfannkuchen(%d)=%ld %(n,fannkuch(n))

再见,

bearophile

This is a direct translation of the D code, maybe it''s not the faster
Python implementation, and surely it''s not the shorter one. But Psyco
makes it much faster (Psyco likes "low level" style code).
ShedSkink is (almost) able to compile it too, producing a really fast
executable (with some "smart attentions" this SS version becomes only
17% slower than the D version for a given n=11 (26.66 sec instead of
22.70 sec of total running time on a PIII 500 MHz)).
! import sys
!
! def fannkuch(n):
! perm = [0] * n
! perm1 = range(n)
! count = [0] * n
! m = n - 1
! r = n
! maxFlipsCount = 0
!
! while True:
! while r != 1:
! count[r-1] = r
! r -= 1
!
! # SS v.0.0.5 has a problem with this line:
! if not (perm1[0]==0 or perm1[m]==m):
! #perm = list(perm1)
! # to not produce memory garbage
! for i in xrange(n):
! perm[i] = perm1[i]
!
! i = perm[0]
! flips = 0
! while i:
! temp = perm[i]
! perm[i] = i
! i = temp
! j = 1
! k = i - 1
! while j < k:
! temp = perm[j]
! perm[j] = perm[k]
! perm[k] = temp
! j += 1
! k -= 1
! flips += 1
!
! if flips > maxFlipsCount:
! maxFlipsCount = flips
!
! while True:
! if r == n:
! return maxFlipsCount
! temp = perm1[0]
! i = 0
! while i < r:
! j = i + 1
! perm1[i] = perm1[j]
! i = j
! perm1[r] = temp
!
! count[r] -= 1
! if count[r] > 0:
! break
! r += 1
!
!
! #import psyco
! #psyco.bind(fannkuch)
!
! if len(sys.argv) > 1:
! n = int(sys.argv[1])
! else:
! n = 1
! print "Pfannkuchen(%d) = %ld" % (n, fannkuch(n))
Bye,
bearophile


我们不知道从新闻组中搜索节目,如果您希望在枪战中显示该节目,那么请将源代码附加到

跟踪器项目。


请按照FAQ说明
http://shootout.alioth.debian.org/faq.php#contribute
是************ @ lycos.com 写道:
We don''t scrape programs from news-groups, if you''d like the program to
be shown on the shootout then please attach the source code to a
tracker item.

Please follow the FAQ instructions
http://shootout.alioth.debian.org/faq.php#contribute
be************@lycos.com wrote:
这是D代码的直接翻译,也许就是'不是更快的Python实现,当然它不是更短的。但是Psyco让它变得更快(Psyco喜欢低级别样式代码)。
ShedSkink(几乎)能够编译它,产生一个非常快的可执行文件(带有一些 ;智能注意对于给定的n = 11(26.66秒而不是PZ 500 MHz上总运行时间的22.70秒),此SS版本仅比D版本慢17%。 br />
! import sys

! def fannkuch(n):
! perm = [0] * n
! perm1 =范围(n)
! count = [0] * n
! m = n - 1
! r = n
! maxFlipsCount = 0

!而真:
!而r!= 1:
!算[r-1] = r
! r - = 1

! #SS v.0.0.5有这个问题:
!如果不是(perm1 [0] == 0或perm1 [m] == m):
! #perm = list(perm1)
! #不产生记忆垃圾
!我在xrange(n):
!烫发[i] = perm1 [i]

! i =烫发[0]
!翻转= 0
!而我:
! temp =烫发[i]
!烫发[i] =我
!我= temp
! j = 1
! k = i - 1
!而j < k:
! temp =烫发[j]
!烫发[j] =烫发[k]
!烫发[k] = temp
! j + = 1
! k - = 1
!翻转+ = 1

!如果翻转> maxFlipsCount:
! maxFlipsCount =翻转

!而真:
!如果r == n:
!返回maxFlipsCount
! temp = perm1 [0]
!我= 0
!而我< r:
! j = i + 1
! perm1 [i] = perm1 [j]
!我= j
! perm1 [r] = temp

!算[r] - = 1
!如果计数[r]> 0:
!打破
! r + = 1


! #import psyco
! #psyco.bind(fannkuch)

!如果len(sys.argv)> 1:
! n = int(sys.argv [1])
!别的:
! n = 1
! printPfannkuchen(%d)=%ld %(n,fannkuch(n))

再见,
bearophile
This is a direct translation of the D code, maybe it''s not the faster
Python implementation, and surely it''s not the shorter one. But Psyco
makes it much faster (Psyco likes "low level" style code).
ShedSkink is (almost) able to compile it too, producing a really fast
executable (with some "smart attentions" this SS version becomes only
17% slower than the D version for a given n=11 (26.66 sec instead of
22.70 sec of total running time on a PIII 500 MHz)).
! import sys
!
! def fannkuch(n):
! perm = [0] * n
! perm1 = range(n)
! count = [0] * n
! m = n - 1
! r = n
! maxFlipsCount = 0
!
! while True:
! while r != 1:
! count[r-1] = r
! r -= 1
!
! # SS v.0.0.5 has a problem with this line:
! if not (perm1[0]==0 or perm1[m]==m):
! #perm = list(perm1)
! # to not produce memory garbage
! for i in xrange(n):
! perm[i] = perm1[i]
!
! i = perm[0]
! flips = 0
! while i:
! temp = perm[i]
! perm[i] = i
! i = temp
! j = 1
! k = i - 1
! while j < k:
! temp = perm[j]
! perm[j] = perm[k]
! perm[k] = temp
! j += 1
! k -= 1
! flips += 1
!
! if flips > maxFlipsCount:
! maxFlipsCount = flips
!
! while True:
! if r == n:
! return maxFlipsCount
! temp = perm1[0]
! i = 0
! while i < r:
! j = i + 1
! perm1[i] = perm1[j]
! i = j
! perm1[r] = temp
!
! count[r] -= 1
! if count[r] > 0:
! break
! r += 1
!
!
! #import psyco
! #psyco.bind(fannkuch)
!
! if len(sys.argv) > 1:
! n = int(sys.argv[1])
! else:
! n = 1
! print "Pfannkuchen(%d) = %ld" % (n, fannkuch(n))
Bye,
bearophile






11月29日2005年14:08:12 -0800, ig***@yahoo.com 写道:
On 29 Nov 2005 14:08:12 -0800, ig***@yahoo.com wrote:
我们不会从新闻组中搜集节目,如果您希望节目能够在枪战中显示,那么请将源代码附加到
跟踪器项目。
你问了什么,得到了回复,然后你傲慢地[1]宣布

它没有在你橱柜的特殊盘子上送达,

你不会屈服于刮服务到你自己的盘子上。

Pfui。你明显的[1]态度让我失望,更不用说你的顶级帖子。


在正常(和自愿的!)回复中使用你的_given_

__在您自己的请求的同一新闻组上下文中___不是b $ b来从新闻组中搜集程序。


[1]允许可能语言翻译困难导致

表达时出现意想不到的态度。


如果你还没准备好至少说谢谢拒绝之前

提供什么,请不要向新闻组志愿者索取任何内容。

他们应该更好地回应他们的慷慨。

请按照常见问题说明进行操作
http:// shootout.alioth.debian.org/faq.php#contribute



你所选择的主要短语(在第一个逗号之前)的影响之后也太晚了。


是******* *****@lycos.com写道:
We don''t scrape programs from news-groups, if you''d like the program to
be shown on the shootout then please attach the source code to a
tracker item. You asked for something, got a response, and then you haughtily[1] declare
that it''s not being served on a special platter from your cupboard,
and you won''t deign to "scrape" the serving onto your own platter.
Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.

Using what you are _given_ in a normal (and voluntary!) response
__within the same newsgroup context of your own request__ is not
to "scrape programs from news-groups".

[1] allowing for possible language translation difficulties resulting
in expressions with unintended attitudinal overtones.

If you are not prepared at least to say "thanks" before rejecting
what''s offered, please don''t ask for anything from newsgroup volunteers.
They deserve a better response to their generosity.

Please follow the FAQ instructions
http://shootout.alioth.debian.org/faq.php#contribute
That "please" is also too little too late, after the impact of
your chosen leading phrase (before the first comma).


be************@lycos.com wrote:
这是D代码的直接翻译,也许它不是更快的Python实现,当然它是'不是短的。但Psyco
This is a direct translation of the D code, maybe it''s not the faster
Python implementation, and surely it''s not the shorter one. But Psyco



看看top-posting如何解决问题?上面就是您回复的
。你的回复和我的回复(在你的部分内部插入你的部分,你的相关回应低于它的回应)这些都属于这里。 Double-pfui。


我最好吃。我注意到我有点太容易引起这种脾气暴躁;-)


问候,

Bengt Richter


See how top-posting screws things up? The immediately above is what you
responded to. Your response and mine (which is in parts interpolated into
yours below parts of yours the put relevant response below what it is
responding to) all belong down here. Double-pfui.

I better eat. I note that I was a bit too easily provoked into this grumpiness ;-)

Regards,
Bengt Richter


这篇关于计算机语言大战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆