/
lev3.html
113 lines (112 loc) · 3.18 KB
/
lev3.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
<html>
<head>
<h1><center>Level 3: Algorithm of Consensus.</center></h1>
<style>
.outer
{
background-color: #000000;
opacity: 0.6;
top: 5%;
left:32%;
position: relative;
height: 60%;
width: 35%;
border-radius: 10px;
}
</style>
<script type="text/javaScript">
var next1=0;
function showMe()
{
if(next1)
{
document.getElementById("showme").setAttribute("style","diaplay: none;");
}
}
function setPopulation()
{
next1=1;
var r = parseInt(document.getElementById("total").value);
document.getElementById("bribe").setAttribute("max",r);
document.getElementById("noofpeople").innerHTML=r;
plotPoints();
showMe();
}
function plotPoints()
{
var b=parseInt(document.getElementById("bribe").value);
var canvas=document.getElementById("draw");
var ctx=canvas.getContext("2d");
ctx.clearRect(0,0,500,500);
var t=parseInt(document.getElementById("total").value);
var nb=t-b;
document.getElementById("bribed").innerHTML=b;
ctx.beginPath();
ctx.rect(150,10,4,4);
ctx.fillStyle="blue";
ctx.fill();
ctx.closePath();
document.getElementById("time").innerHTML=(b*10);
document.getElementById("minTime").innerHTML=(t*5)+10;
for(var i=0;i<b;i++)
{
var x=Math.ceil(Math.random()*1000)%300;
var y=Math.ceil(Math.random()*1000)%150;
ctx.beginPath();
ctx.rect(x,y,1,1);
ctx.fillStyle="red";
ctx.fill();
ctx.closePath();
}
for(var i=0;i<nb;i++)
{
var x=Math.ceil(Math.random()*1000)%300;
var y=Math.ceil(Math.random()*1000)%150;
ctx.beginPath();
ctx.rect(x,y,1,1);
ctx.fillStyle="green";
ctx.fill();
ctx.closePath();
}
showMe();
console.log([b,nb]);
}
</script>
</head>
<body>
<div>
<center>
<div>
<p>
By your previous difficulties santa(in blue) gave you a power to send your message to many people before sending directly to santa.
Now,santa will collect all the messages from the people and will rely on the message which he got in majority(atleast 51% of the total).
Now lets assume it takes 10 minutes for your enemy to manupulate message from 1 person,Now see the calculations and defeat your enemy by this method.
</p>
<div>
<div>
<span><b>Total no. of Persons to whom data is to be send :</b></span>
<input id="total" type="range" min=100 max=5000 value=100 oninput="setPopulation()">
<span id="noofpeople">100<span>
</div>
<br>
<div>
<span><b>Total no. of persons whose data is manupulated:</b><span>
<input id="bribe" type="range" min=0 max=100 value=0 oninput="plotPoints()">
<span id="bribed">0<span>
</div>
</center>
</div>
<div>
<canvas class="outer" id="draw"></canvas>
</div>
<br>
<br>
<div>
<p>Total time required(in mins.) to manupulate majority(atleast 51%) of data:<b id="minTime"></b></p>
<p>Total time required(in mins.) to manupulate selected amount of data:<b id="time"></b></p>
</div>
<div id="showme" style="display: none;">
<input type="button" value="proceed to simulation >>" onclick="location.href = 'simulation.html';">
</div>
</body>
</html>