This commit is contained in:
JeoJake 2021-10-29 13:06:35 +03:00
commit 4a001767b8
7 changed files with 782 additions and 0 deletions

78
index.html Normal file
View File

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CDM Utils</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
</head>
<body>
<nav class="navbar is-white">
<div class="navbar-brand">
<a href="index.html" class="navbar-item">
<!-- <img class="mr-2 py-1" src="assets/cuqmbr.png" alt="Cucumber emoji image"> -->
CDM Utils
<!-- <img class="ml-2 py-1" src="assets/Shchoholev-logo.png" alt="Cucumber emoji image"> -->
</a>
<a class="navbar-burger" id="burger">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div class="navbar-menu" id="nav-links">
<din class="navbar-start">
<a href="index.html" class="navbar-item">
Home
</a>
</din>
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable" id='dropdown'>
<a class="navbar-link">
Introduction. Set Theory
</a>
<div class="navbar-dropdown">
<a href="pages/lab-1.html" class="navbar-item">
Set Algebra
</a>
</div>
</div>
</div>
</div>
</nav>
<div class="columns gapless my-0 has-background-info">
<div class="column is-6-desktop is-12-tablet py-0">
<section class="hero is-fullheight-with-navbar">
<div class="hero-body">
<div class="">
<p class="title">
<span class="icon-text has-text-white">
<span>Hello there</span>
<span class="icon">
<i class="fas fa-handshake ml-5"></i>
</span>
</span>
</p>
<p class="subtitle has-text-white">The web-site is created for people who want to learn<br> more about Computer Discrete Mathematics</p>
</div>
</div>
</section>
</div>
</div>
<script src="js/index.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/js/all.min.js'></script>
</body>
</html>

15
js/index.js Normal file
View File

@ -0,0 +1,15 @@
const burgerIcon = document.querySelector('#burger');
const navbarMenu = document.querySelector('#nav-links');
burgerIcon.addEventListener('click', () => {
burgerIcon.classList.toggle('is-active');
navbarMenu.classList.toggle('is-active');
});
const dropDowns = document.querySelectorAll('#dropdown');
dropDowns.forEach(element => {
element.addEventListener('click', () => {
element.classList.toggle('is-active');
})
});

299
js/lab-1.js Normal file
View File

@ -0,0 +1,299 @@
let maxNum = 26;
let currNum = 2;
function AddSet() {
if (currNum < 26) {
let charNum = 65 + currNum;
currNum++;
let delBtn = document.querySelectorAll('#delBtn');
if (delBtn[delBtn.length - 1]) {
delBtn[delBtn.length - 1].style="display: none;";
}
node = document.getElementById('sets');
node.insertAdjacentHTML('beforeend', ` <div class="field" id="setfield${charNum - 65}">
<div style="display: flex; align-items: center;">
<button class="delete is-small mr-1" type="button" onclick="DeleteSet(${charNum - 65})" id="delBtn"></button>
<label class="label">Set &#${charNum}</label>
</div>
<div class="control">
<input class="input" type="text" placeholder="e.g. 1,2,5" id="set${charNum - 65}">
</div>
</div>`);
} else {
console.log('You have reached a limint of available sets');
}
}
function DeleteSet(setNum) {
let setField = document.querySelector(`#setfield${setNum}`);
setField.remove();
currNum--;
let delBtn = document.querySelectorAll('#delBtn');
if (delBtn[delBtn.length - 1]) {
delBtn[delBtn.length - 1].style="display: inline-block;";
}
}
let universalSet = new Set();
function Complement (set) {
let _complement = new Set();
_complement = Difference(universalSet, set);
return _complement;
}
function Intersection (set1, set2) {
let _intersection = new Set();
set1.forEach(element => {
if (set2.has(element)) {
_intersection.add(element);
}
});
return _intersection;
}
function Union (set1, set2) {
let _union = new Set(set1);
set2.forEach(element => {
_union.add(element);
});
return _union;
}
function Difference (set1, set2) {
let _difference = new Set(set1);
set2.forEach(element => {
if (_difference.has(element)) {
_difference.delete(element);
}
});
return _difference;
}
const OPERATORS = new Set(['~', '!', '∩', '/', '', '+', '-']);
const BRACKETS = new Set(['(', ')']);
let SETSNAMES = new Set();
let SETS = new Array();
function Evaluate() {
FetchSets();
let formulaString = document.getElementById('formula').value;
let charArray = formulaString.split('');
let RPN_Array = ConvertFormulaCharArrayToRPN(charArray);
let result = SolveRPNFormula(RPN_Array);
let readableResult = ConvertToReadableResult(result);
let resultField = document.getElementById('result');
resultField.value = readableResult;
SETSNAMES.clear();
SETS = new Array();
universalSet = new Set();
}
function ConvertFormulaCharArrayToRPN(chars) {
let setsStack = new Array();
let actionsStack = new Array();
chars.forEach(element => {
if (SETSNAMES.has(element)) {
setsStack.push(GetSetFromIndex(element));
}
if (OPERATORS.has(element)) {
while (GetActionPriority(actionsStack[actionsStack.length - 1]) >= GetActionPriority(element)) {
let last = actionsStack.pop();
if (last != '(') {
setsStack.push(last);
} else {
break;
}
}
if (actionsStack[0] == undefined || GetActionPriority(actionsStack[actionsStack.length - 1]) < GetActionPriority(element)) {
actionsStack.push(element);
}
}
if (BRACKETS.has(element)) {
if (element == '(') {
actionsStack.push(element);
}
if (element == ')') {
let last = actionsStack.pop();
while (last != '(') {
setsStack.push(last);
last = actionsStack.pop();
}
}
}
});
while (actionsStack[0] != undefined) {
setsStack.push(actionsStack.pop());
}
return setsStack;
}
function SolveRPNFormula(RPN_Array) {
let stack = new Array();
for (let i = 0; i < RPN_Array.length; i++) {
const element = RPN_Array[i];
if (OPERATORS.has(element)) {
if (element == '~' || element == '!') {
let currSet = stack.pop();
let result = Complement(currSet);
stack.push(result);
} else if (element == '∩' || element == '/') {
let secondSet = stack.pop();
let firstSet = stack.pop();
let result = Intersection(firstSet, secondSet);
stack.push(result);
} else if (element == '' || element == '+') {
let secondSet = stack.pop();
let firstSet = stack.pop();
let result = Union(firstSet, secondSet);
stack.push(result);
} else if (element == '-') {
let secondSet = stack.pop();
let firstSet = stack.pop();
let result = Difference(firstSet, secondSet);
stack.push(result);
}
} else {
stack.push(element);
}
}
return stack[0];
}
function FetchSets() {
let universalArray = new Array();
for (let i = 0; i < currNum; i++) {
let inputField = document.getElementById(`set${i}`);
let numArray;
if (inputField != undefined && inputField.value.length != 0) {
numArray = inputField.value.split(',');
numArray.sort();
let newSet = new Set();
numArray.forEach(element => {
newSet.add(+element);
universalArray.push(+element);
});
SETSNAMES.add(String.fromCharCode(65 + i));
SETS.push(newSet);
} else {
console.log('[WARNING] Some of the sets are not defined');
}
}
universalSet = new Set(universalArray);
}
function GetSetFromIndex(index) {
let unicode = index.charCodeAt(0);
let num = unicode - 65;
return SETS[num];
}
function GetActionPriority(action) {
if (action == '~' || action == '!') {
return 5;
} else if (action == '∩' || action == '/') {
return 4;
} else if (action == '' || action == '+') {
return 3;
} else if (action == '-') {
return 2;
} else if (action == '(') {
return 1;
} else {
return 0;
}
}
function ConvertToReadableResult(unconverted) {
let converted = Array.from(unconverted).sort().join(', ');
return converted;
}

95
js/lab-3.js Normal file
View File

@ -0,0 +1,95 @@
function GeneratePermutations() {
let permCount = document.querySelector('#permCount');
let permBtn = document.querySelector('#permBtn');
let permProgress = document.querySelector('#permProgress');
let permGenTime = document.querySelector('#permGenTime');
let permGenTimeHolder = document.querySelector('#permGenTimeHolder');
console.clear();
let cycle = 1;
let _elCount = permCount.value;
let a = new Array();
for (let i = 1; i <= _elCount; i++) {
a.push(i);
}
permBtn.style = "display: none;";
permProgress.style = "display: flex;";
permGenTimeHolder.style = "display: none";
date = new Date();
let _startTime = date.getTime();
heapPermutation(a, a.length, a.length);
date = new Date();
let _endTime = date.getTime();
permBtn.style = "display: inline-flex;";
permProgress.style = "display: none;";
permGenTimeHolder.style = "display: flex";
let _timeElapsed = _endTime - _startTime;
permGenTime.innerHTML = `${_timeElapsed} milliseconds elapsed`;
// JavaScript program to print all permutations using
// Heap's algorithm
// Prints the array
function printArr(a, c) {
console.log(a, c);
}
// Generating permutation using Heap Algorithm
function heapPermutation(a,size,n) {
// if size becomes 1 then prints the obtained
// permutation
if (size == 1) {
printArr(a, cycle);
cycle++;
}
for (let i = 0; i < size; i++) {
heapPermutation(a, size - 1, n);
// if size is odd, swap 0th i.e (first) and
// (size-1)th i.e (last) element
if (size % 2 == 1) {
let temp = a[0];
a[0] = a[size - 1];
a[size - 1] = temp;
}
// If size is even, swap ith
// and (size-1)th i.e last element
else {
let temp = a[i];
a[i] = a[size - 1];
a[size - 1] = temp;
}
}
}
}
function factorial(n) {
let fact = 1;
for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}

133
pages/lab-1.html Normal file
View File

@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab-1</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
<script src="../js/lab-1.js"></script>
</head>
<body>
<nav class="navbar is-white">
<div class="navbar-brand">
<a href="../index.html" class="navbar-item">
<!-- <img class="mr-2 py-1" src="assets/cuqmbr.png" alt="Cucumber emoji image"> -->
CDM Utils
<!-- <img class="ml-2 py-1" src="assets/Shchoholev-logo.png" alt="Cucumber emoji image"> -->
</a>
<a class="navbar-burger" id="burger">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div class="navbar-menu" id="nav-links">
<din class="navbar-start">
<a href="../index.html" class="navbar-item">
Home
</a>
</din>
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable" id='dropdown'>
<a class="navbar-link">
Introduction. Set Theory
</a>
<div class="navbar-dropdown">
<a href="lab-1.html" class="navbar-item">
Set Algebra
</a>
</div>
</div>
</div>
</div>
</nav>
<script src="../js/index.js"></script>
<div class="columns gapless my-0 has-background-success is-multiline">
<div class="column is-6-desktop is-12-tablet py-0">
<section class="hero is-fullheight-with-navbar">
<div class="hero-body">
<div class="container">
<p class="title has-text-white">Set Operations</p>
<p class="subtitle has-text-white">Simple implementation of different set operations, such as: Complement, Union, Intersection and Difference</p>
</div>
</div>
</section>
</div>
<div class="column is-6-desktop is-12-tablet">
<div class="container">
<section class="hero is-fullheight-with-navbar">
<div class="hero-body">
<div class="container">
<form class="box">
<div class="has-text-centered">
<input type="button" class="button is-info" value="Add new Set" onclick="AddSet();">
</div>
<div class="pb-3" id="sets">
<div class="field">
<label class="label">Set A</label>
<div class="control">
<input class="input" type="text" placeholder="e.g. 1,2,5" id="set0">
</div>
</div>
<div class="field">
<label class="label">Set B</label>
<div class="control">
<input class="input" type="text" placeholder="e.g. 5,6,7" id="set1">
</div>
</div>
</div>
<div class="field">
<label class="label">Formula</label>
<div class="control">
<input class="input" type="text" placeholder="e.g. (A+!B)/C" id="formula">
</div>
</div>
<div class="has-text-centered">
<input type="button" class="button is-info" value="Evaluate" onclick="Evaluate();">
</div>
<div class="field">
<label class="label">Result</label>
<div class="control">
<input class="input" type="text" placeholder="" readonly id="result">
</div>
</div>
</form>
</div>
</div>
</section>
</div>
</div>
</div>
<!--<div class="columns gapless my-0 py-5 has-background-success is-mobile">
<div class="column is-3-desktop is-2-tablet is-1-mobile"></div>
<div class="column is-6-desktop is-8-tablet is-10-mobile">
</div>
<div class="column is-3-desktop is-2-tablet is-1-mobile"></div>
</div>-->
</body>
</html>

14
pages/lab-2.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>

148
pages/lab-3.html Normal file
View File

@ -0,0 +1,148 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab-1</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
<script src="../js/lab-3.js"></script>
<style>
.center {
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<nav class="navbar is-white">
<div class="navbar-brand">
<a href="../index.html" class="navbar-item">
<!-- <img class="mr-2 py-1" src="assets/cuqmbr.png" alt="Cucumber emoji image"> -->
CDM Utils
<!-- <img class="ml-2 py-1" src="assets/Shchoholev-logo.png" alt="Cucumber emoji image"> -->
</a>
<a class="navbar-burger" id="burger">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div class="navbar-menu" id="nav-links">
<din class="navbar-start">
<a href="../index.html" class="navbar-item">
Home
</a>
</din>
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable" id='dropdown'>
<a class="navbar-link">
Introduction. Set Theory
</a>
<div class="navbar-dropdown">
<a href="lab-1.html" class="navbar-item">
Set Algebra (Lab 1)
</a>
</div>
</div>
</div>
</div>
</nav>
<script src="../js/index.js"></script>
<div class="columns gapless my-0 has-background-success">
<div class="column is-8-desktop is-12-tablet py-0">
<section class="hero is-fullheight-with-navbar">
<div class="hero-body">
<div class="container">
<p class="title has-text-white">Lab 3 - Generating permutations and combinations</p>
<p class="subtitle has-text-white">Simple implementation of algorithms for generating permutations and combinations of some set. A built in timer included in order to make your research much more pleasent and faster</p>
</div>
</div>
</section>
</div>
</div>
<div class="columns gapless my-0 has-background-success is-multiline is-mobile">
<div class="column is-1"></div>
<div class="column mb-2 is-4-desktop is-10-tablet is-10-mobile">
<div class="container">
<form class="box">
<div class="has-text-centered mb-2">
<label class="title is-4">Permutations Generator</label>
</div>
<div class="pb-3" id="sets">
<div class="field">
<label class="label">Number of elements in set</label>
<div class="control">
<input class="input" type="text" placeholder="e.g. 5" id="permCount">
</div>
</div>
</div>
<div class="has-text-centered">
<input type="button" class="button is-info" value="Generate" onclick="GeneratePermutations()" id="permBtn">
<progress class="progress is-small is-info" id="permProgress" style="display: none;"></progress>
</div>
<div class="has-text-centered mt-3" id="permGenTimeHolder" style="display: none;">
<p id="permGenTime" style="margin: auto;">Time elapsed: 125623 milliseconds</p>
</div>
</form>
</div>
</div>
<div class="column is-1"></div>
<div class="column is-1"></div>
<div class="column mt-2 is-4-desktop is-10-tablet is-10-mobile">
<div class="container">
<form class="box">
<div class="has-text-centered mb-2">
<label class="title is-4">Combinations Generator</label>
</div>
<div class="pb-3" id="sets">
<div class="field">
<label class="label">Number of elements in set</label>
<div class="control">
<input class="input" type="text" placeholder="e.g. 5" id="permCount">
</div>
</div>
</div>
<div class="has-text-centered">
<input type="button" class="button is-info" value="Generate" onclick="GeneratePermutations()" id="permBtn">
<progress class="progress is-small is-info" id="permProgress" style="display: none;"></progress>
</div>
<div class="has-text-centered mt-3" id="permGenTimeHolder" style="display: none;">
<p id="permGenTime" style="margin: auto;">Time elapsed: 125623 milliseconds</p>
</div>
</form>
</div>
</div>
<div class="column is-1"></div>
</div>
</body>
</html>