add solution 4 with scala