I found the problems straightforward to code in Haskell. The first part ran correctly right after I got it to compile. The second initially gave bogus results. Turns out I needed to invert a test and then it ran correctly too.
15 lines of code including 3 imports and 3 type declarations;
1 line to comment out to do the easier problem.