佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

楼主: Squall_Chua

前幾天我在jobstreet看到有趣的東東

[复制链接]
发表于 5-3-2009 11:14 AM | 显示全部楼层
抱歉,看來之前是我有所誤會
我重新看囘所有帖子發現樓主的O(n ^ 2)是指brute force method而言
至於樓主本身的方法則是O(n ^ 1.5)也正因此比brute force method快
sieve of eratosthenes的複雜度很難計算
wiki上的資料是O((n log n)(log log n))

以下是用python寫的不同方法:

import timeit
import math

def findPrimesV1(total):
    primearr = []
    for i in xrange(2, total):
        prime = True
        for j in xrange(2, i):
            if i % j == 0:
                prime = False
                break
        if prime:
            primearr.append(i)
   
    return sum(primearr)

def findPrimesV2(total):
    primearr = []
    for i in xrange(2, total):
        prime = True
        for j in xrange(2, int(math.sqrt(i)) + 1):
            if i % j == 0:
                prime = False
                break
        if prime:
            primearr.append(i)
   
    return sum(primearr)

def findPrimesV3(total):
    primearr = range(0, total)
    for i in xrange(2, total):
        if primearr:
            for k in xrange(2 * i, total, i):
                primearr[k] = 0
    return sum(primearr) - 1

print 'sum < 10000 primes using bruce force method : %.2f' % timeit.Timer('findPrimesV1(10000)', 'from __main__ import findPrimesV1').timeit(1)
print 'sum < 10000 primes using square root method : %.2f' % timeit.Timer('findPrimesV2(10000)', 'from __main__ import findPrimesV2').timeit(1)
print 'sum < 10000 primes using sieve of eratosthenes : %.2f' % timeit.Timer('findPrimesV3(10000)', 'from __main__ import findPrimesV3').timeit(1)
print
print 'sum < 20000 primes using bruce force method : %.2f' % timeit.Timer('findPrimesV1(20000)', 'from __main__ import findPrimesV1').timeit(1)
print 'sum < 20000 primes using square root method : %.2f' % timeit.Timer('findPrimesV2(20000)', 'from __main__ import findPrimesV2').timeit(1)
print 'sum < 20000 primes using sieve of eratosthenes : %.2f' % timeit.Timer('findPrimesV3(20000)', 'from __main__ import findPrimesV3').timeit(1)
print
print 'sum < 100000 primes using square root method : %.2f' % timeit.Timer('findPrimesV2(100000)', 'from __main__ import findPrimesV2').timeit(1)
print 'sum < 100000 primes using sieve of eratosthenes : %.2f' % timeit.Timer('findPrimesV3(100000)', 'from __main__ import findPrimesV3').timeit(1)
print
print 'sum < 200000 primes using square root method : %.2f' % timeit.Timer('findPrimesV2(200000)', 'from __main__ import findPrimesV2').timeit(1)
print 'sum < 200000 primes using sieve of eratosthenes : %.2f' % timeit.Timer('findPrimesV3(200000)', 'from __main__ import findPrimesV3').timeit(1)
print
print 'sum < 2000000 primes using sieve of eratosthenes : %.2f' % timeit.Timer('findPrimesV3(2000000)', 'from __main__ import findPrimesV3').timeit(1)

在我電腦上的計算結果如下:
sum < 10000 primes using bruce force method : 0.78
sum < 10000 primes using square root method : 0.03
sum < 10000 primes using sieve of eratosthenes : 0.00

sum < 20000 primes using bruce force method : 2.88
sum < 20000 primes using square root method : 0.07
sum < 20000 primes using sieve of eratosthenes : 0.01

sum < 100000 primes using square root method : 0.50
sum < 100000 primes using sieve of eratosthenes : 0.05

sum < 200000 primes using square root method : 1.21
sum < 200000 primes using sieve of eratosthenes : 0.10

sum < 2000000 primes using sieve of eratosthenes : 1.48

如果是用編譯語言會更快,除了bruce force method以外應該都會滿足1秒以内計算出的條件
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 5-3-2009 05:40 PM | 显示全部楼层

回复 41# cristiano~7 的帖子

我是一直都在做brute force method的analysis啊
害我還一直奇怪你們的反應

不過我幾時有說過了我的method?
我用的方法比較特別一點
而且code也很短而已



後面偷偷的說
我今天有感工作難找啊
在jobstreet裡面除了apply幾家公司的software engineer外
也send我的resume和code去這家公司了

虧我還一直在偷笑人
結果自己跑去apply了
回复

使用道具 举报

 楼主| 发表于 5-3-2009 05:43 PM | 显示全部楼层

回复 41# cristiano~7 的帖子

忘了說你的python code看起來很多字
看到很暈很懶惰去讀
我比較習慣看像C那樣的language
回复

使用道具 举报

发表于 5-3-2009 07:42 PM | 显示全部楼层

回复 43# Squall_Chua 的帖子

你对你的C很有信心吗?

这家公司,我有认识人。可以立刻知道答案 他们的确很需要C programmer 是好的C programmer
回复

使用道具 举报

 楼主| 发表于 5-3-2009 09:11 PM | 显示全部楼层

回复 44# faiko 的帖子

應該還好吧
C++的話肯定沒問題
如果是pure C的話就有點汗
不太習慣不用class來manage很複雜的data structure
回复

使用道具 举报

发表于 5-3-2009 10:30 PM | 显示全部楼层

回复 45# Squall_Chua 的帖子

那就看你肯不肯学咯
我可以帮你forward mail给他。通过jobstreet会比较慢一点。

C++和C的确有点距离。而且,C里面的强大功能,在C++反而是危险的工具。
回复

使用道具 举报

Follow Us
 楼主| 发表于 5-3-2009 10:36 PM | 显示全部楼层

回复 46# faiko 的帖子

C language我應該是沒問題的
low level的東西我還能夠接受

C有甚麼強大的功能在C++很危險的?
回复

使用道具 举报

发表于 5-3-2009 10:42 PM | 显示全部楼层

回复 47# Squall_Chua 的帖子

C++ 强调OOP concept
C没有

而C的function pointer完全violate OOP概念。很少大学有真正去探讨C的functor。但是,C不会死的原因也是functor很好用。而且,memory allocation的方式跟C++不同。

呵呵,看你没有意思要我帮你forward mail。那就祝你好运咯。希望你面试成功
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 5-3-2009 10:53 PM | 显示全部楼层

回复 48# faiko 的帖子

我好像是用email過去的
因為看到下面寫說直接email過去
我只是試著apply而已
其實還沒決定要做甚麼樣工作的
回复

使用道具 举报

 楼主| 发表于 6-3-2009 03:27 PM | 显示全部楼层
又再偷偷過來說
剛才他們打電話過來叫我去interview了
回复

使用道具 举报

发表于 6-3-2009 04:07 PM | 显示全部楼层
恭喜恭喜。。。
回复

使用道具 举报

发表于 6-3-2009 08:30 PM | 显示全部楼层
呵呵
看来他们真得很需要人手

Fresh Grad就不要要求太多 这间公司是做Telco service的。可以学很多Telco standard的东西。
回复

使用道具 举报

发表于 7-3-2009 11:08 PM | 显示全部楼层

回复 50# Squall_Chua 的帖子

恭喜恭喜
有工作开了。。。。
回复

使用道具 举报

发表于 12-3-2009 10:32 AM | 显示全部楼层
怎样?
去了interview鸟??
回复

使用道具 举报

 楼主| 发表于 12-3-2009 11:38 AM | 显示全部楼层
明天才去
回复

使用道具 举报

发表于 12-3-2009 11:58 AM | 显示全部楼层
ok
Good Luck
回复

使用道具 举报


ADVERTISEMENT

发表于 15-3-2009 11:41 PM | 显示全部楼层
原帖由 Squall_Chua 于 12-3-2009 11:38 AM 发表
明天才去


你的interview 怎样了???? 成功了吗?
回复

使用道具 举报

 楼主| 发表于 16-3-2009 08:45 PM | 显示全部楼层

回复 57# 晨天 的帖子

今天剛收到email說他們要offer我了
不過我沒接到他們打來的電話


不過我還沒決定要不要去叻
上個禮拜看到UTAR的professor在jobstreet找research assistant的廣告
正好那個professor是我認識的
以前在我學校的
他也還記得我
所以我make了appointment去見他
聽他說些關於那個research project的詳細內容


所以現階段來說
我做不到決定叻
回复

使用道具 举报

 楼主| 发表于 16-3-2009 08:45 PM | 显示全部楼层

回复 57# 晨天 的帖子

[重複回貼,版主請刪除]
回复

使用道具 举报

发表于 16-3-2009 10:58 PM | 显示全部楼层

回复 58# Squall_Chua 的帖子

你MMU的?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 17-12-2025 08:27 PM , Processed in 0.347041 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表