Comparison of offers with previous materials?

Users submit code (mainly java) on my site to solve simple programming problems, but sending code to the server to compile and execute it can take more than 10 seconds.

To speed up this process, I plan to first check the application database to make sure that equivalent code has been submitted before. I understand that this will make random methods always return the same result, but that doesn't really matter. Is there any other potential problem that might be caused by not running the code?

To find matches, I remove comments and spaces when comparing the code. However, the same code can be written in different ways, for example, with different variable names. Is there a way to compare code that finds more equivalent code?

+4
source share
2 answers

Variable names:
You can write code to map variable names in one file to variable names in another, then you can replace both sets with a consistent variable name.

File 1: var1 + = this (var1 - 1);

File 2: sum + = this (sum-1);

, 1, , File 2 , .
* , , . , . , .

:
Force {} () , /else//while/etc...
"i + =..." "i = +..."

:
, , , , .

:
"3 + (2 * 4)" "2 * 4 + 3"
, . , , , .

.

(2+4) * 3 + (2+6) * 5 == someotherequation
//substitute most precedent: (2+4) and (2+6) for a and b  
... a * 3 + b * 5   
//substitute most precedent: (a*3) and (b*5) for c and d   
... c + d   
//substitute most precedent....   

, . , ... .

+1

SHA1 . , . minifier . , cat dog a1, , . -, .

, ? , ClassLoader, JDK tools.jar " ". AJAX REST .

, Eclipse .

, http://ideone.com -.

FYI. , . .

+2

All Articles