MIME Type puzzle discussion

In test Correct division of the extension i don’t think that this “.pdf” is correct file name, but my code fail! Some advises?

.pdf is a correct file name. You can’t create it with the windows graphical user interface, but you can do it with commands lines.

When you have a file like this, you must considerer that the filename is empty and the extension is pdf

Thank you!

It looks like that a file with a name equal to “.pdf” has to be considered like a file with a “pdf” extension. Is it normal?

Yes it is. To know why I let you read Magus’s answer 2 post above your :wink:

1 Like

Thanks for the reply!

In my case, the hardest part was the “Large Dataset.” I solved it by changing concatenation method. “+” operator was taking too long.

Storing the “key” values either uppercase or lowercase won’t have a negative impact on your test results. But, letting values like “TIFf” and “tiFF” become keys… well you know, it’s a mess.

validation test failed for me in Consideration of the case (upper or lower) too in rust language. but it is passed in IDE test case. strange!

From the puzzle description:
“If the extension for a given file can be found in the association table…then print the corresponding MIME type.”
This is not a very good idea for program design
In modern computing, it is very common for malicious files (such as a PHP script) to masquerade as legitimate files (such as a PNG image) simply by using the legitimate extension. If you want to teach people about MIME types, I would encourage you to teach them to utilize more thorough methods.
EX) http://php.net/manual/en/function.finfo-file.php

What a mess. I pass 4 out of 5 IDE tests (i’m coding in C and using an array, so i guess it took too much time to find the good extension name, but i’ll work on it later. i’ve no idea yet on how to do that).

So i pass the IDE tests, except for the last one, but i don’t pass the validation. I got only 30%. I don’t get:
“Correct extension cropping” (no idea on what that mean)
“Consideration of the case” (i do considerate the case. In a simply way: i put everything in MAJ except for the MIME type)
“Detection of same prefix extensions” (still no idea. But maybe it’s a way to make the code go faster. I should work on it).
“Duplicated MIME types” (does the test give us two Mime types that are the same ones and we have to remove one of them?)
“Limit size in extensions” (huh? Extensions have a limited size. What does it means exactly?)
“Large dataset” (this one is normal, since i don’t get the IDE one)

Also, for the last IDE test, the error seems to be on the “scanf” line, the one that is already here at the start of the game and who give the Ext end Mime types (scanf("%s%s", EXT[i], MT[i]); ).
How can i work on it? Its the “given part” of the code!

if someone have some clues…

What correct division of extension means, passed all tests axcept that one. When use stderr to print fname it only print letter a, and result is Found: Nothing, Expected: “a”. Can anyone clerify abit, not get it at all ? Thanks in advance :slightly_smiling:

Concerning “limit size in extensions”:

For example, if a file name is “filename.12345678987654321” your code should recognize that “12345678987654321” is more than 10 characters and thus not a valid extension. In that case you can jump straight to “UNKNOWN”.

okay, thanks. I didn’t even think of this case, but now i’ve fixed it. Or i should have; still not validate it.

We should have better IDE tests on this one. I really don’t see why i get only 30% with nearly al IDE pass :frowning:

Hi guys! I’ve written a code in C# for this puzzle and all of the tests are working ok except the last one which gives me “Failure - Process has timed out. This may mean that your solution is not optimized enough to handle some cases.”. As the expected output is quite huge for this particular test case, it’s hard for me to identify what exactly my code couldn’t “handle”, so I would truly appreciate if you guys could give me some feedback on this.

    int N = int.Parse(Console.ReadLine()); 
    int Q = int.Parse(Console.ReadLine()); 
    string[] EXT = new string[10000];
    string[] MT = new string[10000];
    
    for (int i = 0; i < N; i++)
    {
        string[] inputs = Console.ReadLine().Split(' ');
        EXT[i] = inputs[0]; 
        MT[i] = inputs[1]; 
    }
    for (int i = 0; i < Q; i++)
    {
        string FNAME = Console.ReadLine(); 
        int count = FNAME.Split('.').Length;
        if (count>=2)
        {
            string[] substring = new string[10000];
            substring = FNAME.Split('.');
            for (int j = 0; j < N; j++)
            {
                string sub2 = substring[count-1].ToUpper();
                string EXT2 = EXT[j].ToUpper();
                if(sub2==EXT2)
                {
                    Console.WriteLine(MT[j]);
                    j=N;
                } else if(j==N-1)
                    {
                        Console.WriteLine("UNKNOWN");
                    }
            }
        } else Console.WriteLine("UNKNOWN");
    }
1 Like

Your algorithm only has a limited amount of time to produce the output.

For the large testcase that’s not enough time to compare every filename with every possible extension.

Look at the class Dictionary <TKey, TValue>

2 Likes

Funny Fact:
J’ai changé mon code de sorte que, au lieu de lire le filename, s’arrêter au point (supprimer si besoin les listes de points en trop) puis lire l’extension, il parte de la fin du fichier, s’arrête au premier point et lise l’extension. Il y a ainsi moins de chances de se tromper sur le découpage de l’extension.

Alors, tenez-vous bien: je ne passe plus le test IDE relatif au bon découpage de l’extension. En revanche, j’atteins 50% au lieu de 30% à la validation.

Ces tests sont définitivement mal faits.
Le C aussi, d’ailleurs…l’affichage de mes messages d’erreurs ne se fait pas du tout dans le bon ordre, apparemment c’est un problème récurrent en C, il ne traite pas les choses comme il devrait le faire…Il va vraiment falloir que j’apprenne un langage objet, hein?

EDIT: problème corrigé. Je valide à nouveau tous les tests IDE sauf le grand jeu de données. J’obtiens toujours un score de 50%. Je n’ai toujours pas:

  • Detection of same prefix extensions
    toujours pas d’idée. Faut-il comparer les extensions de départ au cas où le fichier de départ contiendrait deux lignes pour la même extension?

  • Limit size in extensions
    Problème traité, en théorie: si la taille de mon extension n’est pas entre 1 et 10, j’affiche “UNKNOWN”

  • Limite size in filenames
    objectif non déterminé dans le cahier des charges. à quelle taille faudrait-il limiter le nom de fichier?

  • Large dataset
    Normal, mais je sais toujours pas comment traiter ça plus vite en C. Pour l’instant, pour chaque fichier je lis son extension, puis je compare cette extension à celles données en entrée qui ont un MIME TYPE correspondant. Je m’arrête dès que je trouve la bonne. Je vois pas comment aller plus vite.

Hi, i’ve written a solution in C#. Reaching 90%, but fails at validation of “Consideration of the case (upper or lower)”.

Can someone give me a hint

I hope it is ok to post this snippet?!

        // extensions holds all extracted extensions in lowercase
        // extmime (dictionary) holds all extension/MIME pairs
        foreach(string ext in extensions) {              
            if(extmime.ContainsKey(ext)) {
                Console.WriteLine(extmime[ext]);
            } else if(extmime.ContainsKey(ext.ToUpper())) {
                Console.WriteLine(extmime[ext.ToUpper()]);            
            } else Console.WriteLine("UNKNOWN");
        }
1 Like

Why would you ever need more than one extmime.ContainsKey?

1 Like