diff --git a/main.js b/main.js
index dab03cd..9ca580a 100644
--- a/main.js
+++ b/main.js
@@ -1,12 +1,9 @@
-// const Swal = require("sweetalert2");
-// import Swal from "sweetalert2";
-
-function tags() {
- const tags_list = [
+const tags_list = [
"2-sat",
"binary search",
"bitmasks",
"brute force",
+ "chinese remainder theorem ",
"combinatorics",
"constructive algorithms",
"data structures",
@@ -16,7 +13,7 @@ function tags() {
"dsu",
"expression parsing",
"fft",
- "flow",
+ "flows",
"games",
"geometry",
"graph matchings",
@@ -27,172 +24,229 @@ function tags() {
"interactive",
"math",
"matrices",
+ "meet-in-the-middle",
"number theory",
- "probability",
+ "probabilities",
"schedules",
- "shortest path",
- "sorting",
+ "shortest paths",
+ "sortings",
+ "string suffix structures ",
"strings",
"ternary search",
"trees",
"two pointers",
- ];
+];
- let needed_html = "";
+const green = "rgb(51, 172, 113)";
+const blue = "rgb(0, 188, 212)";
- tags_list.forEach((tag) => {
- needed_html += ``;
- });
+function tags() {
+ let needed_html = "";
- return needed_html;
+ tags_list.forEach((tag) => {
+ needed_html += ``;
+ });
+
+ return needed_html;
}
window.addEventListener("load", () => {
- document.getElementsByClassName("tags-container")[0].innerHTML = tags();
-
- let btns = document.getElementsByClassName("tag-btn");
- const green = "rgb(51, 172, 113)";
- const blue = "rgb(0, 188, 212)";
+ document.getElementsByClassName("tags-container")[0].innerHTML = tags();
- for (let i = 0; i < btns.length; i++) {
- let element = btns[i];
+ let btns = document.getElementsByClassName("tag-btn");
- element.style.backgroundColor = blue;
+ for (let i = 0; i < btns.length; i++) {
+ let element = btns[i];
- element.addEventListener("click", () => {
- if (element.style.backgroundColor == blue) {
- // Include
- element.style.backgroundColor = green;
- } else {
- // Exclude
element.style.backgroundColor = blue;
- }
- });
- }
+
+ element.addEventListener("click", () => {
+ if (element.style.backgroundColor == blue) {
+ // Include
+ element.style.backgroundColor = green;
+ } else {
+ // Exclude
+ element.style.backgroundColor = blue;
+ }
+ });
+ }
});
-async function valid(handle) {
- const url = `https://codeforces.com/api/user.info?handles=${handle}`;
+async function http_request(url) {
+ let response = await fetch(url);
+ let data = await response.json();
- const instance = axios.create({
- baseURL: url,
- });
+ return data;
+}
- instance.interceptors.response.use(
- (response) => {
- return response;
- },
- (error) => {
- if (error.response.status === 400) {
- return false;
- }
- return Promise.reject(error);
- }
- );
+async function valid_handle(handle) {
+ let data = await http_request(`https://codeforces.com/api/user.info?handles=${handle}`);
- try {
- const response = await axios.get(url);
- const data = response.data;
- console.log(data);
- return true;
- // if (response.status === 400) return false;
- // else return true;
- } catch (error) {
- console.log(error);
- return false;
- }
-
- return true;
+ if (data['status'] === 'FAILED') return false;
+ else return true;
}
function add_handle(handle) {
- // if (document.getElementsByClassName('accepted-handles').length === 0) {
- // document.getElementsByClassName('handles-container')[0].innerHTML +=
- // '
';
- // }
-
- document.getElementsByClassName(
- "accepted-handles"
- )[0].innerHTML += `
+ document.getElementsByClassName(
+ "accepted-handles"
+ )[0].innerHTML += `
${handle}
Click to remove
`;
- document.getElementById("handles").value = "";
+ document.getElementById("handles").value = "";
- let acc_handles = document.getElementsByClassName("accepted-handle tooltip");
+ let acc_handles = document.getElementsByClassName("accepted-handle tooltip");
- for (let i = 0; i < acc_handles.length; i++) {
- acc_handles[i].addEventListener("click", (element) => {
- // if (document.getElementsByClassName('accepted-handle tooltip').length === 1)
- // document.getElementsByClassName('accepted-handles')[0].remove();
- // else
- element.srcElement.remove();
- });
- }
+ for (let i = 0; i < acc_handles.length; i++) {
+ acc_handles[i].addEventListener("click", (element) => {
+ element.srcElement.remove();
+ });
+ }
}
document
- .getElementsByClassName("add-handle-btn")[0]
- .addEventListener("click", () => {
- const handle = document.getElementById("handles").value;
-
- if (handle === "")
- Swal.fire({
- icon: "error",
- title: "Oops...",
- text: "Please Enter a handle!",
- });
- else if (!valid(handle)) {
- Swal.fire({
- icon: "error",
- title: "Oops...",
- text: "Please Enter a valid handle!",
- });
- } else add_handle(handle);
- });
+ .getElementsByClassName("add-handle-btn")[0]
+ .addEventListener("click", () => {
+ const handle = document.getElementById("handles").value;
+
+ if (handle === "")
+ Swal.fire({
+ icon: "error",
+ title: "Oops...",
+ text: "Please Enter a handle!",
+ });
+ else if (!valid_handle(handle))
+ Swal.fire({
+ icon: "error",
+ title: "Oops...",
+ text: "Please Enter a valid handle!",
+ });
+ else add_handle(handle);
+ });
function validate_input() {
- let [from, to, problems_cnt] =
+ let [from, to, problems_cnt] =
document.getElementsByClassName("another-class");
- from = +from.value;
- to = +to.value;
- problems_cnt = +problems_cnt.value;
+ from = +from.value;
+ to = +to.value;
+ problems_cnt = +problems_cnt.value;
+
+ if (from % 100 !== 0 || to % 100 !== 0 || from > to) {
+ Swal.fire({
+ icon: "error",
+ title: "Oops...",
+ text: "Please Enter a valid ratings!",
+ });
+ return false;
+ } else if (from > 3500 || from < 800 || to > 3500 || to < 800) {
+ Swal.fire({
+ icon: "error",
+ title: "Oops...",
+ text: "Please Enter a valid rating boundaries (800 - 3500)!",
+ });
+ return false;
+ } else if (problems_cnt < 1 || problems_cnt > 50) {
+ Swal.fire({
+ icon: "error",
+ title: "Oops...",
+ text: "Enter a valid number of problems (1 - 50)!",
+ });
+ return false;
+ } else return true;
+}
- if (from % 100 !== 0 || to % 100 !== 0 || from > to) {
- Swal.fire({
- icon: "error",
- title: "Oops...",
- text: "Please Enter a valid ratings!",
+function valid_problem(problem, min, max, problems_out_of_scope, chosen_tags) {
+ problems_out_of_scope.forEach((element) => {
+ if (element === problem['name'])
+ return false;
});
- return false;
- } else if (from > 3500 || from < 800 || to > 3500 || to < 800) {
- Swal.fire({
- icon: "error",
- title: "Oops...",
- text: "Please Enter a valid rating boundaries (800 - 3500)!",
+
+ let rate = (problem['rating'] !== undefined ? problem['rating'] : 0);
+
+ if (rate < min || rate > max)
+ return false;
+
+ problem['tags'].forEach((tag) => {
+ if (!chosen_tags.has(tag))
+ return false;
});
- return false;
- } else if (problems_cnt < 1 || problems_cnt > 50) {
- Swal.fire({
- icon: "error",
- title: "Oops...",
- text: "Enter a valid number of problems (1 - 50)!",
+
+ return true;
+}
+
+function shuffle(available_problems) {
+ return available_problems;
+}
+
+async function get_problems() {
+ let not_solved_by = [];
+ let acc_handles = document.getElementsByClassName("accepted-handle tooltip");
+
+ for (let i = 0; i < acc_handles.length; i++) {
+ not_solved_by.push(acc_handles[i].innerText);
+ }
+
+ let problems_out_of_scope = new Set();
+
+ not_solved_by.forEach(async (handle) => {
+ let url = `https://codeforces.com/api/user.status?handle={handle}`
+ let submissions = await http_request(url);
+ submissions['result'].forEach((submission) => {
+ if (submission['verdict'] === 'OK')
+ problems_out_of_scope.add(submission['problem']['name']);
+ });
+ });
+
+ console.log(problems_out_of_scope);
+
+ let chosen_tags = new Set();
+
+ let all_tags = document.getElementsByClassName("tag-btn");
+ for (let i = 0; i < all_tags.length; i++) {
+ if (all_tags[i].style.backgroundColor === green)
+ chosen_tags.add(all_tags[i].innerText);
+ }
+
+ if (chosen_tags.size === 0)
+ chosen_tags = new Set(tags_list);
+
+ let problemset = await http_request('https://codeforces.com/api/problemset.problems');
+ let available_problems = [];
+ let [from, to] = document.getElementsByClassName("another-class");
+
+ from = +from.value;
+ to = +to.value;
+
+ let min = Math.max(800, from);
+ let max = Math.min(3500, to);
+
+ problemset['result']['problems'].forEach((problem) => {
+ if (valid_problem(problem, min, max, problems_out_of_scope, chosen_tags))
+ available_problems.push(problem);
});
- return false;
- } else return true;
+
+ // available_problems = shuffle(available_problems);
+
+ let problems_cnt = +(document.getElementsByClassName("another-class")[2].value);
+
+ let final_problems = available_problems.slice(0, problems_cnt);
+
+ console.log(final_problems);
+
+ return final_problems;
}
-function get_problems() {}
+function view_problems(problems) {
-function view_problems() {}
+}
document.getElementsByClassName("gen-btn")[0].addEventListener("click", () => {
- if (validate_input() === true) {
- let problems = get_problems();
- view_problems();
- }
-});
+ if (validate_input() === true) {
+ let problems = get_problems();
+ view_problems(problems);
+ }
+});
\ No newline at end of file