Skip to content

Commit

Permalink
add exercise6
Browse files Browse the repository at this point in the history
  • Loading branch information
talgat-ruby committed Nov 14, 2023
1 parent eeb4cd9 commit 0c596e0
Show file tree
Hide file tree
Showing 81 changed files with 4,735 additions and 0 deletions.
70 changes: 70 additions & 0 deletions exercise6/sortOut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// const groups = ["Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff"];
const groups = ["1", "2", "3", "4", "5", "6", "7", "8"];

const participants = [
"Gulfia",
"Kanat",
"Rash",
"Alisher",
"Samat",
"Kuanyshbek",
"Bibigul",
"Yerzhan",
"Beksultan",
"Danial",
"Zarina",
"Aituar",
"Duman",
"Kazybek",
"Ilyas",
"Daniyar",
"Yedil",
"Anastasia",
];

function sortOut() {
const randomParticipants = randomize(participants);
const groupsWithParticipants = sortToGroups(groups, randomParticipants);

console.log(
groupsWithParticipants
.map(({ name, participants }) => `${name}: ${participants.join(", ")}`)
.join("\n")
);
}

function randomize(strs: string[]) {
const randomParticipants = [];
let newParticipants = [...strs];

while (newParticipants.length > 0) {
const ind = getRandomInt(newParticipants.length);
randomParticipants.push(newParticipants[ind]);
newParticipants = [
...newParticipants.slice(0, ind),
...newParticipants.slice(ind + 1),
];
}

return randomParticipants;
}

function sortToGroups(groups: string[], participants: string[]) {
const sorted = groups.map<{ name: string; participants: string[] }>(
(group) => ({ name: group, participants: [] })
);

for (let i = 0; i < participants.length; i++) {
const ind = i % groups.length;
sorted[ind].participants.push(participants[i]);
}

return sorted;
}

function getRandomInt(max: number) {
max = Math.floor(max);
return Math.floor(Math.random() * max); // The maximum is exclusive
}

sortOut();
33 changes: 33 additions & 0 deletions exercise6/tic-tac-toe-bot/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {}
}
24 changes: 24 additions & 0 deletions exercise6/tic-tac-toe-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions exercise6/tic-tac-toe-bot/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
5 changes: 5 additions & 0 deletions exercise6/tic-tac-toe-bot/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: ["prettier-plugin-tailwindcss"],
tailwindConfig: "./tailwind.config.js",
tailwindFunctions: ["twMerge", "tailwind-merge"],
};
21 changes: 21 additions & 0 deletions exercise6/tic-tac-toe-bot/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Talgat Sarybaev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions exercise6/tic-tac-toe-bot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<link href="/favicon.ico" rel="icon" type="image/x-icon"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<script src="/src/index.ts" type="module"></script>
<title>Tic-tac-toe</title>
</head>
<body>
<div class="flex min-h-screen justify-center bg-white dark:bg-gray-900" id="app"></div>
</body>
</html>
Loading

0 comments on commit 0c596e0

Please sign in to comment.