two exercises translated to scala