最短素数计划 [英] Shortest prime number program
问题描述
我认为那里有人必须写一个最小代码大小的原始
数字生成器。经过一段时间的搜索,我找不到一个。
对于高达100的素数,我能做的最好是70个字符(包括
空格):
r =范围(2,99)
m = [x为y,r为r,y为r]
[x代表x in r如果不是x in m]
I figured someone out there must have written a minimal code size prime
number generator. I did not find one after a bit of searching around.
For primes up to 100 the best I could do was 70 characters (including
spaces):
r=range(2,99)
m=[x*y for x in r for y in r]
[x for x in r if not x in m]
推荐答案
swisscheese写道:
swisscheese wrote:
我认为有人必须有写了一个最小代码大小的数字生成器。经过一段时间的搜索,我没有找到一个。
对于高达100的素数,我能做的最好的是70个字符(包括
空格):
r = range( 2,99)
m = [x代表r中的x代表r中的x]对于r中的x,如果不是x,则代表x中的x
I figured someone out there must have written a minimal code size prime
number generator. I did not find one after a bit of searching around.
For primes up to 100 the best I could do was 70 characters (including
spaces):
r=range(2,99)
m=[x*y for x in r for y in r]
[x for x in r if not x in m]
>
一个更直接,更简短的解决方案:
r =范围(2,99)
[如果x为x则为x,如果[x%] d for d in r] .count(0)< 2]
我确定它可以缩短。
A more straightforward and somewhat shorter solution:
r=range(2,99)
[x for x in r if [x%d for d in r].count(0)<2]
I''m sure it can be made shorter still.
>
58岁,非常好:-)在你的建筑上我们得到57:
r =范围(2,99)
[如果总和为x则为x ([x%d == 0表示r中的d])< 2]
At 58, very nice :-) Building on yours we get 57:
r=range(2,99)
[x for x in r if sum([x%d==0 for d in r])<2]
On Sat,2006年2月11日02:03:46 -0800 ,swisscheese写道:
On Sat, 11 Feb 2006 02:03:46 -0800, swisscheese wrote:
我想有人在那里必须写一个最小代码大小的数字生成器。经过一段时间的搜索,我没有找到一个。
对于高达100的素数,我能做的最好的是70个字符(包括
空格):
r = range( 2,99)
m = [x代表r中的x代表r中的x]对于r中的x,如果不是x,则代表x中的x
I figured someone out there must have written a minimal code size prime
number generator. I did not find one after a bit of searching around.
For primes up to 100 the best I could do was 70 characters (including
spaces):
r=range(2,99)
m=[x*y for x in r for y in r]
[x for x in r if not x in m]
>
我发誓我永远不会玩Python高尔夫。
p,r = [],范围(2,99)
而r :p,r = p + r [:1],[x表示r中的x,如果x%r [0]]
结果'在p。
--Ian Bygrave
I swore I''d never play Python golf.
p,r=[],range(2,99)
while r:p,r=p+r[:1],[x for x in r if x%r[0]]
And the result''s in p.
--Ian Bygrave
这篇关于最短素数计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!