├── challenges ├── README.md ├── dictionary_from_trie_C++.md ├── Sudoku-BackTracking-C++.md └── tic-tac-toe-C++.md ├── snippets ├── c │ ├── README.md │ └── Diamond_Pattern │ │ ├── Output.png │ │ └── Diamond_Square.md ├── c++ │ ├── README.md │ ├── Diamond_Square │ │ ├── rows_6.png │ │ └── diamondSquare.md │ ├── Emerging_Rainbow │ │ ├── Rainbow_gif.gif │ │ └── Emerging_Rainbow.md │ ├── count_frequency.md │ ├── fizzbuzz.md │ ├── LongestCommonSubsequence.md │ └── RecursiveFibonacciWithMemoization.md ├── java │ ├── README.md │ ├── Diamond_Square │ │ ├── output.png │ │ └── diamondSquare.md │ ├── fizzbuzz.md │ ├── charFreqCount.md │ ├── LongestCommonSubsequence.md │ └── Flames_Game.md ├── python │ ├── README.md │ ├── Diamond_Square │ │ ├── Output.png │ │ └── Diamond_Square.md │ ├── rgbtohex.md │ ├── Fizzbuzz.md │ ├── unpacking.md │ ├── FaceDetector │ │ └── FaceDetector.md │ ├── count_frequency.md │ ├── tablularformatting.md │ ├── Longest_common_subsequence.md │ ├── flamesGame.md │ ├── caesar_cipher.md │ ├── dictionary_using_trie_python.md │ └── tic_tac_toe_game_using_python.md ├── typescript │ ├── README.md │ └── frequencyOfCharacters.md └── webdev │ └── README.md ├── resources.md ├── .github ├── ISSUE_TEMPLATE.md ├── workflows │ └── greetings.yml └── PULL_REQUEST_TEMPLATE.md ├── LICENSE ├── CONTRIBUTING.md ├── README.md └── CODE_OF_CONDUCT.md /challenges/README.md: -------------------------------------------------------------------------------- 1 | # Coding Challenges -------------------------------------------------------------------------------- /snippets/c/README.md: -------------------------------------------------------------------------------- 1 | # Cool C Snippets 2 | 3 | C code snippets 4 | 5 | Go through CONTRIBUTING.md to start contributing! -------------------------------------------------------------------------------- /snippets/c++/README.md: -------------------------------------------------------------------------------- 1 | # Cool C++ Snippets 2 | 3 | C++ code snippets 4 | 5 | Go through CONTRIBUTING.md to start contributing! -------------------------------------------------------------------------------- /snippets/java/README.md: -------------------------------------------------------------------------------- 1 | # Cool Java Snippets 2 | 3 | Java code snippets 4 | 5 | Go through CONTRIBUTING.md to start contributing! -------------------------------------------------------------------------------- /snippets/python/README.md: -------------------------------------------------------------------------------- 1 | # Cool Python Snippets 2 | 3 | Python code snippets 4 | 5 | Go through CONTRIBUTING.md to start contributing! -------------------------------------------------------------------------------- /snippets/typescript/README.md: -------------------------------------------------------------------------------- 1 | # Cool TypeScript Snippets 2 | 3 | TypeScript code snippets 4 | 5 | Go through CONTRIBUTING.md to start contributing! -------------------------------------------------------------------------------- /snippets/c/Diamond_Pattern/Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Students-Club-MAIT/cool_code_snippets/HEAD/snippets/c/Diamond_Pattern/Output.png -------------------------------------------------------------------------------- /snippets/c++/Diamond_Square/rows_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Students-Club-MAIT/cool_code_snippets/HEAD/snippets/c++/Diamond_Square/rows_6.png -------------------------------------------------------------------------------- /snippets/java/Diamond_Square/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Students-Club-MAIT/cool_code_snippets/HEAD/snippets/java/Diamond_Square/output.png -------------------------------------------------------------------------------- /snippets/python/Diamond_Square/Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Students-Club-MAIT/cool_code_snippets/HEAD/snippets/python/Diamond_Square/Output.png -------------------------------------------------------------------------------- /snippets/c++/Emerging_Rainbow/Rainbow_gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Students-Club-MAIT/cool_code_snippets/HEAD/snippets/c++/Emerging_Rainbow/Rainbow_gif.gif -------------------------------------------------------------------------------- /snippets/webdev/README.md: -------------------------------------------------------------------------------- 1 | # Cool HTML, CSS and Javascript Snippets 2 | 3 | Add HTML, CSS and Javascript code snippets! 4 | 5 | Go through CONTRIBUTING.md to start contributing! -------------------------------------------------------------------------------- /resources.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | Here is a list of resources for learning that are useful for developers. Create a pull request adding a great resource along with a one line description. 4 | 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | Please include a brief summary of what the issue is all about. 4 | 5 | ## Language 6 | 7 | - [ ] C++: @ 8 | - [ ] Java: @ 9 | - [ ] Python: @ 10 | - [ ] Other (Please specify) 11 | 12 | ## Type of issue 13 | 14 | - [ ] Feature 15 | - [ ] Bug 16 | 17 | The checklist will be updated by the maintainers / author of this issue according to the language in which snippets are added or are proposed to be added. 18 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: Congrats for creating your first issue here! Wait till our mentors assign this issue to you. Meanwhile have a look at contribution guidlines to avoid PR rejection! 13 | -------------------------------------------------------------------------------- /snippets/python/rgbtohex.md: -------------------------------------------------------------------------------- 1 | # RGB to Hex value conversion 2 | 3 | ## Code 4 | 5 | ```python 6 | def rgb_to_hex(r, g, b): 7 | return ("{:02X}" * 3).format(r, g, b) 8 | 9 | print("The hex value for RGB values (100, 255, 167) = #" + rgb_to_hex(100, 255, 167)) 10 | ``` 11 | 12 | ## Output 13 | 14 | ``` 15 | The hex value for RGB values (100, 255, 167) = #64FFA7 16 | ``` 17 | 18 | --- 19 | 20 | ## Contributed By 21 | 22 | | Name | GitHub Username | Institute | 23 | | --- | --- | --- | 24 | | Saksham Arora | sakshamarora1 | Maharaja Agrasen Institute of Technology | 25 | 26 | -------------------------------------------------------------------------------- /snippets/python/Fizzbuzz.md: -------------------------------------------------------------------------------- 1 | # Fizzbuzz 2 | 3 | ## Code 4 | 5 | ```python 6 | def fizzbuzz(): 7 | for num in range(1, 101): 8 | fizz = 'Fizz' if num % 3 == 0 else '' 9 | buzz = 'Buzz' if num % 5 == 0 else '' 10 | print(f'{fizz}{buzz}') if fizz or buzz else print(num) 11 | 12 | fizzbuzz() 13 | ``` 14 | 15 | ## Output 16 | 17 | ``` 18 | 1 19 | 2 20 | Fizz 21 | . 22 | . 23 | 98 24 | Fizz 25 | Buzz 26 | ``` 27 | 28 | ## Contributed By 29 | 30 | | Name | GitHub Username | Institute | 31 | | --- | --- | --- | 32 | | Uday A S | ItIsUday | RV College of Engineering | 33 | -------------------------------------------------------------------------------- /snippets/python/Diamond_Square/Diamond_Square.md: -------------------------------------------------------------------------------- 1 | # Diamond Square 2 | 3 | ## Description 4 | A Program to print the Diamond Sqaure Pattern. The rows count is given as a input which denotes the longest row in the pattern. 5 | 6 | ## Code 7 | ```python 8 | n = int(input("Enter the rows count:")) 9 | 10 | # The Top Pyramid 11 | for i in range(n): 12 | space = " " * (n - i - 1) 13 | star = (2 * i) * "* " + "*" 14 | print(space + star) 15 | 16 | # The bottom Pyramid 17 | for i in range(n): 18 | space = " " * (i) 19 | star = star[:-4] 20 | print(" " + space + star) 21 | ``` 22 | 23 | ## Output 24 | 25 | ![Code Output](./Output.png) 26 | 27 | ## Contributed By 28 | 29 | | Name | GitHub Username | Institute | 30 | | --- | --- | --- | 31 | | Biraj De | BirajCoder | Future Institute of Engineering and Management, Kolkata | -------------------------------------------------------------------------------- /snippets/python/unpacking.md: -------------------------------------------------------------------------------- 1 | # Unpacking list/tuples 2 | 3 | ## Code 4 | 5 | ```python 6 | names = ["Messi", "Muller", "Lewandowski", "Kevin", "Ramos", "Mbappe", "Neymar", "Ronaldo"] 7 | 8 | messi, *footballers, ronaldo = names 9 | 10 | print(messi + " plays for Barcelona.") 11 | print(ronaldo + " plays for Juventus.\n") 12 | 13 | print(*footballers, sep=", ", end=" ") 14 | print("are some of the top football players.", sep="") 15 | ``` 16 | 17 | ## Output 18 | 19 | ``` 20 | Messi plays for Barcelona. 21 | Ronaldo plays for Juventus. 22 | 23 | Muller, Lewandowski, Kevin, Ramos, Mbappe, Neymar are some of the top football players. 24 | ``` 25 | 26 | --- 27 | 28 | ## Contributed By 29 | 30 | | Name | GitHub Username | Institute | 31 | | --- | --- | --- | 32 | | Saksham Arora | sakshamarora1 | Maharaja Agrasen Institute of Technology | 33 | 34 | -------------------------------------------------------------------------------- /snippets/c++/Diamond_Square/diamondSquare.md: -------------------------------------------------------------------------------- 1 | # Diamond Square 2 | 3 | ## Code 4 | 5 | ```C++ 6 | int main() 7 | { 8 | int n; 9 | cout << "Enter the number of rows : "; 10 | cin >> n; 11 | 12 | int i, j; 13 | for(i = 0 ; i < n ; i++) { 14 | for(j = i ; j < n-1 ; j++) 15 | cout << " "; 16 | for(j = 0 ; j < i*2+1 ; j++) 17 | cout << "*"; 18 | cout << endl; 19 | } 20 | for(i = n-1 ; i > 0 ; i--) { 21 | for(j = i ; j < n ; j++ ) 22 | cout << " "; 23 | for(j = 0 ; j < i*2-1 ; j++ ) 24 | cout << "*"; 25 | cout << endl; 26 | } 27 | return 0; 28 | } 29 | ``` 30 | 31 | ## Output 32 | 33 | ![Diamond image](rows_6.png?raw=true "Diamond(row=6)") 34 | 35 | ## Contributed By 36 | 37 | | Name | GitHub Username | 38 | | --- | --- | 39 | | Srijita | SrijitaSarkar99 | 40 | -------------------------------------------------------------------------------- /snippets/c++/Emerging_Rainbow/Emerging_Rainbow.md: -------------------------------------------------------------------------------- 1 | # Emerging Rainbow 2 | ## Description 3 | This code is about making a rainbow emerge from time=0 seconds. 4 | ## Langauge 5 | C++ 6 | ## Code 7 | ```C++ 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | int main() 13 | { 14 | int gdriver = DETECT,gmode; 15 | int x,y,i; 16 | 17 | initgraph(&gdriver,&gmode,"C:\\TC\\BIN"); 18 | x=getmaxx()/2; 19 | y=getmaxy()/2; 20 | 21 | for(i=30;i<200;i++) 22 | { 23 | delay(100); 24 | setcolor(i/10); 25 | arc(x,y,0,180,i-10); 26 | } 27 | return 0; 28 | } 29 | ``` 30 | ## Output 31 | ![Rainbow Gif](https://github.com/einhawking/cool_code_snippets/blob/master/snippets/c%2B%2B/Emerging_Rainbow/Rainbow_gif.gif) 32 | ## Contributed By 33 | |Name|Github Username|College Name| 34 | |---|---|---| 35 | |Shreya Garg|einhawking|Maharaja Agrasen Institute of Technology| 36 | -------------------------------------------------------------------------------- /snippets/python/FaceDetector/FaceDetector.md: -------------------------------------------------------------------------------- 1 | # Face Detection Using Opencv 2 | ## Code 3 | 4 | ```python 5 | import cv2 6 | cap = cv2.VideoCapture(0) 7 | classifier = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") # xml file is provided in the folder 8 | 9 | while True: 10 | 11 | ret, frame = cap.read() 12 | if ret: 13 | faces = classifier.detectMultiScale(frame) 14 | 15 | for face in faces: 16 | x, y, w, h = face 17 | frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 4) 18 | cv2.imshow("My window", frame) 19 | key = cv2.waitKey(1) 20 | 21 | if key == ord("q"): 22 | break 23 | 24 | cap.release() 25 | cv2.destroyAllWindows() 26 | ``` 27 | 28 | ## Output 29 | 30 | 31 | ## Contributed By 32 | 33 | | Name | GitHub Username | Institute | 34 | | --- | --- | --- | 35 | | Shitiz Aggarwal | SHITIZ-AGGARWAL | Maharaja Agrasen Institute of Technology | 36 | -------------------------------------------------------------------------------- /snippets/python/count_frequency.md: -------------------------------------------------------------------------------- 1 | # Count frequency of unique characters in a string 2 | 3 | ## Code 4 | ```python 5 | from collections import Counter 6 | 7 | # Input string 8 | string = input("Enter string: ") 9 | 10 | # Keeps count of frequency of each character 11 | frequency = Counter(string) 12 | 13 | # Write frequency to frequency.txt file 14 | with open("frequency.txt", "w") as file: 15 | for char in frequency: 16 | file.write(f"Frequency of {char}: {frequency[char]}\n") 17 | ``` 18 | 19 | ## Description 20 | Counter(a `dict` subclass) is a collection where elements are stored as dictionary keys and their counts are stored as dictionary values. [See docs](https://docs.python.org/3/library/collections.html#collections.Counter) 21 | 22 | ## Input 23 | ``` 24 | Enter string: aabbc 25 | ``` 26 | 27 | ## Output 28 | ``` 29 | $ cat frequency.txt 30 | 31 | Frequency of a: 2 32 | Frequency of b: 2 33 | Frequency of c: 1 34 | ``` 35 | 36 | ## Contributed By 37 | 38 | | Name | GitHub Username | Institute | 39 | | --- | --- | --- | 40 | | Yogesh Singh | yogeshsingh101200 | Maharaja Surajmal Institute of Technology | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Developer-Students-Club-MAIT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /snippets/c/Diamond_Pattern/Diamond_Square.md: -------------------------------------------------------------------------------- 1 | # Diamond Square 2 | 3 | ## Description 4 | A Program to print the Diamond Sqaure Pattern. The rows count is given as a input which denotes the longest row in the pattern. 5 | 6 | ## Code 7 | ```c 8 | #include 9 | void main(){ 10 | int temp; 11 | printf("\nEnter the rows count: "); 12 | scanf("%d",&temp); 13 | int n=2*temp-1; 14 | 15 | // The Top Pyramid 16 | for(int i=0;ii;j--){ 18 | printf(" "); 19 | } 20 | for(int j=0;j<2*i+1;j++){ 21 | printf("* "); 22 | } 23 | printf("\n"); 24 | } 25 | 26 | //The bottom Pyramid 27 | for(int i=n/2;i>=0;i--){ 28 | for(int j=n/2;j>i;j--){ 29 | printf(" "); 30 | } 31 | for(int j=0;j<2*i+1;j++){ 32 | printf("* "); 33 | } 34 | printf("\n"); 35 | } 36 | } 37 | ``` 38 | 39 | ## Output 40 | 41 | ![Code Output](./Output.png) 42 | 43 | ## Contributed By 44 | 45 | | Name | GitHub Username | Institute | 46 | | --- | --- | --- | 47 | | Arnab Bhakta | arnab031 | Future Institute of Engineering and Management, Kolkata | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Title/Heading 2 | 3 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. 4 | 5 | Fixes: # (issue) 6 | 7 | ## Type of change 8 | 9 | Please delete options that are not relevant. (including this line) 10 | 11 | - [ ] Bug fix (non-breaking change which fixes an issue) 12 | - [ ] New feature (non-breaking change which adds functionality) 13 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 14 | - [ ] This change requires a documentation update 15 | 16 | # Checklist: 17 | 18 | - [ ] My code follows the style guidelines of this project 19 | - [ ] I have performed a self-review of my own code 20 | - [ ] I have commented my code, particularly in hard-to-understand areas 21 | - [ ] I have made corresponding changes to the documentation 22 | - [ ] My changes generates no new warnings 23 | - [ ] I have added tests that prove my fix is effective or that my feature works 24 | - [ ] New and existing unit tests pass locally with my changes 25 | - [ ] Any dependent changes have been merged and published in downstream modules 26 | -------------------------------------------------------------------------------- /snippets/c++/count_frequency.md: -------------------------------------------------------------------------------- 1 | # Count frequency of unique characters in a string 2 | 3 | ## Code 4 | ```cpp 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(void) 11 | { 12 | std::string str; 13 | 14 | // Input string 15 | std::cout << "Enter string: "; 16 | getline(std::cin, str); 17 | 18 | // Keeps count of frequency 19 | int freq[26] = {0}; 20 | for (char c : str) 21 | { 22 | freq[tolower(c) - 'a'] += 1; 23 | } 24 | 25 | // Writes frequency to file 26 | std::ofstream fout("frequency.txt"); 27 | for (int i = 0; i < 26; ++i) 28 | { 29 | if (freq[i]) 30 | fout << "Frequency of " << (char)(i + 'a') << " : " << freq[i] << "\n"; 31 | } 32 | 33 | // Closing file 34 | fout.close(); 35 | 36 | return 0; 37 | } 38 | ``` 39 | 40 | ## Input 41 | ``` 42 | Enter string: eezzfhhaaa 43 | ``` 44 | 45 | ## Output 46 | ``` 47 | $ cat frequency.txt 48 | 49 | Frequency of a : 3 50 | Frequency of e : 2 51 | Frequency of f : 1 52 | Frequency of h : 2 53 | Frequency of z : 2 54 | ``` 55 | 56 | ## Contributed By 57 | 58 | | Name | GitHub Username | Institute | 59 | | --- | --- | --- | 60 | | Shivam Porwal | ShivamPorwal02 | Maharaja Surajmal Institute of Technology | -------------------------------------------------------------------------------- /snippets/c++/fizzbuzz.md: -------------------------------------------------------------------------------- 1 | # Fizzbuzz 2 | 3 | ## Code 4 | 5 | ```C++ 6 | int main(void) 7 | { 8 | int i; 9 | for (i=1; i<=100; i++) 10 | { 11 | if (i%15 == 0) 12 | cout<<"FizzBuzz "; 13 | else if ((i%3) == 0) 14 | cout<<"Fizz "; 15 | else if ((i%5) == 0) 16 | cout<<"Buzz "; 17 | else 18 | cout< 0 and j > 0: 29 | 30 | if string1[i-1] == string2[j-1]: 31 | lcs_algo[idx-1] = string1[i-1] 32 | i -= 1 33 | j -= 1 34 | idx -= 1 35 | 36 | elif L[i-1][j] > L[i][j-1]: 37 | i -= 1 38 | else: 39 | j -= 1 40 | 41 | print("LCS: " + "".join(lcs_algo)) 42 | 43 | 44 | string1 = input("Enter string1: ") 45 | 46 | string2 = input("Enter string2: ") 47 | 48 | lcs(string1,string2) 49 | ``` 50 | 51 | ## Output 52 | 53 | ``` 54 | Enter String1: ACADB 55 | 56 | Enter String2: CBDA 57 | 58 | LCS: CB 59 | ``` 60 | ## Contributed By 61 | 62 | | Name | GitHub Username | Institute | 63 | | --- | --- | --- | 64 | | Shivam Porwal | ShivamPorwal02 | Maharaja Surajmal Institute of Technology | -------------------------------------------------------------------------------- /snippets/c++/LongestCommonSubsequence.md: -------------------------------------------------------------------------------- 1 | # Longest Common Subsequence 2 | 3 | ## Code 4 | 5 | ```C++ 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int findmax( int a, int b) 12 | { 13 | return a > b ? a : b; 14 | } 15 | 16 | void lcs( char *str1, char *str2, int m, int n ) 17 | { 18 | int L[m+1][n+1]; 19 | 20 | for (int i=0; i<=m; i++) 21 | { 22 | for (int j=0; j<=n; j++) 23 | { 24 | if (i == 0 || j == 0) 25 | L[i][j] = 0; 26 | else if (str1[i-1] == str2[j-1]) 27 | L[i][j] = L[i-1][j-1] + 1; 28 | else 29 | L[i][j] = findmax(L[i-1][j], L[i][j-1]); 30 | } 31 | } 32 | 33 | int index = L[m][n]; 34 | char lcs[index+1]; 35 | lcs[index] = '\0'; 36 | 37 | int i = m, j = n; 38 | while (i > 0 && j > 0) 39 | { 40 | if (str1[i-1] == str2[j-1]) 41 | { 42 | lcs[index-1] = str1[i-1]; 43 | i--; j--; index--; 44 | } 45 | else if (L[i-1][j] > L[i][j-1]) 46 | i--; 47 | else 48 | j--; 49 | } 50 | 51 | cout << "LCS: " << lcs; 52 | } 53 | 54 | int main() 55 | { 56 | char str1[100], str2[100]; 57 | cout << "String 1: "; 58 | cin.getline(str1, 100); 59 | cout << "String 2: "; 60 | cin.getline(str2, 100); 61 | 62 | int m = strlen(str1); 63 | int n = strlen(str2); 64 | 65 | lcs(str1, str2, m, n); 66 | return 0; 67 | } 68 | 69 | ``` 70 | 71 | ## Output 72 | ``` 73 | String 1: YUOSJTYPE 74 | String 2: OSYEWEASW 75 | LCS: OSYE 76 | ``` 77 | 78 | ## Contributed By 79 | 80 | | Name | GitHub Username | 81 | | --- | --- | 82 | | Srijita | SrijitaSarkar99 | 83 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | ## Make sure to go through all the sections in README.md 4 | 5 | To contribute to this repository and add cool code snippets, the following pointers should be kept in mind to avoid merge conflicts and other problems such as a bad PR while contributing: 6 | 7 | 1. Create a markdown file with a suitable name according to your snippet. Make sure the code snippet is not already in the codebase and is in the correct sub-directory. 8 | 2. Write appropriate title and sub-titles following the style in the already existing files inside the folders. 9 | 3. You can add a **Description** sub-heading if you want to provide an explanation! 10 | 4. Add the snippet and output in the appropriate blocks i.e. **Code** and **Output**. For example, for a python snippet: 11 | ~~~ 12 | ## Code 13 | 14 | ```python 15 | print("A cool code snippet here") 16 | ``` 17 | 18 | ## Output 19 | 20 | ```console 21 | A cool code snippet here 22 | ``` 23 | ~~~ 24 | 5. Add a **Contributed By** sub-heading at the end of the file and add your name, GitHub username and institute name in a tabular format in the markdown file. 25 | 6. *If the output of the snippet is an image/gif*, then only create a folder and shift the markdown file along with the output image in it. 26 | 27 | ## Important Note 28 | - **Do not add 2 different snippets in a single PR. Create a new PR from a new branch for that.** 29 | - **Do not add pure code files, add your snippets in the code blocks in the markdown file.** 30 | 31 | To connect with the community, join the [DSC MAIT Telegram Group.](https://t.me/joinchat/M3bPT1dhZCH-YQd197Xk5Q) 32 | -------------------------------------------------------------------------------- /snippets/java/fizzbuzz.md: -------------------------------------------------------------------------------- 1 | # Fizzbuzz 2 | 3 | ## Code 4 | 5 | ```java 6 | class FizzBuzz 7 | { 8 | public static void main(String args[]) 9 | { 10 | int upper = 100; 11 | for (int i=1; i<=upper; i++) 12 | { 13 | if (i%15==0) 14 | System.out.print("FizzBuzz "); 15 | else if (i%5==0) 16 | System.out.print("Buzz "); 17 | else if (i%3==0) 18 | System.out.print("Fizz "); 19 | else 20 | System.out.print(i+" "); 21 | } 22 | } 23 | } 24 | 25 | ``` 26 | 27 | ## Output 28 | 29 | ``` 30 | 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 31 | Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz 32 | Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 33 | 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 34 | Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 35 | 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 36 | 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 37 | Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 38 | 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 39 | 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz 40 | ``` 41 | 42 | 43 | ## Contributed By 44 | 45 | | Name | GitHub Username | Institute | 46 | | --- | --- | --- | 47 | | Manishita Choudhary| manishita24 | mody university | 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cool Code Snippets 2 | This is a repository for adding not so popular/known but very useful and cool code snippets in any language or framework that the community might benefit from! 3 | 4 | # Contributing 5 | - Go through the [Contributing Guidelines](CONTRIBUTING.md) for a detailed information on contributing to this repository! 6 | - For beginners - [Jump to this section.](#for-beginners) 7 | - PRs made without adding any useful Resource / Code / Solving Issues will be marked as invalid/spam. 8 | 9 | # For beginners 10 | - If this is your first time creating a Pull Request - go through the next section to know how to create one. 11 | - If you feel you don't have any cool snippets of code, don't worry! You can pick up one of the issues, solve them in your preferred language and add that code in a Markdown file inside the challenges folder according to the contributing guidelines. 12 | 13 | # Creating a pull request 14 | 1. Fork and Star this repository 15 | 2. Create a new git branch 16 | 3. Add files / Modify files 17 | 4. Add and commit your changes 18 | 5. Push your changes to your forked repository 19 | 6. Open this repository and click on **Pull requests** and then the **New Pull Request** button 20 | 7. Click on compare across forks and select **head repository** as your own forked repository and the new branch with changes 21 | 8. Click on **Create pull request** 22 | 23 | And voila! You have created a new pull request! Now all that's left is for the maintainer for the project/repository to review your PR and merge it if it is good to go! 24 | 25 |   26 | 27 | ## To connect with the community, join the [DSC MAIT Telegram Group.](https://t.me/joinchat/M3bPT1dhZCH-YQd197Xk5Q) 28 | 29 | ## Happy coding! 30 | -------------------------------------------------------------------------------- /snippets/c++/RecursiveFibonacciWithMemoization.md: -------------------------------------------------------------------------------- 1 | # Recursive Fibonacci in C++ with Memoization 2 | 3 | ## Description 4 | In an ordinary recursive function of the Fibonacci same function with the same parameter is called many times, so there are excessive recursive calls, but with memoization, an array of suitable size is taken and each value is initialized with -1. The result of the unique recursive call in an array is then stored replacing -1. So, when the function needs to be called again, it isn't called, instead, the result is directly taken from the array already stored and if it does not exists then the function is called recursively. This works upto 100 numbers. 5 | 6 | ## Code 7 | ```C++ 8 | #include 9 | 10 | using namespace std; 11 | int F[100]; //Globally declared or Static Array to store the value of called function 12 | //It prevent from excessive recursion 13 | int mfib(int n) { 14 | if (n <= 1) { 15 | F[n] = n; 16 | return n; 17 | } else { 18 | if (F[n - 2] == -1) 19 | F[n - 2] = mfib(n - 2); 20 | if (F[n - 1] == -1) 21 | F[n - 1] = mfib(n - 1); 22 | F[n] = F[n - 2] + F[n - 1]; 23 | 24 | return F[n]; 25 | } 26 | } 27 | 28 | int main() { 29 | int i,x; 30 | for (i = 0; i < 100; i++) 31 | F[i] = -1; 32 | cout << "Enter the index(max:100) : "; 33 | cin>>x; 34 | cout << "The " << x << "th term in the fibonacci sequence is : " << mfib(x); 35 | return 0; 36 | } 37 | ``` 38 | 39 | ## Input 40 | ``` 41 | Enter the index(max:100) : 7 42 | ``` 43 | ## Output 44 | ``` 45 | The 7th term in the fibonacci sequence is : 13 46 | ``` 47 | 48 | ## Contributed By 49 | |Name|Github Username|College Name| 50 | |---|---|---| 51 | |Manikant Rai|Manikant25|SRM Institute of Science And Technology| 52 | -------------------------------------------------------------------------------- /snippets/java/Diamond_Square/diamondSquare.md: -------------------------------------------------------------------------------- 1 | # Print a Diamond pattern enclosed in a square 2 | 3 | ## Description 4 | 5 | `Scanner` is a java.util package class that is used to take input from console. 6 | 7 | First outer for loop displays half of the diamond pattern, second outer for loop displays the remaining half of the diamond pattern. 8 | 9 | ## Code 10 | ```Java 11 | import java.util.*; 12 | public class Diamond_Square 13 | { 14 | public static void main(String[]args) 15 | { 16 | Scanner sc=new Scanner(System.in); 17 | //row count input 18 | System.out.print("Enter the row count : "); 19 | int N=sc.nextInt(); 20 | int i,j,k; 21 | //printing the upper half of the diamond including the middle part 22 | for(i=1;i<=N;i++) 23 | { 24 | for(j=1;j<=(N-i);j++) 25 | System.out.print(" "); 26 | for(k=1;k<=(2*i-1);k++) 27 | System.out.print("* "); 28 | System.out.println(); 29 | } 30 | //printing the lower part of the diamond after the middle part 31 | for(i=N-1;i>=1;i--) 32 | { 33 | for(j=N-i;j>=1;j--) 34 | System.out.print(" "); 35 | for(k=(2*i-1);k>=1;k--) 36 | System.out.print("* "); 37 | System.out.println(); 38 | } 39 | } 40 | } 41 | ``` 42 | 43 | ## Output 44 | 45 | ![Code Output](./output.png) 46 | 47 | ## Contributed By 48 | 49 | | Name | GitHub Username | Institute | 50 | | -------------| ------------------------------------------------| -------------------------------------------------------| 51 | | Bhaswati Saha| Bhaswati-Saha | Future Institute of Engineering and Management,Kolkata | 52 | -------------------------------------------------------------------------------- /snippets/python/flamesGame.md: -------------------------------------------------------------------------------- 1 | # Flames Game 2 | 3 | ## Code 4 | 5 | ```python 6 | def remove_match_char(list1, list2): 7 | 8 | for i in range(len(list1)) : 9 | for j in range(len(list2)) : 10 | if list1[i] == list2[j] : 11 | c = list1[i] 12 | list1.remove(c) 13 | list2.remove(c) 14 | list3 = list1 + ["*"] + list2 15 | return [list3, True] 16 | 17 | list3 = list1 + ["*"] + list2 18 | return [list3, False] 19 | 20 | # Driver code 21 | if __name__ == "__main__" : 22 | p1 = input("Enter your name : ") 23 | 24 | p1 = p1.lower() 25 | 26 | p1.replace(" ", "") 27 | 28 | p1_list = list(p1) 29 | 30 | p2 = input("Player 2 name : ") 31 | p2 = p2.lower() 32 | p2.replace(" ", "") 33 | p2_list = list(p2) 34 | 35 | proceed = True 36 | 37 | while proceed : 38 | 39 | ret_list = remove_match_char(p1_list, p2_list) 40 | con_list = ret_list[0] 41 | proceed = ret_list[1] 42 | star_index = con_list.index("*") 43 | p1_list = con_list[ : star_index] 44 | p2_list = con_list[star_index + 1 : ] 45 | 46 | 47 | count = len(p1_list) + len(p2_list) 48 | 49 | # list of FLAMES acronym 50 | result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"] 51 | 52 | while len(result) > 1 : 53 | 54 | split_index = (count % len(result) - 1) 55 | 56 | if split_index >= 0 : 57 | right = result[split_index + 1 : ] 58 | left = result[ : split_index] 59 | result = right + left 60 | 61 | else : 62 | result = result[ : len(result) - 1] 63 | 64 | print("Relationship status :", result[0]) 65 | ``` 66 | 67 | 68 | ## Input 69 | ``` 70 | Ajay 71 | Priya 72 | ``` 73 | ## Output 74 | ``` 75 | Relationship status :Friends 76 | ``` 77 | 78 | 79 | ## Contributed By 80 | 81 | | Name | GitHub Username | Institute | 82 | | --- | --- | --- | 83 | | Manav Gupta | silentwraith6 | PEC | -------------------------------------------------------------------------------- /snippets/typescript/frequencyOfCharacters.md: -------------------------------------------------------------------------------- 1 | # Count frequency of unique characters in a string 2 | 3 | ## Code 4 | 5 | ```typescript 6 | import { writeFileSync } from 'fs' 7 | 8 | const countCharactersAndOutputToTxt = ( 9 | str: string, 10 | ignoreCase?: boolean, 11 | omitWhitespace?: boolean 12 | ) => { 13 | //Ignore case. 14 | if (ignoreCase) { 15 | str = str.toLowerCase() 16 | } 17 | 18 | //Ignore whitespace 19 | if (omitWhitespace) { 20 | str = str.replace(/ /g, '') 21 | } 22 | 23 | const chars = {} 24 | 25 | //Iterate, increment char on occurance if existing, else assign 1. 26 | for (const char of str) { 27 | chars[char] ? chars[char]++ : (chars[char] = 1) 28 | } 29 | 30 | //Create an acceptable string output. 31 | let payload = '' 32 | for (const char in chars) { 33 | if (chars.hasOwnProperty(char)) { 34 | payload += `The character ${char} occured ${chars[char]} ${ 35 | chars[char] === 1 ? 'time.' : 'times.' 36 | } \n` 37 | } 38 | } 39 | 40 | //Write payload to text. 41 | writeFileSync('chars.txt', payload, 'UTF8') 42 | } 43 | 44 | const loremStr = 45 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis metus nibh, congue nec sagittis vel, blandit lobortis mi. Sed ac congue lorem. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum scelerisque dolor sed enim porttitor venenatis bibendum ut sem. Praesent pharetra augue urna, ut posuere tellus mattis in. Integer posuere suscipit massa, a gravida ligula tincidunt id. Duis placerat rutrum est et sodales. Vestibulum dolor lacus, auctor id purus ac, tristique facilisis mauris. Curabitur sed diam mollis, feugiat justo nec, posuere nulla. Etiam ut velit lacus. Nam vitae feugiat elit. Proin vitae nisi semper, vehicula risus et, finibus odio. Donec sit amet sodales eros.' 46 | 47 | countCharactersAndOutputToTxt(loremStr, true, true) 48 | ``` 49 | 50 | ## Output 51 | 52 | ``` 53 | The character l occured 32 times. 54 | The character o occured 29 times. 55 | The character r occured 35 times. 56 | The character e occured 72 times. 57 | The character m occured 24 times. 58 | The character i occured 62 times. 59 | The character p occured 15 times. 60 | The character s occured 60 times. 61 | The character u occured 50 times. 62 | The character d occured 21 times. 63 | The character t occured 58 times. 64 | The character a occured 47 times. 65 | The character , occured 11 times. 66 | The character c occured 22 times. 67 | The character n occured 28 times. 68 | The character g occured 11 times. 69 | The character . occured 14 times. 70 | The character b occured 11 times. 71 | The character h occured 4 times. 72 | The character v occured 9 times. 73 | The character q occured 4 times. 74 | The character f occured 5 times. 75 | The character j occured 1 time. 76 | ``` 77 | 78 | ## Description 79 | 80 | Please note, as this is TypeScript, @types/node is required. 81 | 82 | ## Contributed by 83 | 84 | | Name | GitHub Username | 85 | | ----------- | --------------- | 86 | | Tom Whiting | KwehDev | 87 | -------------------------------------------------------------------------------- /snippets/java/charFreqCount.md: -------------------------------------------------------------------------------- 1 | # Count frequency of unique characters in a String 2 | 3 | ## Code 4 | ```Java 5 | import java.util.Scanner; 6 | import java.io.FileWriter; 7 | import java.io.InputStreamReader; 8 | 9 | public class Main { 10 | public static void main(String[] args) throws Exception { 11 | Scanner scn = new Scanner(new InputStreamReader(System.in)); 12 | 13 | // string input 14 | System.out.println("Enter String : "); 15 | char[] str = scn.nextLine().toCharArray(); 16 | 17 | // Frequency map of string characters 18 | int[] chars = new int[127 - 32]; // readble ASCII characters are from 32 to 126 number 19 | for (char c : str) { 20 | chars[c - ' ']++; // ASCII(32) = ' ' 21 | } 22 | 23 | // output to write in file 24 | StringBuilder res = new StringBuilder("Frequency of characters in input string is : \n\n"); 25 | for (int i = 0, N = chars.length; i < N; i++) { 26 | if (chars[i] != 0) { // if frequency is not 0 then append in result string 27 | res.append("character '" + (char)(' ' + i) + "' occurred :" + chars[i] + " times\n"); 28 | } 29 | } 30 | 31 | FileWriter file = new FileWriter("output.txt"); 32 | file.write(res.toString()); // writing file 33 | 34 | // just flushing left out bytes 35 | file.flush(); 36 | file.close(); 37 | scn.close(); 38 | } 39 | } 40 | ``` 41 | 42 | ## Description 43 | `Scanner` is a java.util package class to take input from console. 44 | `InputStreamReader` is a java.io package class to manage input stream of characters taken from console (used to increase Scanner performance). 45 | `FileWriter` is a java.io class to append or writer character streams to system files. 46 | 47 | ## Input 48 | ``` 49 | Enter String : 50 | I am doing this contribution to github!! Yay!! :) 51 | ``` 52 | 53 | ## Output 54 | ``` 55 | $ cat ./output.txt 56 | Frequency of characters in input string is : 57 | 58 | character ' ' occurred :8 times 59 | character '!' occurred :4 times 60 | character ')' occurred :1 times 61 | character ':' occurred :1 times 62 | character 'I' occurred :1 times 63 | character 'Y' occurred :1 times 64 | character 'a' occurred :2 times 65 | character 'b' occurred :2 times 66 | character 'c' occurred :1 times 67 | character 'd' occurred :1 times 68 | character 'g' occurred :2 times 69 | character 'h' occurred :2 times 70 | character 'i' occurred :5 times 71 | character 'm' occurred :1 times 72 | character 'n' occurred :3 times 73 | character 'o' occurred :4 times 74 | character 'r' occurred :1 times 75 | character 's' occurred :1 times 76 | character 't' occurred :5 times 77 | character 'u' occurred :2 times 78 | character 'y' occurred :1 times 79 | ``` 80 | 81 | ## Contributed By 82 | 83 | | Name | GitHub Username | Institute | 84 | | ----------- | --------------------------------------------- | ---------------------------------------- | 85 | | Yash Saxena | [YashSaxena9](https://github.com/YashSaxena9) | Maharaja Agrasen Institute of Technology | 86 | -------------------------------------------------------------------------------- /challenges/dictionary_from_trie_C++.md: -------------------------------------------------------------------------------- 1 | # Dictionary using Trie 2 | 3 | ## Trie 4 | Trie is an efficient data retrieval structure which builds upon the properties of tree structure. Word seaarch complexitites 5 | can be brought to an optimal limit which depends on key length. 6 | 7 | ## Traversing the trie 8 | Main application of the trie is storing words in the structure. This trie can be traversed by first approaching the root node then traversing along the path on which our 9 | letter and the letter within the node's branch matches. You can learn more about inserting and searching, and tries in general [here](https://www.geeksforgeeks.org/trie-insert-and-search/). 10 | 11 | ## C++ Code 12 | TrieNode definition, Recursive functions for searching, inserting and a few helper functions are given in the following code snippet. 13 | ```cpp 14 | struct TrieNode 15 | { 16 | unordered_map branches; 17 | bool isEnd; 18 | string meaning; 19 | }; 20 | 21 | 22 | TrieNode* createNode(void) 23 | { 24 | // helper function which creates new node and initialises isEnd to false 25 | TrieNode* node = new TrieNode; 26 | node->isEnd = false; 27 | 28 | return node; 29 | } 30 | 31 | void insert(TrieNode*& node, const string &str, const string &meaning, int index = 0) 32 | { 33 | // inserts a character node to existing trie structure 34 | 35 | if (node == NULL) // creates a new root if there is none 36 | { 37 | node = createNode(); 38 | cout<<"Creating ROOT"<= str.length()) // check if we have reached end of the word 44 | { 45 | temp->isEnd = true; 46 | temp->meaning = meaning; 47 | 48 | return; 49 | } 50 | 51 | // assigns letter on i'th position of string to key 52 | char key = str[index]; 53 | if (temp->branches.find(key) == temp->branches.end()) 54 | { 55 | temp->branches[key] = createNode(); 56 | } 57 | 58 | // recursive definition to insert into trie 59 | return insert(temp->branches[key], str, meaning, index+1); 60 | } 61 | 62 | string search(TrieNode* root, const string &str, int index = 0) 63 | { 64 | // function which returns meaning of word if found else error message 65 | 66 | if (root == NULL) // return not found if no words added 67 | { 68 | return "Word not found."; 69 | } 70 | 71 | TrieNode* temp = root; 72 | 73 | if (index >= str.length()) // return word meaning if end of word encountered 74 | { 75 | return temp->meaning; 76 | } 77 | 78 | char key = str[index]; 79 | // recursive definition to iterate through trie 80 | return search(temp->branches[key], str, index+1); 81 | } 82 | 83 | int main() 84 | { 85 | TrieNode* root = NULL; 86 | 87 | // Build the dictionary 88 | insert(root, "apple", "a fruit"); 89 | insert(root, "ball", "a round object that you hit, kick, throw, etc. in games and sports"); 90 | insert(root, "cat", "an animal"); 91 | insert(root, "book", "a written or printed work"); 92 | insert(root, "draw", "to do a picture or diagram of something "); 93 | 94 | string str; 95 | cout<<"Enter Word to search:"; 96 | cin>>str; 97 | cout << search(root, str) 98 | 99 | return 0; 100 | } 101 | ``` 102 | 103 | ## Contributed By 104 | 105 | | Name | GitHub Username | Institute | 106 | | --- | --- | --- | 107 | | Dwij Mehta | dwij2212 | BITS Pilani | 108 | -------------------------------------------------------------------------------- /snippets/java/LongestCommonSubsequence.md: -------------------------------------------------------------------------------- 1 | # Longest Common Subsequence 2 | 3 | ## Description 4 | 5 | `Scanner` is a java.util package class that is used to take input from console. 6 | 7 | In the first part,length of the longest common subsequence for X[0..n-1] and Y[0..m-1] is stored in a table t[n+1][m+1] where t[i][j] stores the length of the longest common subsequence of X[0..i-1] and Y[0..j-1].In the first outer for loop, if either of the two strings X or Y is null then t[i][j]=0.In the second outer for loop, if the last character of both the strings matches then t[i][j]=1+t[i-1][j-1] else take the maximum of t[i][j-1] and t[i-1][j] and store it to t[i][j]. 8 | 9 | In the second part,longest common subsequence is formed and stored in a string s. 10 | 11 | ## Code 12 | ```Java 13 | //Dynamic Programming implementation of Longest Common Subsequence problem in Java 14 | import java.util.*; 15 | public class Longest_Common_Subsequence 16 | { 17 | //Returns the longest common subsequence 18 | static String LCS(String X,String Y,int n,int m) 19 | { 20 | int t[][]=new int[n+1][m+1]; 21 | int i,j; 22 | //Following steps builds the t[n+1][m+1] in bottom up fashion. 23 | //t[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] 24 | for(i=0;i<=n;i++) 25 | { 26 | for(j=0;j<=m;j++) 27 | { 28 | if(i==0 || j==0) 29 | t[i][j]=0; 30 | } 31 | } 32 | for(i=1;i<=n;i++) 33 | { 34 | for(j=1;j<=m;j++) 35 | { 36 | if (X.charAt(i - 1) == Y.charAt(j - 1)) 37 | t[i][j]= 1 + t[i-1][j-1]; 38 | else 39 | t[i][j]= Math.max(t[i][j-1], t[i-1][j]); 40 | } 41 | } 42 | //Following code forms the longest common subsequence which will be returned 43 | // s is the string to store the longest common subsequence 44 | String s=""; 45 | //Start from the right-most-bottom-most corner and one by one store the characters in the string s 46 | i=n; 47 | j=m; 48 | while(i>0 && j>0) 49 | { 50 | // If current character in X and Y are same, then current character is a part of LCS 51 | if(X.charAt(i-1)==Y.charAt(j-1)) 52 | { 53 | s=X.charAt(i-1)+s; 54 | i--; 55 | j--; 56 | } 57 | //If not same, then find the larger of two and go in the direction of larger value 58 | else 59 | { 60 | if(t[i-1][j]>t[i][j-1]) 61 | i--; 62 | else 63 | j--; 64 | } 65 | } 66 | return s; 67 | } 68 | public static void main(String[]args) 69 | { 70 | Scanner sc=new Scanner(System.in); 71 | System.out.println("Enter String 1 :"); 72 | String X=sc.nextLine(); 73 | System.out.println("Enter String 2 :"); 74 | String Y=sc.nextLine(); 75 | System.out.println("Longest Common Subsequence : "+LCS(X,Y,X.length(),Y.length())); 76 | } 77 | } 78 | ``` 79 | 80 | ## Input 81 | ``` 82 | Enter String 1 : 83 | ABCDGH 84 | Enter String 2 : 85 | AEBDFHR 86 | ``` 87 | 88 | ## Output 89 | ``` 90 | Longest Common Subsequence : ABDH 91 | ``` 92 | 93 | ## Contributed By 94 | 95 | | Name | GitHub Username | Institute | 96 | | -------------| ------------------------------------------------| -------------------------------------------------------| 97 | | Bhaswati Saha| Bhaswati-Saha | Future Institute of Engineering and Management,Kolkata | 98 | -------------------------------------------------------------------------------- /snippets/java/Flames_Game.md: -------------------------------------------------------------------------------- 1 | # Flames Game 2 | 3 | ## Description 4 | 5 | `Scanner` is a java.util package class that is used to take input from console. 6 | 7 | FLAMES is a popular game named after the acronym: Friends, Love, Affection, Marriage, Enemies, Siblings. 8 | 9 | int cancel(String name1,String name2) removes the common characters with their respective common occurrences from the two strings and returns the total count of the characters that are left.In the main(),characters are removed from the string f which contains the word "FLAMES" using the total count we got until there is one character left in f.The character which last the process is the result. 10 | 11 | ## Code 12 | ```Java 13 | import java.util.Scanner; 14 | public class Flames_Game 15 | { 16 | //function to remove the common characters with their respective common occurrences from the two strings and returns the total count of the characters that are left 17 | static int cancel(String name1,String name2) 18 | { 19 | int total=name1.length()+name2.length(); 20 | int canc=0; 21 | for(int i=0;i=f.length()) 53 | cut=0; 54 | ++cut; 55 | } 56 | f=f.substring(cut)+f.substring(0,cut-1); 57 | f=f.trim(); 58 | } 59 | //Print the result 60 | System.out.print("Relationship:"); 61 | switch(f){ 62 | case "F": 63 | System.out.println("Friends"); 64 | break; 65 | case "L": 66 | System.out.println("Love"); 67 | break; 68 | case "A": 69 | System.out.println("Affection"); 70 | break; 71 | case "M": 72 | System.out.println("Marriage"); 73 | break; 74 | case "E": 75 | System.out.println("Enemies"); 76 | break; 77 | case "S": 78 | System.out.println("Siblings"); 79 | break; 80 | } 81 | } 82 | } 83 | ``` 84 | 85 | ## Input 86 | ``` 87 | Enter a name: 88 | ALIA 89 | Enter the partner name 90 | RANBIR 91 | ``` 92 | 93 | ## Output 94 | ``` 95 | Relationship:Marriage 96 | ``` 97 | 98 | ## Contributed By 99 | 100 | | Name | GitHub Username | Institute | 101 | | -------------| ------------------------------------------------| -------------------------------------------------------| 102 | | Bhaswati Saha| Bhaswati-Saha | Future Institute of Engineering and Management,Kolkata | 103 | -------------------------------------------------------------------------------- /snippets/python/caesar_cipher.md: -------------------------------------------------------------------------------- 1 | # Caesar Cipher 2 | 3 | ## Description 4 | This script uses the [Caesar Cipher](https://en.wikipedia.org/wiki/Caesar_cipher) for encrypting messages in plain text. 5 | 6 | 7 | ## Options: 8 | -e: encrypts plain text 9 | -d: decodes encrypted text 10 | -k, --key: key 11 | 12 | 13 | ## Code: 14 | ```python 15 | import sys 16 | 17 | 18 | def encrypt(msg=None,s_pattern=None): 19 | """ 20 | encrypts a message in plain text using the 'Caesar cipher' 21 | :param msg: plain text string 22 | :param s_patter: shift pattern 23 | """ 24 | if msg is None: 25 | raise ValueError("'msg' cannot be None") 26 | if isinstance(msg, str) is False: 27 | raise TypeError("'msg' must be type 'str'") 28 | if s_pattern is None: 29 | raise ValueError("'s_pattern' must be specified") 30 | if isinstance(s_pattern, int) is False: 31 | raise TypeError("'s_pattern' must be type 'int'") 32 | 33 | result = "" 34 | 35 | for idx in range(len(msg)): 36 | char = msg[idx] 37 | if char.isalpha(): 38 | if char.isupper(): 39 | result += chr((ord(char) + s_pattern - 65) % 26 + 65) 40 | else: 41 | result += chr((ord(char) + s_pattern - 97) % 26 + 97) 42 | else: 43 | result += msg[idx] 44 | 45 | return result 46 | 47 | 48 | def decode(msg=None, s_pattern=None): 49 | """ 50 | decodes a message in plain text using the 'Caesar cipher' 51 | :param msg: plain text string 52 | :param s_patter: shift pattern 53 | """ 54 | if msg is None: 55 | raise ValueError("'msg' cannot be None") 56 | if isinstance(msg, str) is False: 57 | raise TypeError("'msg' must be type 'str'") 58 | if s_pattern is None: 59 | raise ValueError("'s_pattern' must be specified") 60 | if isinstance(s_pattern, int) is False: 61 | raise TypeError("'s_pattern' must be type 'int'") 62 | 63 | result = "" 64 | 65 | for idx in range(len(msg)): 66 | char = msg[idx] 67 | if char.isalpha(): 68 | if char.isupper(): 69 | result += chr((ord(char) - s_pattern - 65) % 26 + 65) 70 | else: 71 | result += chr((ord(char) - s_pattern - 97) % 26 + 97) 72 | else: 73 | result += msg[idx] 74 | 75 | return result 76 | 77 | 78 | if __name__ == "__main__": 79 | options = ''' 80 | usage: 81 | 82 | -e: encrypts plain text 83 | -d: decodes encrypted text 84 | -k, --key: key 85 | ''' 86 | if "-e" in sys.argv and "-d" in sys.argv: 87 | print(f"error: only one option can be specified at a time\n\n{options}") 88 | sys.exit(1) 89 | if "-k" not in sys.argv: 90 | print(f"error: must specify a key\n\n{options}") 91 | sys.exit(1) 92 | if sys.argv[1] == "-e": 93 | msg = sys.argv[sys.argv.index("-e") + 1] 94 | key = int(sys.argv[sys.argv.index("-k") + 1]) 95 | e_msg = encrypt(msg, key) 96 | print(f"encrypted: {e_msg}") 97 | sys.exit(0) 98 | elif sys.argv[1] == "-d": 99 | msg = sys.argv[sys.argv.index("-d") + 1] 100 | key = int(sys.argv[sys.argv.index("-k") + 1]) 101 | d_msg = decode(msg, key) 102 | print(f"decoded message: {d_msg}") 103 | sys.exit(0) 104 | else: 105 | print(f"error: you must specify one option\n\n:{options}") 106 | sys.exit(1) 107 | ``` 108 | 109 | 110 | ## Output: 111 | 112 | $ python caesar_cipher.py -e "Hi, How are you?" -k -17 113 | encrypted: Qr, Qxf jan hxd? 114 | 115 | $ python caesar_cipher.py -d "Qr, Qxf jan hxd?" -k -17 116 | decoded message: Hi, How are you? 117 | 118 | 119 | ## Contributed By 120 | 121 | | Name | GitHub Username | Institute | 122 | | --- | --- | --- | 123 | | Alejandro Olaria | aolaria | Universidad Rafael Belloso Chacín | -------------------------------------------------------------------------------- /snippets/python/dictionary_using_trie_python.md: -------------------------------------------------------------------------------- 1 | # Dictionary using Trie 2 | 3 | ## Description 4 | 5 | ### Trie 6 | Trie is an efficient data retrieval structure which builds upon the properties of tree structure. Word search complexitites 7 | can be brought to an optimal limit which depends on key length. 8 | 9 | ### Traversing the trie 10 | Main application of the trie is storing words in the structure. This trie can be traversed by first approaching the root node then traversing along the path on which our 11 | letter and the letter within the node's branch matches. You can learn more about inserting and searching, and tries in general [here](https://www.geeksforgeeks.org/trie-insert-and-search/) 12 | 13 | ## Code 14 | ```python 15 | 16 | class TrieNode: 17 | 18 | # Trie node class 19 | def __init__(self): 20 | self.children = [None] * 26 21 | 22 | # isEndOfWord is True if node represent the end of the word 23 | self.isEndOfWord = False 24 | self.meaning="" 25 | 26 | 27 | class Trie: 28 | 29 | # Trie data structure class 30 | def __init__(self): 31 | self.root = self.getNode() 32 | 33 | def getNode(self): 34 | 35 | # Returns new trie node (initialized to NULLs) 36 | return TrieNode() 37 | 38 | def _charToIndex(self, ch): 39 | 40 | # Converts key current character into index 41 | # use only 'a' through 'z' 42 | 43 | return ord(ch) - ord('a') 44 | 45 | def insert(self, key,meaning): 46 | 47 | # If not present, inserts key into trie 48 | # If the key is prefix of trie node, 49 | # just marks leaf node 50 | pCrawl = self.root 51 | length = len(key) 52 | for level in range(length): 53 | index = self._charToIndex(key[level]) 54 | 55 | # if current character is not present 56 | if not pCrawl.children[index]: 57 | pCrawl.children[index] = self.getNode() 58 | pCrawl = pCrawl.children[index] 59 | 60 | # mark last node as leaf 61 | pCrawl.isEndOfWord = True 62 | pCrawl.meaning=meaning 63 | 64 | def search(self, key): 65 | 66 | # Search key in the trie 67 | # Returns meaning if key presents 68 | # in trie, else word not found 69 | pCrawl = self.root 70 | length = len(key) 71 | for level in range(length): 72 | index = self._charToIndex(key[level]) 73 | if not pCrawl.children[index]: 74 | return "Word not found." 75 | pCrawl = pCrawl.children[index] 76 | 77 | return pCrawl.meaning 78 | 79 | 80 | # Input keys (use only 'a' through 'z') 81 | keys = {"hacktoberfest":"a month long virtual festival event to celebrate open source contributions", "git":"a distributed version-control system for tracking changes in source code during software development", 82 | "opensource":"denoting software for which the original source code is made freely available and may be redistributed and modified", 83 | "issue":"an important topic or problem for debate or discussion","contribution":"a gift or payment to a common fund or collection"} 84 | 85 | # Trie object 86 | t = Trie() 87 | 88 | # Construct trie 89 | for k,v in keys.items(): 90 | t.insert(k,v) 91 | #Here is the option 92 | while(True): 93 | print("Press 1 to search a word.") 94 | print("Press 2 to a new word and its definition") 95 | print("Press 3 to exit.") 96 | n=int(input("Enter your choice: ")) 97 | if(n==1): 98 | #covert the input into lowercase 99 | search_word=input("Enter the word: ").lower() 100 | # Search for different keys 101 | print("{} ---- {}".format(search_word, t.search(search_word))) 102 | elif(n==2): 103 | new_word=input("Enter the new word: ").lower() 104 | #check the word exist or not 105 | if new_word not in keys.keys(): 106 | new_mean=input("Enter its meaning: ").lower() 107 | keys[new_word]=new_mean 108 | t.insert(new_word, new_mean) 109 | else: 110 | print("The Word already exist in the dictionary.") 111 | elif(n==3): 112 | exit(0) 113 | else: 114 | print("Wrong Choice") 115 | print() 116 | 117 | ``` 118 | ## Output 119 | 120 | ``` 121 | Press 1 to search a word. 122 | Press 2 to a new word and its definition 123 | Press 3 to exit. 124 | Enter your choice: 1 125 | Enter the word: bus 126 | bus ---- Word not found. 127 | 128 | Press 1 to search a word. 129 | Press 2 to a new word and its definition 130 | Press 3 to exit. 131 | Enter your choice: 2 132 | Enter the new word: Bus 133 | Enter its meaning: a large motor vehicle carrying passengers by road 134 | 135 | Press 1 to search a word. 136 | Press 2 to a new word and its definition 137 | Press 3 to exit. 138 | Enter your choice: 1 139 | Enter the word: bus 140 | bus ---- a large motor vehicle carrying passengers by road 141 | 142 | Press 1 to search a word. 143 | Press 2 to a new word and its definition 144 | Press 3 to exit. 145 | Enter your choice: 3 146 | ``` 147 | 148 | ## Contributed By 149 | 150 | | Name | GitHub Username | Institute | 151 | | --- | --- | --- | 152 | | Arnab Bhakta | arnab031 | Future Institute of Engineering and Management, Kolkata | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, religion, or sexual identity 11 | and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the 27 | overall community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or 32 | advances of any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email 36 | address, without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [DSC MAIT](mailto:developerstudentclubmait@gmail.com). 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series 87 | of actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or 94 | permanent ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within 114 | the community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.0, available at 120 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 121 | 122 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 123 | enforcement ladder](https://github.com/mozilla/diversity). 124 | 125 | [homepage]: https://www.contributor-covenant.org 126 | 127 | For answers to common questions about this code of conduct, see the FAQ at 128 | https://www.contributor-covenant.org/faq. Translations are available at 129 | https://www.contributor-covenant.org/translations. 130 | -------------------------------------------------------------------------------- /challenges/Sudoku-BackTracking-C++.md: -------------------------------------------------------------------------------- 1 | # Solving a Sudoku puzzle using backtracking 2 | 3 | ## What is Backtracking? 4 | Backtracking is an algorithmic-technique for solving problems recursively by trying to build a solution incrementally, one piece at a time, removing those solutions that fail to satisfy the constraints of the problem at any point of time (by time, here, is referred to the time elapsed till reaching any level of the search tree). 5 | More [here](https://www.geeksforgeeks.org/backtracking-introduction/). 6 | 7 | ## How does this help in solving sudoku? 8 | The algorithm tries the first valid number it can put in the first empty square it finds on the grid. After this it recursively calls the function and it tries the first valid number on the next empty square. 9 | If we encounter an empty square where no number is valid then the algorithm goes back to the previous recursive state, finds the next valid number in the previous step and builds upon that number. 10 | This might not seem intuitive at the first go but you could find an amazing visualisation video on the topic [here](https://www.youtube.com/watch?v=_vWRZiDUGHU). 11 | 12 | ## C++ Code 13 | ```cpp 14 | // declared as global variables for proper functioning 15 | int row; 16 | int col; 17 | 18 | bool findblank (int sudoku[9][9], int &row, int &col) 19 | { 20 | /* this function takes in a sudoku grid as an arguement 21 | and returns true if there exist an empty space in our grid. */ 22 | 23 | for (row = 0 ; row < 9; row++) 24 | { 25 | for (col = 0 ; col < 9; col++) 26 | { 27 | if (sudoku[row][col] == 0) 28 | { 29 | return true; 30 | } 31 | } 32 | } 33 | 34 | return false; 35 | } 36 | 37 | bool checknum (int sudoku[9][9], int row, int col, int num) 38 | { 39 | // function to check whether a given number is valid in the given row and column 40 | 41 | // iterates over all rows and reuturns false if the number already exist in the column. 42 | for (int i = 0; i < 9; i++) 43 | { 44 | if (sudoku[i][col] == num) 45 | return false; 46 | } 47 | 48 | // iterates over all columns and returns false if the number already exist in the row. 49 | for (int i = 0; i < 9; i++) 50 | { 51 | if (sudoku[row][i] == num) 52 | return false; 53 | } 54 | 55 | // checks the 3*3 box in which the number is to be placed 56 | for (int i = row - row%3; i < row - row%3 + 3; i++) 57 | { 58 | for (int j = col - col%3; j < col - col%3 + 3; j++) 59 | { 60 | if (sudoku[i][j] == num) 61 | return false; 62 | } 63 | } 64 | 65 | // return false directly if the square is pre-occupied 66 | if (sudoku[row][col] != 0) 67 | return false; 68 | 69 | return true; 70 | } 71 | 72 | bool solvemain (int sudoku[9][9]) 73 | { 74 | // main function where backtracking algorithm has been implemented. 75 | 76 | /* if there is no empty square then the puzzle is solved hence return true. 77 | however if there is an empty square then the values of the global variables 78 | row and column would have changed accordingly hence we make use of them 79 | in the following for-loop. */ 80 | 81 | if (!findblank(sudoku, row, col)) // FIRST if condition 82 | return true; 83 | 84 | /* iterates over all the numbers and uses the modified values of row, col to 85 | check whether the given number is valid in that position or not. */ 86 | for (int num = 1; num < 10; num++) 87 | { 88 | // if the given number is valid then assign the number to that empty square 89 | if (checknum (sudoku,row,col,num)) 90 | { 91 | sudoku[row][col] = num; 92 | 93 | 94 | /* heart of the algorithm. 95 | recursive call to solvemain. 96 | if the sudoku is completed then the last function will return true 97 | from the FIRST if condition itself. 98 | hence the sudoku will be completed and we can return true. */ 99 | 100 | if (solvemain(sudoku)) 101 | return true; 102 | 103 | /* however if for some reason there comes a point when there is no valid 104 | number for a given empty square,at that point this else condition will 105 | run and the function will finally return false. 106 | This will lead to 'popping' of all stacks in which our sudoku has been 107 | wrongly solved and the puzzle is essentially back to the point on which 108 | the next empty square has no valid numbers. */ 109 | 110 | else 111 | sudoku[row][col] = 0; 112 | } 113 | } 114 | 115 | return false; 116 | } 117 | ``` 118 | 119 | ## Driver Code Snippet 120 | ```cpp 121 | int sudoku[9][9] = {{0,6,4,0,3,0,0,0,0}, {0,0,0,1,0,0,0,0,0},{3,0,5,0,8,0,0,0,2},{0,0,0,0,0,8,0,7,0},{7,5,0,6,0,2,4,0,0},{0,0,0,0,0,0,0,1,8},{0,0,0,0,0,0,0,0,0},{0,0,2,7,0,0,0,0,9},{1,0,3,0,0,4,0,6,0}}; 122 | if (solvemain(sudoku)) 123 | print_sudoku_grid(sudoku); 124 | else 125 | printf( "No solution exists"); 126 | ``` 127 | 128 | ## Output 129 | ```terminal 130 | 9 6 4 2 3 7 8 5 1 131 | 2 8 7 1 4 5 9 3 6 132 | 3 1 5 9 8 6 7 4 2 133 | 6 3 1 4 9 8 2 7 5 134 | 7 5 8 6 1 2 4 9 3 135 | 4 2 9 5 7 3 6 1 8 136 | 8 7 6 3 5 9 1 2 4 137 | 5 4 2 7 6 1 3 8 9 138 | 1 9 3 8 2 4 5 6 7 139 | ``` 140 | 141 | ## Contributed By 142 | 143 | | Name | GitHub Username | Institute | 144 | | --- | --- | --- | 145 | | Dwij Mehta | dwij2212 | BITS Pilani | 146 | -------------------------------------------------------------------------------- /challenges/tic-tac-toe-C++.md: -------------------------------------------------------------------------------- 1 | # Tic -Tac Toe Game 2 | 3 | ## Description: 4 | 5 | ## Rules of the Game 6 | 7 | The game is to be played between two people (in this program between HUMAN and COMPUTER). 8 | One of the player chooses ‘O’ and the other ‘X’ to mark their respective cells. 9 | The game starts with one of the players and the game ends when one of the players has one whole row/ column/ diagonal filled with his/her respective character (‘O’ or ‘X’). 10 | If no one wins, then the game is said to be draw. 11 | 12 | ## C++ Code 13 | 14 | ```cpp 15 | 16 | #include 17 | using namespace std; 18 | 19 | #define COMPUTER 1 20 | #define HUMAN 2 21 | 22 | #define SIDE 3 // Length of the board 23 | 24 | // Computer will move with 'O' 25 | // and human with 'X' 26 | #define COMPUTERMOVE 'O' 27 | #define HUMANMOVE 'X' 28 | 29 | // A function to show the current board status 30 | void showBoard(char board[][SIDE]) 31 | { 32 | printf("\n\n"); 33 | 34 | printf("\t\t\t %c | %c | %c \n", board[0][0], 35 | board[0][1], board[0][2]); 36 | printf("\t\t\t--------------\n"); 37 | printf("\t\t\t %c | %c | %c \n", board[1][0], 38 | board[1][1], board[1][2]); 39 | printf("\t\t\t--------------\n"); 40 | printf("\t\t\t %c | %c | %c \n\n", board[2][0], 41 | board[2][1], board[2][2]); 42 | 43 | return; 44 | } 45 | 46 | // A function to show the instructions 47 | void showInstructions() 48 | { 49 | printf("\t\t\t Tic-Tac-Toe\n\n"); 50 | printf("Choose a cell numbered from 1 to 9 as below" 51 | " and play\n\n"); 52 | 53 | printf("\t\t\t 1 | 2 | 3 \n"); 54 | printf("\t\t\t--------------\n"); 55 | printf("\t\t\t 4 | 5 | 6 \n"); 56 | printf("\t\t\t--------------\n"); 57 | printf("\t\t\t 7 | 8 | 9 \n\n"); 58 | 59 | printf("-\t-\t-\t-\t-\t-\t-\t-\t-\t-\n\n"); 60 | 61 | return; 62 | } 63 | 64 | 65 | // A function to initialise the game 66 | void initialise(char board[][SIDE], int moves[]) 67 | { 68 | // Initiate the random number generator so that 69 | // the same configuration doesn't arises 70 | srand(time(NULL)); 71 | 72 | // Initially the board is empty 73 | for (int i=0; i