Problem 102
コンテンツ
http://projecteuler.net/index.php?section=problems&id=102
三角形の内部判定。
外積を使うと楽。かな。
import Data.List cross (x,y) (u,v) = x*v-y*u containO [x,y,z] = sameSign.map (uncurry cross)$[(x,y),(y,z),(z,x)] where sameSign xs = all (>) xs || all (<) xs toTuples = unfoldr t where t [] = Nothing t (x:y:zs) = Just ((x,y),zs) main = do f <-readFile $ "triangles.txt" print.length.filter (containO.triangle).lines$f where triangle x = toTuples.read$"["++ x ++ "]" ::[(Int,Int)]
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)