-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
134 lines (118 loc) · 3.87 KB
/
index.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
<!DOCTYPE html>
<html lang="en-AU">
<head>
<meta charset="UTF-8">
<title>Extended Euclidean Algorithm Practice Questions</title>
<style>
/* General styling */
body {
background-color: #282A36;
color: #D4D4D4;
font-family: 'JetBrains Mono ExtraBold', sans-serif;
font-weight: 700;
}
h1 {
color: #D4D4D4;
font-size: 8rem;
margin: 0;
padding: 0;
text-align: left;
text-transform: uppercase;
user-select: none;
}
/* Button styling */
.button {
background-color: #D4D4D4;
border: 2px solid #D4D4D4;
border-radius: 5px;
color: #282A36;
cursor: pointer;
display: inline-block;
font-family: 'JetBrains Mono ExtraBold', sans-serif;
font-size: 3rem;
font-weight: 700;
letter-spacing: 0;
margin-right: 20px;
padding: 10px 20px;
text-transform: uppercase;
transition: background-color 0.25s ease, color 0.25s ease;
user-select: none;
}
.button:hover {
background-color: #282A36;
color: #D4D4D4;
}
/* Question and Answer styling */
#question {
color: #FFB86C;
font-size: 2rem;
margin-top: 50px;
margin-bottom: 0;
text-align: left;
}
#answer {
color: #6272A4;
display: none;
font-size: 2rem;
text-align: right;
}
#answer-text {
color: #D4D4D4;
font-size: 2rem;
}
/* Button container styling */
.button-container {
display: flex;
margin-bottom: 20px;
}
.button-container div {
flex: 1;
}
.button-container div:hover {
background-color: #282A36;
color: #D4D4D4;
}
</style>
</head>
<body>
<h1>ext.euclidean generator</h1>
<div class="button-container">
<div class="button" onclick="generateQuestion()">generate</div>
<div class="button" onclick="revealAnswer()">answer</div>
</div>
<p id="question"></p>
<div id="answer">
<div id="answer-text"></div>
</div>
<script>
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
const extendedEuclidean = (a, b) => {
let [x, y, u, v] = [0, 1, 1, 0];
while (a !== 0) {
const q = Math.floor(b / a);
const [m, n] = [x - u * q, y - v * q];
[x, y, u, v, b, a] = [u, v, m, n, a, b % a];
}
const gcd = b;
const [x1, y1] = [x, y];
const [x2, y2] = [b / gcd, -a / gcd];
return { gcd, x1, y1, x2, y2 };
};
const generateQuestion = () => {
const a = Math.floor(Math.random() * 100) + 1;
const b = Math.floor(Math.random() * 100) + 1;
document.getElementById("question").innerHTML = `Find the GCD of ${a} and ${b} and express it as a linear combination of ${a} and ${b} using the extended Euclidean algorithm.`;
document.getElementById("question").setAttribute("data-a", a.toString());
document.getElementById("question").setAttribute("data-b", b.toString());
document.getElementById("answer").style.display = "none";
};
const revealAnswer = () => {
const a = parseInt(document.getElementById("question").getAttribute("data-a"));
const b = parseInt(document.getElementById("question").getAttribute("data-b"));
const { gcd, x1, y1 } = extendedEuclidean(a, b);
document.getElementById("answer").innerHTML = `The GCD of ${a} and ${b} is ${gcd}, and it can be expressed as x=${x1} and y=${y1}.`;
document.getElementById("answer").style.display = "block";
};
</script>
</body>
</html>