The OS indeed does care about how you name your files. As you mentioned on linux based systems filenames starting with a dot are hidden for example .config
But on Windows such a filename wouldn’t be allowed because it needs at least a basefilename. The file extension is the indicator with which program the file should be opened. If the file extension is missing Windows asks every time what program should be used to open the file.
On linux based systems files don’t need a file extension because the system reads the file header and decides then what program should be used to open it.
Not to mention that some special characters are not allowed in filenames, depending on the OS.
I still believe that a .txt filename for example in this puzzle shouldn’t be identified as text/plain MIME-Type because of the reasons I metioned above. That is not how it works. If somebody can convince me that this works, then I said nothing.
I’ve looked trough the topic and I have found that you actually can create a file only with a dot and file extension. That changes everything. Sorry for being stupid. Should have searched trough the topic before I complain. Thanks chr-m for the discussion!
I just realized something. In the article you linked they mention the Linux tool “mimetype” (see the sixth image). That is literally the program you are implementing in this puzzle. You can use it from the command line like this:
Bonjour,
J’ai un souci de validation du test 5.
Sauf erreur de ma part, le test échoue sur le fichier “.ico” dont mon code retourne “image/vn…” alors que le test attends “UNKNOWN”.
Pourtant dans le test 3, le fichier “.pdf” est accepté en “application/pdf”.
There is definitely something wrong with the ‘Limit size in extensions’ validation test in C (most people who have encountered this are using C)
Only use the last ‘.’ - strrchr()
No extension is UNKNOWN.
None of the test cases have an extension longer than 10, but I still only hash at most 10 characters.
Then I tried 9 characters to account for the null terminator.
Then I tried 5 characters for fun.
The only way I could see validating this is to give:
file.verylongextension1 and file.verylongextension2
then both map to the mime-type associated with extension ‘verylongex’
Which my program will do.
I wondered if they tried to register verylongextension1 and verylongextension2 to different mime-types? Which would cause an ambiguous case. Do we return the first association, the second, neither, both? My guess is the second because that’s how most built in hash maps work (which C does not have).
Nope. that didn’t work either…
Why would you not provide a test for this validation case? Or allow us to see the validation?
Still 95% - moving on from this busted puzzle.
Looks like this puzzle has not full\incorrect specifications. Rules say: “The extension of a file is defined as the substring which follows the last occurrence, if any, of the dot character within the file name.”. That is literally the only definition.
Now let’s look at test case 3.
So, if the reference table says: “pdf application/pdf”, then the correct answer to line “report…pdf” is “pdf application/pdf”. But here is the responce to this:
Failure
Found: applicat…
Expected: UNKNOWN
Hello i have a little problem with the test 5 : every test is succes but there is one error in this test but I cant find the problem in the 9999 entry…
Thanks a lot. Last year I stopped at this because it annoyed me and using hash was too much work. Now I solved it in 20 minutes using dictionary (last test case with big data set).
My solution passed all the tests but if one of the test had a filed named mp3.mp3 it would have failed (i check if there is no dot by comparing if the first and last strings of a split(’.’) are the same.
Maybe add this case in one of the test.
Why is the correct solution to create a map with both all lowercase and all uppercase? If the right way to write each mime-type is only one (*) but I have to accept different cases, why is it wrong to accept them all (all lowercase or ALL UPPERCASE or WhATeveR)? Is there any real-world case that justifies this?
(*) It seems that the correct way is all lowercase (but it’s not accepted as a solution here):
On one side we have a database/program that doesn’t follow the all lowercase convention but expects to receive information exactly as given to us (Let’s assume it’s in whaTEeVEr case), and on the other side we have the user (and we must accept any case used). To make them understand I have used two maps/dictionaries, one internal (mime as given to me to mime in lowercase) and one external (mime in lowercase to extension in lowercase).
Impossible to validate large datasets with C. I’m using an array of struct with key/value and checking them one by one. Is this supposed to work or do you have to use a hash table? The difficulty spike compared to previous ones is a bit crazy…