
Two Scrolls, One Name
A plan can hide a trap. Look at this folder:
Map 1.txtwould becomemap-1.txtmap 1.txt(two spaces) would also becomemap-1.txt- and
map-1.txtalready exists, because it was tidy already
On most computers, renaming onto a name that exists silently replaces that file. One scroll would vanish forever.
So before applying a plan, look for collisions: target names that would clash. There are two kinds:
- The same target name is planned more than once.
- A target name is already the name of a file in the folder.
Also watch out on Windows and macOS: they usually treat Map.txt and
map.txt as the same name. Our clean names are all lowercase,
which helps.
The bug
find_collisions(plan, existing) should return a sorted list of the
clashing target names. existing is the list of file names
already in the folder. Right now it misses the two scrolls that
want the same name. And when it spots a clash with an existing file,
it reports the wrong name.
Assignment
Fix find_collisions so that:
- A target planned two or more times is reported.
- A target that is already in
existingis reported. - Each clashing target appears once, and the list is sorted.
Fix find_collisions so that:
- A target planned two or more times is reported.
- A target that is already in
existingis reported. - Each clashing target appears once, and the list is sorted.
Press Run to try your code, then Check to test it.