I do introductory computer science once a week. I was hoping that at the end of my next lab I would strive for competition. I want to give them a code block as follows:
public class EfficientCode{ public static void main(){ long startTime, endTime, executionTime; startTime = System.currentTimeMillis(); yourEfficientMethod(): endTime = System.currentTimeMillis(); executionTime = endTime – startTime; } public static void doSomething(){ // you do this part. } }
They will implement the doSomething method, and the person with the fastest code will receive several bonus tags.
The problem is that the question should be somewhat simple. Students have a good idea: loops, if / else, strings, append, arrays, etc.
Here are my ideas on what the question might be:
, , , - .
, , , - , , , , . , , , , Google.
, . , , , , . , -, , , . , . . , ( ) , , .
- , . , 2kb - . .
" " , , .
Project Euler, . , " ", , . .:)
.
-, - , . , , / .. , . , , , . ...
-, 15 , :
, 121212. . 1 . , 98167 + 23045. , , . 192 ...
121212
1
98167 + 23045
. ?
Sorting an array of numbers can also be a good idea, since there are a whole bunch of algorithms for it (insert, select, quick, heap, etc.) that have different performance characteristics. It will also give students the opportunity to learn about capitalization O notation, etc.