solved p4 with haskell
solved p1, p2 with haskell