Bug hunt

Two Scrolls, One Name

A plan can hide a trap. Look at this folder:

  • Map 1.txt would become map-1.txt
  • map 1.txt (two spaces) would also become map-1.txt
  • and map-1.txt already 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:

  1. The same target name is planned more than once.
  2. 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:

  1. A target planned two or more times is reported.
  2. A target that is already in existing is reported.
  3. Each clashing target appears once, and the list is sorted.