MIME Type puzzle discussion

Hi there, i am trying to solve this puzzle in lua. I am pretty a beginner with programming. So far i pass all tests except the large dataset: Found: U expected: a. So i know this error from the previous test cases but i do not know why and where the error is in the large dataset. Any way to get the positions where the error occurs?

Also on submit i fail “duplicate mime” and “same prefix extension”. I don’t know what the puzzle wants from me. There is no explanation whats the error behind these two cases…so i do not know a solution. Anyone know what the input is? and what the expected code behavior is?

My Code: http://pastiebin.com/embed/5974bcf09e4ec

Thanks for the answers

The IDE testcases and the validation testcases look similar, but they serve very different purposes. For a beginner it’s not easy to see the difference. Sadly Codingame only tells you the validation testcases are there “to prevent hard coded solutions”. That’s certainly right, but it doesn’t explain anything.

Lets start at the beginning. The problem description tells you what your program has to do. To solve a problem, you have to write a program that produces the right output for every possible input.

The IDE testcases are there to help you understand the problem description and to facilitate debugging. They are examples and tell you what output your program has to produce for a specific input. That’s why you can see the input, the output and where your program produces errors.

The validation testcases serve a different purpose. To see if you have solved the problem Codingame would have to check that your program produces the right output for every possible input, but that’s obviously not practical. Instead, Codingame only checks for a limited number of inputs (the validation testcases) that your program produces the right output. That’s the reason they can’t give you any information about the validation testcases.

So what does it mean if your program passes all IDE testcases, but fails some validation testcases? It means you have to go back to the problem description and think about your program. Because for some input it doesn’t produce the right output. A good way to go about it is to make some more testcases yourself.

For example take your “duplicate mime” testcase and look at the IDE testcase. It’s probably a list of mime types with two identical entries somewhere (e.g. a,a). Here are some questions you can ask yourself and use to construct additional testcases. Does your program also work if: there are three or more identical entries (a,a,a)? there are multiple identical entries (a,a,b,b)? the identical entries are far apart, or at the front/end of the list? all entries in the list are identical? the duplicates are not in order (a,b,c,a,b,c)?

But these questions obviously depend on your program and you have to find the right questions yourself.

1 Like

Thx…i took the slow approach and built myself a function to iterate through parts of the large dataset and narrow down and find the filename that got matched wrong…

In the end all i missed was the wrong pattern in my expression. I used "a"pattern for letter and so i missed .mp3 and other extensions with a number in it. Fixed it and used “w” for all alphanumerical… DOH…

You sound a bit disappointed, but that’s exactly what I was talking about. It’s in the problem description that filenames can include numbers. That’s the kind of information you have to notice and then ask yourself, does this work in my program?

Hi, my code works but I just can’t pass the filename size test, I keep getting 95%. I did it in C, how was I supposed to do it?

Hi

I’m learning Python language and my code passes all tests except the bid dataset one.
I search for the file extension using .re in for loop.
I guess this is not efficient enough so I would like some advice on a better way.

Thanks

Maybe there is a .p file and a .ppt file?

Better way is to put extensions into a map (also called dictionary in some languages).
This way you can access every item in O(1) time (more or less). something like extensions[get_extension(file_name)]

Hey, I’m doing it in C and I still can’t figure out what to do in order to get it from 95% to 100%. The problem is “Limit size in extensions”. I’ve read some suggestions but still’nothing. I compare only the first 10th elements of the extension but still nothing. Do you guys have any ideas?

How do you handle names like “file.name.ext”?

if you give in input a file like “file.name.ext” it will save in a string just “ext” and then compare it with the extensions given

Okay. Mine solution do the same and I got 100% (files without dots are always “UNKNOWN”, also I do NOT cut extensions to 10 symbols)

I wrote the code without considering only the first 10 characters and considering only 10 characters but none of them seems to work. I guess I got a problem with C, in which language did you solve it?

Initially I’ve solved it in ruby, c# and java. And specially for you I just solved it in C (all 100% done)
I haven’t changed initial constraints so

char ext[101];
char mt[501];
char fname[501];

names like “name” and “name.” yields UNKNOWN always and names like “file.name.ext” are checked for EXT via mime table (ext converted to UPPERCASE).

Maybe you are reusing loop variables outside of loops. Try to malloc everything.

First of all thank you verry much for your help but it didn’t work…
I’ve already malloc -ed everything and all but nothing. I figured out a solution in javascript and made it to 100%, but not in C. May I send you the code to figure out where I mistake? but I guess it would be too much trouble for you, so if you wanna send me yours would be the same. Thank you again man!

Sure, go ahead.

I’ve received your message.

Have you tried to debug inputs? Most likely no.

I’ve added this line to your gist:

fprintf(stderr, "'%s'\n", FNAME);

and got this for first test:

'image.png
'
'animated.gif
'
'script.js
'
'source.cpp
'

Filenames are read with trailing ‘\n’.
Obviously you don’t need it and you have to deal with it somehow. Easiest way is to use scanf instead of gets.

Replacing this line

fgets(FNAME, 501, stdin);

with this one

scanf("%s", FNAME); fgetc(stdin);

makes your code to pass all tests.

Hello,

I have succeeded all the tests cases , but when i submit , i only get 90% and fail on “Correct extension cropping” . As all the given tests are ok , i have no idea on where i have messed up. Any help ?

Did you solve that issue?

I would suggest to use pattern to validate the file name and get the extension from it (using groups).

Pattern.compile("^[a-zA-Z0-9\\.]{0,256}\\.([a-zA-Z0-9]{1,10})$");