MIME Type puzzle discussion

I’d say that regular expressions is a bit overkill when it is enough just split by last “.” symbol

Hello all,
I have an issue when I submit, I do not valide the case 4 even if the test case 4 is ok.
Can someone explain why how that is possible ?
I using JS.
Thx

Ran into the problem with that one that I was pushing all the types into lower case, but the ‘game’ expects them to be the same case as you started with. Had to change the code so that it compared the lower case of the name’s extension to the lower case of the data set, but returned the original. After that, all was good.

Problem I am running into is that I am playing around with this thing in LUA. There seem to be function to find the last index of something, as part of the language, for a lot of other languages. LUA doesn’t, nor does it have a built in split function, etc., but it does support regular expressions in its string.find function. Seems that the one I came up with: “%.[^%.]*$”, is slow, so, even if the rest of my code was fast enough, the “find the extension” part of the function bleeds too much time for every file name, to pass the “large dataset” test. Something is delaying it “just enough”. :frowning:

Hello, can someone look at my code and see what I can do to improve performance? On the last case it keeps timing out but I don’t know what I can do to speed it up. I have checks all in the comments.
https://pastebin.com/Zng4DxYR

First of all, you have to use string::rfind() to look for last dot in the file name instead of trying to match testcases with ifs.
On the second hand, you have to normalize file extensions by converting them to lower or upper case (e.g. 1.DOC and 2.doc should have the same mime type)
On the third hand, you should not iterate over values in the map, use map::find() instead.

Thank you so much. the map::find() helped a ton. I didn’t know there was something like that before hand. I also used the FNAME.find_last_of(’.’) to find the last dot and then ran a case to see if that was the end of the file or the start of the name of the file extension.

I had the tolower before I posted my code it was more or less trying to figure out why it kept timing out.

Is it possible to do it in Haskell? Specificaly, I mean large dataset test.
I am using Data.Map for dictionary and findWithDefault for lookup.

Hi,
I have exactly the same issue with the case 4 ‘Consideration of the case (upper or lower)’ when I submit. I’m using JS too. All testcases are ok and I tried other testcases in my code editor that were ok too regarding to the case. My code could be wrong but I can’t figure out what’s the problem if it’s case related.
Did someone pass this test successfully with JavaScript?

Hi, I used the map to code this puzzle with C++, but I still haven’t pass the large dataset test, can someone help me?

Resolved, I used a pointer to refer the map instead of call directly the object

There is a problem with the initial sample test cases. i failed my last submission that is the “large dataset” part. but when i just ignored and submitted the solution, the hidden test cases qualified the large dataset case as passed. I don’t know if it is a bug or something.
hope its rectified soon.

“large dataset” test case certainly has a problem. with c++, I failed to pass it but pass the same test on submit stage. I guess that is some problem with test functions involved.

p.s. using map is a right way as written above. and do not loop for it.

Can confirm. I was losing my mind trying to figure out how using an unordered_map wasn’t efficient enough. Even replaced a call to rfind with a loop that only checked the last 10 chars and still timed out on the examples.

Submitted like you said and got 100% first time.

Hi everyone ! Can you help me ? :slight_smile:
For the lastest test I have a problem “larg dataset” Process has timed out. But I don’t know how to improve what I did.
https://pastebin.com/aGAAfXer
This is my code in pastBin !

Thank you a lot :slight_smile:

you can try :
if cle in donnees
instead of your for loop
you already are in a for loop

Hi, I seem to be having the same problem with upper and lower case considerations.

I tried optimizing my code to make it run faster, but I still can not pass the Upper Lower in submit. Currently using Python 3 and would be very happy if someone could take a look at my code, maybe give me some pointers.

Since when is a .<file_extension> a valid filename?
Can you open a file with the filename “.html” with your browser? I don’t think so. That is my problem with the puzzle. I check for a valid filename. A valid filename should be <basefilename>.<extension> and only .<extension> shouldn’t be allowed. A basfilename should consist of at least 1 character and not none. I know that one of the constraints is that the maximum (base?)filename length is 256 but there is no minimum set. And I can’t imagine that a file with 0 basefilename characters is a valid file. Or am I wrong?

On Linux all hidden files start with a dot. So .anything is perfectly fine.

So a web browser can open such files?

EDIT: I found a useful article to this. Lunix systems don’t need file extensions to determine the MIME-Type of a file. Good to know.

Article: https://www.howtogeek.com/192628/mime-types-explained-why-linux-and-mac-os-x-dont-need-file-extensions/

EDIT 2: But wait. A MIME-Type identification will still fail if only the file extension is the only available information to determine the MIME-Type. To get the type the file has to be opened up and then there has to be a specific byte or string order. But in this puzzle you can’t do this because you just have the file extension as reference.

When you open a file on Linux or Mac OS X, the operating system doesn’t just rely on the file extension. (…) Rather than relying on the file extension at the end of a file’s name, information about the file’s content — the file’s MIME type — is embedded into the beginning of the file itself.

I think you are confusing a few things. The OS doesn’t care how you name your files and if they have extensions or not, as long as it’s a valid filename. That has nothing to do with Mime types. A valid filename doesn’t need to have an extension. You can save an image as image.jpg and rename it to image.txt or just image. That doesn’t change anything, the data on your hard drive is still the same image.

Your filemanager might not start the right program if you try to open image, but from inside a paint program you can still open it.

This puzzle is just a simplified version of the part from the filemanager that decides what program to launch.