by generallyfalse · 8y ago · 0 comments
Sum of cubes:
sum(i**3 for i in range(n+1))
findMedianSortedArrays using Haskell: let m a [] n = a !! n
m [] a n = a !! n
m (x:_) (y:_) 0 = if x<=y then x else y
m (x:xs) (y:ys) n = if x<=y then m xs (y:ys) (n-1)
else m (x:xs) ys (n-1)
let m1 a b = if odd n1 then m a b n12
else (m a b n12 + m a b (n12-1))/2
where n1 = length a + length b; n12 = div n1 2
let findMedianSortedArrays = m1
I haven't checked the code.No comments yet.