My last two ideas for new exercises didn’t gain much attention but I’ll try again, with a new idea.
Moving Day
Description
Your friend Sean is writing a program that manages a TODO list and is asking for your help.
Users should be able to move some selected items to a different location within the list.
Specifically:
- The selected items are grouped together.
- The relative order of the selected items does not change.
- The relative order of the unselected items does not change.
- All items above the target index in the original list are still above that index in the reordered list.
- All items at or below the target index in the original list are still at or below that index in the reordered list.
For example:
In the list below on the left side the user has selected seven items.
They move them to the index that is currently occupied by “Mopping floors”.
The result is the list on the right side.
Before: After:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Washing dishes ┃ ┃ Washing dishes ┃
┃ Unloading the dishwasher ┃ ┃ Unloading the dishwasher ┃
┃ Taking out the trash ┃ ┃ Taking out the trash ┃
┃ ☒ Vacuuming ┃──┐ ┃ Doing laundry ┃
┃ ☒ Sweeping floors ┃──┤ ┃ Putting away laundry ┃
┃ Doing laundry ┃ │ ┃ ☒ Vacuuming ┃
┃ Putting away laundry ┃ │ ┃ ☒ Sweeping floors ┃
┃ ☒ Mopping floors ┃──┤ ╭──▸┃ ☒ Mopping floors ┃
┃ ☒ Dusting surfaces ┃──┤ │ ┃ ☒ Dusting surfaces ┃
┃ Making the bed ┃ │ │ ┃ ☒ Cleaning the bathroom ┃
┃ Changing bed sheets ┃ ├──╯ ┃ ☒ Wiping kitchen counters ┃
┃ ☒ Cleaning the bathroom ┃──┤ ┃ ☒ Cleaning out the fridge ┃
┃ Cooking meals ┃ │ ┃ Making the bed ┃
┃ ☒ Wiping kitchen counters ┃──┤ ┃ Changing bed sheets ┃
┃ Grocery shopping ┃ │ ┃ Cooking meals ┃
┃ ☒ Cleaning out the fridge ┃──┘ ┃ Grocery shopping ┃
┃ Organizing clutter ┃ ┃ Organizing clutter ┃
┃ Watering plants ┃ ┃ Watering plants ┃
┃ Walking the dog ┃ ┃ Walking the dog ┃
┃ Taking out recycling ┃ ┃ Taking out recycling ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- The selected items are now grouped together, from “Vacuuming” to “Cleaning out the fridge”.
- The relative order of the selected items did not change, e.g. “Vacuuming” comes before “Sweeping floors”.
- The relative order of the unselected items did not change, e.g. “Putting away laundry” comes before “Making the bed”.
- All items above “Mopping floors” in the original list are still above “Mopping floors”.
- All items at or below “Mopping floors” in the original list are still at or below “Mopping floors”.