warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
งง งง
คือไรอ่ะ? ให้เขียน function หาตัวหารร่วมมากเหรอ??
»
Submitted by sugree on 19 March, 2007 - 16:28.
เอ่อ ใช่แล้วครับ ผมพลาดเอง
>>>print gcd(100,28)
4
»
Submitted by pphetra on 20 March, 2007 - 10:49.
ใน haskell, function gcd มีมาให้พร้อมใน standard library เลย
ลองดูวิธี implement ของมัน
gcd :: Integral a => a -> a -> a
gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined"
gcd x y = gcd' (abs x) (abs y)
where gcd' x 0 = x
gcd' x y = gcd' y (x `rem` y)
งง งง
คือไรอ่ะ? ให้เขียน function หาตัวหารร่วมมากเหรอ??
เอ่อ ใช่แล้วครับ ผมพลาดเอง
ใน haskell, function gcd มีมาให้พร้อมใน standard library เลย
ลองดูวิธี implement ของมัน
gcd :: Integral a => a -> a -> a gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined" gcd x y = gcd' (abs x) (abs y) where gcd' x 0 = x gcd' x y = gcd' y (x `rem` y)ใช้ tail-recursive
ลองไล่ดู method gcd ของ ruby
ก็พบว่ามันมีประเด็นน่าสนใจ
ก็เลยไปเขียนใน blog แทน
http://pphetra.blogspot.com/2007/03/ruby-gcd.html
ตอนผมเรียนผมเรียก HCF Highest Common Factor
ไว้กันงงน่ะครับ