Created
October 16, 2017 15:13
-
-
Save TimVosch/b37ede009173918f8132074298a33597 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.util.ArrayList; | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author Tim van Osch, 20160095 | |
*/ | |
public class RecursionCreator { | |
public static final int NUMBER_OF_TESTS = 100; | |
public static void main(String[] args) throws InterruptedException { | |
String input = createInput(NUMBER_OF_TESTS); | |
System.out.println(input); | |
System.setIn(new ByteArrayInputStream(input.getBytes())); | |
System.out.println("Starting tests...."); | |
for (int x = 0; x < NUMBER_OF_TESTS; x++) { | |
System.out.printf("\n========================\nDuration: %.5f\n", test()); | |
} | |
} | |
public static String createInput(int x) { | |
String data = createOne(); | |
for (int p = 1; p < x; p++) { | |
data += " " + createOne(); | |
} | |
return data; | |
} | |
public static String createOne() { | |
String data = ""; | |
// int n = (int)(Math.random() * 90) + 10; | |
int n = 100; | |
data += n; | |
ArrayList<Integer> explosives = new ArrayList<>(); | |
int maxHeight = 0; | |
ArrayList<Integer> birds = new ArrayList<>(); | |
while(explosives.size() != n) { | |
int ed = (int)(Math.random() * 2 * n); | |
if (!explosives.contains(ed)) { | |
explosives.add(ed); | |
data += " " + ed; | |
maxHeight += ed; | |
} | |
} | |
while (birds.size() != n - 1) { | |
int bh = (int)(Math.random() * (maxHeight-1) + 1); | |
if (!birds.contains(bh)) { | |
birds.add(bh); | |
data += " " + bh; | |
} | |
} | |
return data; | |
} | |
public static float test(){ | |
// run explosive recursion | |
ExplosiveRecursion er = new ExplosiveRecursion(); | |
float startTime = System.nanoTime(); | |
er.run(); | |
float duration = (System.nanoTime() - startTime)/1000000; | |
if (duration > 10) { | |
System.out.printf("(!) Duration was %.6f\n", duration); | |
} | |
return duration; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment