@leftynaut/

Binary Search Tree

JavaScript

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9835362163770545","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"dmFyIHRvdGFsID0gMDsKdmFyIG9uZTsKCmZ1bmN0aW9uIGZ1bigpewoJdmFyIG1pbiA9IDE7Cgl2YXIgbWF4ID0gMTAwMDAwMDsKCXZhciBndWVzczsKCXZhciBudW1iZXIgPSBNYXRoLmZsb29yKE1hdGgucmFuZG9tKCkgKiBtYXgpICsgbWluOwoJdmFyIGNvdW50ZXIgPSAwOwoJCgl3aGlsZSAoZ3Vlc3MgIT09IG51bWJlcil7CgkgICAgICAgIGNvdW50ZXIgKz0gMTsKCQlndWVzcyA9IE1hdGguZmxvb3IoKG1pbiArIG1heCkgLyAyKTsKCQlpZiAobnVtYmVyID4gZ3Vlc3MpewoJCQltaW4gPSBndWVzcyArIDE7CgkJfSBlbHNlIGlmIChudW1iZXIgPCBndWVzcykgewoJCQltYXggPSBndWVzcyAtIDE7CgkJfQoJfQoJdG90YWwgKz0gMTsKCWlmIChjb3VudGVyID09PSAxKXsKCQlvbmUgPSAxOwoJfQoJCn0Kd2hpbGUgKG9uZSAhPT0gMSl7CglmdW4oKTsKfQpjb25zb2xlLmxvZyh0b3RhbCk="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var total = 0;
var one;

function fun(){
	var min = 1;
	var max = 1000000;
	var guess;
	var number = Math.floor(Math.random() * max) + min;
	var counter = 0;
	
	while (guess !== number){
	        counter += 1;
		guess = Math.floor((min + max) / 2);
		if (number > guess){
			min = guess + 1;
		} else if (number < guess) {
			max = guess - 1;
		}
	}
	total += 1;
	if (counter === 1){
		one = 1;
	}
	
}
while (one !== 1){
	fun();
}
console.log(total)
Native Browser JavaScript