Hacker News new | ask | show | jobs
by generallyfalse 2893 days ago
In one of your comments you say you have improved a lot in two months or so, so perhaps you need a little more practice and I think you could improve a lot more (less time for solving puzzles and writing better code). Anyway, I have tried to solve some of the puzzles. Perhaps other people in this thread can give more valuable information about your coding style. I wish you the best.

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.