MIME Type puzzle discussion

I think that this puzzle manager should not be comparing exact case for the resulting MIME types. The MIME type definition states that MIME types are not case sensitive, but your tests fail if the MIME types are not returned in the exact case in which they were provided.

For the life of me, I can’t figure out how to do this in Bash4 (on the large dataset). I’ve tried associative arrays, regular arrays, File I/O, plain old environment variables…
Just for fun, I completed this first with Python3, and it worked without any trouble whatsoever.

Any ideas? Has anyone managed to complete this with Bash? Is it even possible, or is it just too slow?

Hi. It’s plainly possible to solve this problem with an associative array in bash.

Oh, I see. I made the mistake of using grep, haha… Maaajor bottleneck. Thanks anyway. I got it.

I have the feeling that at the moment of writing the validation process of this problem is flawed. I have the following situation:
(1) when I allow for empty filenames then I pass all the testcases but during validation I don’t pass the parts : ‘Correct extension cropping’ and ‘Limit size in extensions’

(2) when I don’t allow for empty filenames, testcase 3 and 5 return failed. But now when I am validating my code I dont pass the parts ‘Large dataset’ and ‘Limit size in extensions’. (i.e. So now suddenly I do pass ‘Correct extension cropping’.)

The thing I conclude from this, is that in the validation step ‘Large dataset’ there are entries with empty filenames for which I should return a MIME type but for the step ‘Correct extension cropping’ I should not allow empty filenames.

If this is correct behavior from the part of the validator this can only mean that I am missing something else here. Anybody a clue because as far as I can see the validation process is faulty.

As a second question, how do I pass ‘Limit size in extensions’, I have no clue what is required from me for this step. In the problem definition it is stated that the maximum extension character length is 10 characters. Therefore I assume that the input already satisfies these constraints. Nowhere it is written that I should check for this criterium. But lets for the sake of argument say that I do check on this, how should I select 10 characters from the extension in the case that the extension length indeed exceeds 10? Should I pick the first 10 or the last 10 characters? Nothing seems to work so far.

Anybody an idea for these two issues? I am programming in c++.

Ok I found the issue. I was manually searching for the ‘.’ in the string instead of using rfind for example. The index variable I was using was of type size_t. Now if no ‘.’ was found in the string the index would go to the value -1, or at least that is what I thought. But because size_t is an unsigned value, instead of going to -1 it goes to something very large. I was checking on negativity of the index to see whether a ‘.’ was found whereas I should have checked on whether the value was very large. For some reason though in the tests this never caused an issue and it flawlessly gave me correct output whereas the validation process seemed to be able to detect this problem.

Does a mod have any thoughts on why the test cases seem to work perfectly but only during the validation this causes an issue?

cheers

1 Like

I’m stuck at validation “Limit size in extensions”. Every other test passes.

  • I have saved the Extensions and Mime-types in a list of
    “Information-objects” and I check that no extension is more than 10
    characters, before saving the values to my list.
  • Then I extract the extensions (.xxx) from the filenames and save them to a separate list of strings.
  • Then I run the contains-method in C#, in a foreach- and a forloop, combined.

Is there a problem with this type of solution?

Any advice?

Did anyone else got this error while testing Large Dataset :
“Process has timed out. This may mean that your solution is not optimized enough to handle some cases.”
There is only this error and I’m writing the code in Python3.

1 Like

Using C too.

[1] For me, i turned EXT & MT into 2D array.
Then i just created one more numeric array same # of items with the lookup table. Then come up with some equation to translate the extension (i uppercase all of them, and use the ASCII #) into a hash number, stored them according to their row.
To do matching, i’ll just need to apply the same formula to obtain the hashnum i need, then look through the array containing all the hash numbers, if it is found, then you may start printing the MIME type since it is the same row in another array.

[2] Initially i use “int” for the array i created to keep hash numbers, and faced the same issue as you. Later just changed it to “unsigned long” and i get 100%.

happy trying… :smile:

Hello,

I’m using c++ and a map instead of an array but I failed on the large dataset.

This is the error:
Process has timed out. This may mean that your solution is not optimized enough to handle some cases.

But the output is correct.

What can I do to solve this?

Thanks

I used “containsKey()” and “get()” methods, so I didn’t have to iterate over the map

There might be a bug in the tests for lua. Even though I’m printing the correct mimetypes for the file extensions (preserving case perfectly etc), it says I got it wrong. Below is sample output from my program for the 01 simple example:

image/gif
image/png
text/html
Fail
Found: “”
Expected: “i”

Hi, i’m trying to pass this but it keeps giving me an error
" Process has timed out. This may mean that your solution is not optimized enough to handle some cases."

I think the problem is on the “Try” line. Everything else gives me green output.

This is the program i currently wrote:

[EDIT: NO FULL CODE]

PS: The error is on the “LARGE DATASET”

Hello.

I’ve got an (ugly) solution to the MIME Type puzzle. It passes all tests, but for some reason when I submit it, I only get 95%. Does anybody know why this might be happening?

Thanks in advance.

Maybe your code is too ugly to get 100%. :smiley:

I have made my code, submitted it and passed all validators except these two: “Detection of same prefix extensions” and “Large dataset”. From the tests I passed all but the “large dataset” test.

My question is, what could be the problem with “Detection of same prefix extensions” ? I found no clues about it here
Please help!

I made my code and it passed all tests in the IDE, but after validation the “Consideration of the case (upper or lower)” failed.

I checked my code several times, but i can’t find any problem with this.

if(FNAME.length == 1 || typeof mimeMap.get(FNAME[FNAME.length -1].toLowerCase()) === 'undefined' && typeof mimeMap.get(FNAME[FNAME.length -1].toUpperCase()) === 'undefined') {
    mimes += "UNKNOWN\n";
} else if (typeof mimeMap.get(FNAME[FNAME.length -1].toLowerCase()) === 'undefined') {
    mimes += mimeMap.get(FNAME[FNAME.length -1].toUpperCase()) + '\n'
} else {
    mimes += mimeMap.get(FNAME[FNAME.length -1].toLowerCase()) + '\n'
}

Hi Rick,
I did it in javascript too, did similar steps to yours and still fail the Large Data Sets test and validation with "Time Out bla bla " warning, it passes all other tests. If I cut the input file in half it still fails from Time Out, but not if I use 1/3 or less of the data set. I break the loop when I get the right answer or if file extension is longer than 10 characters (which I don’t think any is anyway but) I don’t how to further optimize it. Any extra tip? thanks

Here is a tip for everyone that has problems with the runtime: The program should have two parts. First, create some kind of map and store all the mappings from extension to MIME type there. Second, for every filename, use the map to get the corresponding mime type and print it.

A map is a datastructure that saves key/value pairs and is constructed in a way that makes the lookup of a value for a given key very fast. For example a hashmap.

Here is a tip for everyone that uses Javascript: You can use a normal object as a map. Think about this way obj.key = value.

Initialize an object var map = {};.

Then add all the MIME types. For example map["html"] = "text/html";.

In the second part you can then access the MIME type of a given extension with map["html"].

Keep in mind, I say map["html"] = "text/html"; for illustrative purposes only. In your program you have to use variables like in map[ext] = mime;, because you don’t know the MIME types until the program runs.

Also keep in mind the difference between map.ext and map[ext]. The first will always access the property with the name ext. The second will access the property named by the variable ext.

1 Like

Chrm,
thanks for the tip. Changed my program from using arrays to using objects and passed all the tests!