quite involved exercise
took me a bit, I´m finding these flatmap exercises quite difficult, but tractable once you take your time and think them through