My solutions including naive version and sophisticated version I could find.