Last active
August 29, 2015 14:17
-
-
Save pathikrit/ffb8a05cd9cd7414c2c2 to your computer and use it in GitHub Desktop.
Natural weekday chooser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val weekdays = IndexedSeq("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat") | |
| def solve(idx: Int*) = (idx foldLeft Seq.empty[(Int, Int)]) { | |
| case (ts :+ ((start, end)), x) if x == end + 1 => ts :+ (start, x) | |
| case (t, x) => t :+ (x, x) | |
| } map { | |
| case (start, end) if start == end => weekdays(start) | |
| case (start, end) => s"${weekdays(start)}-${weekdays(end)}" | |
| } | |
| println(solve(1, 2, 3, 5)) | |
| println(solve(1, 2, 5)) | |
| println(solve(2, 3, 4)) | |
| println(solve(1, 3, 5)) | |
| println(solve(0, 1, 3, 5, 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment