fork download
  1. main :: IO ()
  2. main = mapM_ print [count 1 1 1 1, count 0.5 0.5 0.5 1]
  3. count :: Double -> Double -> Double -> Double -> Int
  4. count x y z r = length
  5. [(a, b, c)
  6. | a <- map fromIntegral [floor $ x - r .. floor $ x + r + 1]
  7. , b <- map fromIntegral [floor $ y - r .. floor $ y + r + 1]
  8. , c <- map fromIntegral [floor $ z - r .. floor $ z + r + 1]
  9. , inside a b c]
  10. where
  11. inside x0 y0 z0 = (x - x0) ^ 2 + (y - y0) ^ 2 + (z - z0) ^ 2 <= r ^ 2
  12.  
Success #stdin #stdout 0s 6268KB
stdin
Standard input is empty
stdout
7
8