-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-house.html
135 lines (123 loc) · 2.95 KB
/
find-house.html
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Find House Number </title>
</head>
<body>
<h3>Find House Number </h3>
<quote>
A certain street has houses in a row, numbered 1, 2, 3, 4, … consecutively. There is a certain house on the street such that the sum of all the house numbers to the left side of it is equal to the sum of all the house numbers to its right. Find the number of this house.?,
</quote>
<br />
<p>Below run against forumala 2h<sup>2</sup> = n(n+1) <br />
<li>h -> house number</li>
<li>n -> number of houses</li>
</p>
<div id="status">
</div>
<button id="stop">Stop</button> <button id="start">Start</button> <br /> <br />
<div id="number">
</div>
<br />
Found new number Email us 📧- <a href="mailto:weinfinitech@gmail.com">weinfinitech@gmail.com</a
<br /><br />
<div>
<table border="1">
<thead>
<td> <b>Number of houses (n) </b></td>
<td><b>House Number (h)</b></td>
</thead>
<tr>
<td>8</td>
<td>6</td>
</tr>
<tr>
<td>49</td>
<td>35</td>
</tr>
<tr>
<td>288</td>
<td>204</td>
</tr>
<tr>
<td>1681</td>
<td>1189</td>
</tr>
<tr>
<td>9800</td>
<td>6930</td>
</tr>
<tr>
<td>57,121</td>
<td>40,391</td>
</tr>
<tr>
<td>332,928</td>
<td>235,416</td>
</tr>
<tr>
<td>1,940,449</td>
<td>1,372,105</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>11,309,768 </td>
<td>79,97,214</td>
</tr>
</table>
</div>
</body>
<script>
$(document).ready(function(){
var intervals = [];
var no_of_thread = 1000;
var i = 2;
alert("Press ok to procced and enter min/max (optional)");
var min = prompt("Min House");
if(min !=null && min > 0){
i = min;
}
var max = prompt("Max House");
for(j=0;j < no_of_thread;j++){
interval1 = setInterval(findNumber,1);
intervals.push(interval1);
}
var t0 = new Date().getTime();
function findNumber(){
var number = Math.sqrt( ( i*(i+1) ) / 2 );
$("#status").html("<h4>Finding for number " + i + " and result is "+number+"</h4>");
if(number % 1 == 0){
$('#number').append("For Total house of n= "+ i +" house number is h= " +number + " (<i>time taken "+(new Date().getTime()-t0)/1000+" secs </i>) <br />");
}
if(max != null && max > 0 && i >= max){
stop();
}
i++;
}
$("#stop").click(function(){
stop();
});
$("#start").click(function(){
max = null;
start();
});
function start(){
intervals = [];
for(j=0;j < no_of_thread;j++){
interval1 = setInterval(findNumber,1);
intervals.push(interval1);
}
return false;
}
function stop(){
for(j=0;j<no_of_thread;j++){
clearInterval(intervals[j]);
}
return false;
}
});
</script>
</html>