Puzzle - MIME Type - What is the expected behavior for extensions >10 characters

Continuing the discussion from MIME Type puzzle discussion:

My javascript solution passes all of the tests except for the limit on file extension length.
Should the output for extension > 10 characters be “UNKNOWN” even if the MIME definitions include an extension that is more than 10 characters?

1 Like

Hello.
I’m fairly sure there is no special behaviour for long extensions, I’m inclined to believe your program fails for another reason.
Just to be sure, do you correctly handle cases where there are only the filename or only the extension ?
For example, this input:

2
2
html text/html
png image/png
index
.html

Requires this outputs:

UNKNOWN
text/html

Does your program do that ?

Why is ‘.html’ text/html? If I use python’s os.path.splitext function it is just hidden file “.html” with no extension. I passed the test using split. Please add a note about that.

.html is an hidden file only on linux system, on Windows I could be considered a valid html file.

I have the same problem, my program keep failing the limit size in extensions even it is able to pass all the other tests, even the one that you are providing in this reply.

However the Limit size in extensions test is keep failing.
What is it suppose to happen for something like:

1
1
superhtml53 text/superhtml53
foo.superhtml53

This can’t happen.

The constraints are here to say that:

  1. your code must work with extensions up to 10 characters;
  2. there is no extension with more than 10 characters, and there is no need to check that fact.
    The same for the other limits.

There are languages and implementation choices where it is important to know these limits (C is one of those), and others where it doesn’t matter.

Ok so, as I expected, the tests won’t try to force this constrains by themselves. Is it possible to have the test to debug it?
I find kind of hard the debug something which is failing without knowing the input. I can imagine tons of possible things going wrong: uninitialized variables, weird input data sequence. Stupid stuff but without a bug-trace these are just hypothesis.

Im having trouble with this too. I tried all I can think of and it still doesnt work! Can we have the test please?

The explanation is not clear about what to do with extensions > 10 characters.
What did work for my code and made me jump from 95% to 100% is creating the list of mime types, include EXT but truncate them to the FIRST 10 characters.

When searching the filenames extension also check only the first 10 characters of the filename extension you find.

Example Input:
1
1
verylongextension text/longextensiontext
file.verylongextension

Your code should map
“verylongex” mime-type to “text/longextensiontext”
and check the filename extension “.verylongextension” as “verylongex” thus find the appropriate mime-type.
HTH

This helped me get from 95% to 100%. The explanation is not clear on the problem. I was assigning UNKNOWN by default when the extension was longer than 10 characters.

Same here…

So, if I understand everything correctly, this means that I should not have the “verylongextension text/longextensiontext” MIME association but “verylongex text/longextensiontext” ?

I tried that and it works as it’s supposed to in your example but still 95% when i submit it. I’m doing it in C, do you have any idea?

Confirmed this is the solution!
Wow. Really who made these instructions??? What a dick move.

Me also, I tried that and it works as it’s supposed to in your example but still 95% when i submit it. I’m doing it in C, do you have any idea?

Why are you posting in this old topic the question to which I already answered in the puzzle’s thread? -_-

1 Like

what you mean ??

What you wrote is incorrect.
I did what you said and I get 95.

So this is what I did to get 100 :

for this example :
1
1
verylongextension text/longextensiontext
file.verylongextension

result should be:
UNKNOWN

file.verylongextension
ext = verylongextension
strlen(ext) > 10 => printf(“UNKNOWN”);

Thanks demnaty for clarifying that what I wrote 5 years ago ist incorrect although other Coders have confirmed that it helped them. It could be that the puzzle has been corrected since, that idea could cross your mind when comparing 2021 to 2016, especially when others confirmed that it had to be done in the way I described five years ago. It could however also have something to do with the choice of programming language. I might check the puzzle again if I have some spare time to validate that it has been corrected. Thanks for your input.