MIME Type puzzle discussion

The specification states the maximum length of the extension.
That test probably has a longer than specified extension in it, you should truncate the length of the extension when parsing the MIME types!

What do you mean with “Duplicated MIME types” ? I don’t get it.

2 Likes

For the large dataset test, you’ll need an efficient algorithm to search for the proper MIME type for a large number of files. If you’re using arrays, you aren’t using the best container for efficiently searching for MIME types.

If you’re using C++ (my programming language of choice), I suggest that you use a map instead of an array. A map in C++ may be called an associative array, hash table, or dictionary in other languages.

27 Likes

Big thanks :slight_smile:

A map is an easy and efficient solution, which requires less work than yours ^_^. Moreover, what you’re proposing is actually a kind of tree map, thus a map :wink:

What do you mean with “limit size in filenames”?  I don’t need to use the filenames at all.
All 5 Test Case pass ok, but the final score is 95%

4 Likes

you should use a map, as described above :wink:
I think that the problem is that your program is too long to give an answer. But we can’t be sure as we don’t have the data set for the test.

Anyway, That was my problem too, and using a map resolved it :wink:

sure? If I make a pause of 400ms [ usleep(400) in PHP ] the test goes right, but if I pause for 500ms the test fails in  “Large dataset (300 pts)”. So I assume this is the checking for slow program.
“limit size in filenames” have no sense about program velocity check.

Please, any ideas on the “limit size in filenames” check?

EDIT:
The problem was the original input line suggested by the platform:
$FNAME = stream_get_line(STDIN, 256, “\n”);

the problem disappeared using this one:
$FNAME = stream_get_line(STDIN, 2560, “\n”);

1 Like

Hi! I am confused by Large dataset test. My script’s (I used bash) output is fully identical to given out.txt, but test fails. I can imagine only one problem - performance. Script executes more than 70 seconds…

UPD: Fixed it by the hash-tables solution.

Hi in javascript is something wrong with “Large dataset” test, I got fail without any error, on Console output after line 70 strangely appear this:

text/html
application/json
application/vnd.ms-powerpoint


UNKNOWN

2 Likes

If the line with “…” is bothering you, as I said in another topic:

It also applies to the output stream so you can’t see the whole response with large dataset tests.

1 Like

I think that there is an issue in the test data set. For example, I see it fail on this last entry:

iLowerCaseAndUpperCaseLetters.exe>>application/octet-stream
thisistheend.xls>>application/vnd.ms-excel
anotherfiletest.zip>>application/zip
thisisanotherfilename.longextens>>UNKNOWN
iLowerCaseAndUpperCaseLetters.>>UNKNOWN

My code properly handles the fact there is a period with no extension following and it reports UNKOWN yet the test harness reports this is not correct. Makes no sense to me. Is it possible an issue in the Groovy/Java tests?

1 Like

The test report doesn’t tell you where the fail is exactly. Your last line is correct but one or several of other lines might be wrong.

4 Likes

Guys, make sure you make everything correct:

  • have a proper map of mime types (key / value, hash set, or both)
  • have a proper method of extracting extension from file. I forgot about digits and all mp3-s missed.
  • make sure performance is good (which is if you use hashset / generic dictionary)
1 Like

I presume your program fails on file extensions that have a length of 10 characters.

File extensions are composed of a maximum of 10 alphanumerical ASCII characters.
MIME types are composed of a maximum 50 alphanumerical and punctuation ASCII characters.
File names are composed of a maximum of 256 alphanumerical ASCII characters and dots (full stops).

If you are using a language that requires a 0 character to end a string, you must add that to the maximum length when reserving space.

There may be more than one extension that resolves to the same MIME type.

hi! how you did it?
i’m use BASH too
i can’t pass 2 puzzle with BIG DATA (MIME Type & Horse-racing Duals)
tried to use arr[key]=value and arr[]=key:value, but didn’t work
i get different steps_count every time in cycle

Those kind of puzzle require more than just the basic algorithm, “gotta go fast!” is the key point. I’m not fluent in shell scripting so I can only give you a general advices:

  • Break a for or while loop whenever you can. Those can really slow down your processing time
  • Try to limit action that takes a lot of time on large list: for and while but also sorting can be really long
  • Turn around your code completly once in a while to test different method. Sometimes you can find really improved way of doing things.

That’s all for my basic advices. Honestly MIME Type didn’t put me in a lot of trouble but horse racing dual did, don’t hesitate to go to the topic that speak about it: Horse racing dual topic

1 Like

Hi !
I’m passing everything except “Correct extension cropping” ! what does that mean ?!

Haven’t tried, but 257 also would work.