Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Exploit using files in HW4 (to get extremely low efficiency)

gianluca5539 (9820 points)
4 6 44
in HW4 by (9.8k points)
Yesterday I noticed that you can score a very very good efficiency, as little as 30ms, by exploiting a "bug" in the VM test system.

This is what i think happens:

Since the tests are repeated, you can make the code execute almost instantly in all test rounds after the first by opening the files with mode 'x', exclusive creating mode.

As the files already exist after the first test, the exclusive creating mode will throw an error saying that the file already exists. This will take an extremely small amount of time and so the total execution time will be very small. The result is then all tests passed in ~35ms.

This is obviously not a fair way to solve the homework.

The "fix" is easy: just use the 'w' mode, which will create the files if they don't exist or overwrite them if they exist.

I'm writing this so that, if you find a very small execution time, you know that you are actually (probably without even noticing) exploiting a bug.

Wish everyone good luck with HW4!
502 views

3 Answers

andrea.sterbini (207920 points)
750 1267 2373
by (208k points)
edited by
Thanks for signaling this, I've added an "file open mode check" to the VM tests
andrea.sterbini (207920 points)
750 1267 2373
by (208k points)
Found an even easier solution: delete the output file after the test
James_F (6070 points)
10 14 47
by (6.1k points)
Brilliant catch!
Quellocinese (2700 points)
4 4 22
by (2.7k points)
This is brilliant.