├── .DS_Store ├── C++ ├── Longest Substring Without Repeating Characters.cpp ├── distanceofnodes.cpp ├── maximum_length_of_a_concatenated_string_with_unique_characters.cpp ├── minimum-no-k-consecutive-bit-flips.cpp ├── reverse.c └── reverseaLinkedList.cpp ├── C ├── MatrixChainMultiplication.c ├── nQueen.c └── reverse.c ├── Java ├── Best_Time_to_Buy_and_Sell_Stock.java ├── Combination Sum.java ├── Maximum_Subarray.java ├── power_of_a_number.java └── two_sum.java ├── Python ├── 3d_Kadane's_Algorithm_code.py ├── Binary-Search.py ├── Binary_Search_Tree.py ├── Create BFS.py ├── Divide_Players_Into_Teams_Of_Equal_Skills.py ├── Guessing_game.py ├── Min_elem_rotated_array.py ├── Power_Of_Heros.py ├── Score_of_string.py ├── Set_Matrix_Zeros.py ├── TicTacToeGUI.py ├── Tim_Sort.py ├── Valid_Number.py ├── mergesort.py └── multilevel queue scheduling.py ├── README.md └── WebProjects ├── birthday-invite-project.html └── dice game ├── images ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg └── 6.jpg ├── index.html ├── main.js └── styles.css /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/.DS_Store -------------------------------------------------------------------------------- /C++/Longest Substring Without Repeating Characters.cpp: -------------------------------------------------------------------------------- 1 | /* Leetcode problem 2 | Author : Ashish Kumar Sahoo 3 | 3. Longest Substring Without Repeating Characters 4 | 5 | Intiuation : 6 | Intuition is strightforward and simple, we track the frequencey and as we know we can't use string to track longest substring without repeating characters, as poping a char from front of string is not in O(1) which could be optimized by deque approch. 7 | 8 | Approch : 9 | 1) At first we initialize a unordered_map to track the frequncy and then. 10 | 2) We initialize deque for pushing the characters and if temp > res we update our res deque to temp as we need longest substring here. 11 | 3) And while loop is used to reduce the frequency from front doing i++ and removing charecters from temp deque as we no longer need them. 12 | 4) return res.size() as we only need size not string. 13 | 14 | Time Complexity : 15 | O(N) 16 | 17 | Space Complexity : 18 | O(N) 19 | 20 | I hope this helps to understand. 21 | Thank you!! 22 | */ 23 | 24 | class Solution { 25 | public: 26 | int lengthOfLongestSubstring(string s) { 27 | if(s.size()==1) return 1; 28 | 29 | unordered_mapm; 30 | int n = s.length(); 31 | 32 | dequetemp; 33 | dequeres; 34 | int i,j; 35 | for(i=0,j=0;i1) { 39 | if(temp.size()>res.size()) { 40 | res = temp; 41 | } 42 | 43 | while(m[s[j]]>1) { 44 | temp.pop_front(); 45 | m[s[i]]--; 46 | i++; 47 | } 48 | } 49 | 50 | temp.push_back(s[j]); 51 | j++; 52 | } 53 | 54 | if(temp.size()>res.size()) { 55 | res = temp; 56 | } 57 | 58 | return res.size(); 59 | } 60 | }; 61 | -------------------------------------------------------------------------------- /C++/distanceofnodes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define nl '\n' 6 | const ll maxn = 2e5 + 20; 7 | const ll LOG = 20; // Because 2^20 > 1e5 8 | vector adj[maxn]; 9 | ll up[maxn][LOG]; // up[v][j] is the 2^j-th ancestor of v 10 | ll depth[maxn]; 11 | 12 | void dfs(ll v, ll p) { 13 | up[v][0] = p; // The 2^0-th ancestor (parent) 14 | for (ll i = 1; i < LOG; i++) { 15 | if (up[v][i - 1] != -1) { 16 | up[v][i] = up[up[v][i - 1]][i - 1]; // Set the 2^i-th ancestor 17 | } else { 18 | up[v][i] = -1; // No ancestor 19 | } 20 | } 21 | for (auto u : adj[v]) { 22 | if (u != p) { 23 | depth[u] = depth[v] + 1; 24 | dfs(u, v); 25 | } 26 | } 27 | } 28 | 29 | ll lca(ll u, ll v) { 30 | if (depth[u] < depth[v]) { 31 | swap(u, v); // Ensure u is the deeper node 32 | } 33 | 34 | // Lift u up until it's the same depth as v 35 | ll diff = depth[u] - depth[v]; // first we will bring them to the same level 36 | for (ll i = 0; i < LOG; i++) { 37 | if ((diff >> i) & 1) { // If the i-th bit of diff is set, lift u by 2^i 38 | u = up[u][i]; 39 | } 40 | } 41 | 42 | if (u == v) return u; // If u and v are the same, return u 43 | 44 | // Now lift both u and v until their lowest common ancestor is found 45 | for (ll i = LOG - 1; i >= 0; i--) { 46 | if (up[u][i] != up[v][i]) { 47 | u = up[u][i]; 48 | v = up[v][i]; 49 | } 50 | } 51 | 52 | // The parent of u (or v) is the LCA 53 | return up[u][0]; // once up[u][i] == up[v][i] then keep subtracting i until it becomes 0 54 | } 55 | 56 | void run() { 57 | ll n, q; 58 | cin >> n >> q; 59 | 60 | for(ll i=2;i<=n;i++){ 61 | ll u,v; 62 | cin >> u >> v; 63 | adj[u].push_back(v); 64 | adj[v].push_back(u); 65 | } 66 | memset(up, -1, sizeof(up)); 67 | depth[1] = 0; 68 | dfs(1, -1); 69 | 70 | while (q--) { 71 | ll u, v; 72 | cin >> u >> v; 73 | ll ans=abs(depth[u]-depth[lca(u,v)])+abs(depth[v]-depth[lca(u,v)]); 74 | cout<& masks, int currentMask, int n, vector& arr) { 17 | if (i >= n) 18 | return __builtin_popcount(currentMask); // Count the number of set bits (length of unique chars) 19 | 20 | int include = 0; 21 | int exclude = solve(i+1, masks, currentMask, n, arr); // Exclude current string 22 | 23 | // If no common characters between current mask and next string's mask 24 | if (masks[i] != -1 && (currentMask & masks[i]) == 0) { 25 | include = solve(i+1, masks, currentMask | masks[i], n, arr); // Include current string 26 | } 27 | 28 | return max(include, exclude); 29 | } 30 | 31 | int maxLength(vector& arr) { 32 | int n = arr.size(); 33 | vector masks(n, 0); 34 | 35 | // Precompute bitmasks for all strings and eliminate those with duplicate characters 36 | for (int i = 0; i < n; ++i) { 37 | masks[i] = stringToBitmask(arr[i]); 38 | } 39 | 40 | // Start recursive solving with an empty mask (0) 41 | return solve(0, masks, 0, n, arr); 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /C++/minimum-no-k-consecutive-bit-flips.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | LEETCODE PROBELM 3 | 995. Minimum Number of K Consecutive Bit Flips 4 | (hard) 5 | Author: Anisha 6 | 7 | Q- You are given a binary array nums and an integer k. 8 | 9 | A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. 10 | 11 | Return the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible, return -1. 12 | 13 | A subarray is a contiguous part of an array. 14 | 15 | Intuietion: 16 | 17 | We want to flip subarrays of size k in a binary array nums so that all elements become 1. 18 | The question is solved keeping in mind that: 19 | 20 | 1) Flipping Impact: Flipping affects not just the current element but the next k-1 elements as well. We need to track when these flips end. 21 | 2) Tracking Flips: Use a queue to remember when each flip ends. If a flip starts at index i, it impacts elements until i + k - 1. 22 | 3) When to Flip: 23 | Flip if the current element is 0 and we have made an even number of flips so far. 24 | Flip if the current element is 1 and we have made an odd number of flips. 25 | 4) Edge Case: If a flip is required but there aren’t enough elements left to flip a full subarray of size k, return -1. 26 | 27 | APPROACH 28 | 29 | 1) Tracking where ongoing flips end using a queue. 30 | 2) for each element, remove expired flips. 31 | If the current element needs flipping, check if a flip is possible. 32 | 3) If flipping is needed, mark the end of the flip in the queue and increase the flip count. 33 | 4) If flipping isn't possible, return -1. 34 | 5) After iterating, return the total number of flips. 35 | 36 | Time COMPLEXITY: 37 | O(n) 38 | 39 | SPACE COMPLEXITY 40 | O(x) 41 | here x is the size of the subarray that we can flip at any given time 42 | 43 | I hope its easy to understand from this explanation! 44 | Thanks 45 | */ 46 | 47 | #include 48 | #include 49 | using namespace std; 50 | 51 | class Solution { 52 | public: 53 | int minKBitFlips(vector& nums, int k) { 54 | int n = nums.size(); 55 | queue flipEnds; 56 | int flips = 0; 57 | 58 | for (int i = 0; i < n; ++i) { 59 | if (!flipEnds.empty() && flipEnds.front() <= i) { 60 | flipEnds.pop(); 61 | } 62 | if ((nums[i] == 0 && flipEnds.size() % 2 == 0) || (nums[i] == 1 && flipEnds.size() % 2 != 0)) { 63 | if (i + k > n) { 64 | return -1; 65 | } 66 | flipEnds.push(i + k); 67 | flips++; 68 | } 69 | } 70 | return flips; 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /C++/reverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void reverseArrayExtraArray(int arr[], int size) 4 | { 5 | int reversedArr[size]; 6 | for (int i = 0; i < size; i++) { 7 | reversedArr[i] = arr[size - i - 1]; 8 | } 9 | 10 | // Print reversed array 11 | printf("Reversed Array: "); 12 | for (int i = 0; i < size; i++) { 13 | printf("%d ", reversedArr[i]); 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | int originalArr[] = { 1, 2, 3, 4, 5 }; 20 | int size = sizeof(originalArr) / sizeof(originalArr[0]); 21 | 22 | reverseArrayExtraArray(originalArr, size); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C++/reverseaLinkedList.cpp: -------------------------------------------------------------------------------- 1 | /* The main idea is to reverse the linked list, we try to changes the direction of the arrows or links. This in-place reversal allows us to efficiently transform the original list without using extra space. 2 | 3 | 1. At first we keep a pointer let's say "prev" before the start pointer pointing to null . A temporary node points to first node, a front pointer pointing to the first node itself 4 | 5 | 2. Now we move forward using a while loop and along the way we point front to the current (temp) pointer's next. 6 | 7 | 3. Then we point current pointers to the previous pointer which is pointing to null. 8 | 9 | 4. Then we update previous pointer as the current pointer. 10 | 11 | 5. Then we update current pointer or temp to the front node. 12 | 13 | And voilah! we've reversed a linked list inplace without using any extra space 14 | 15 | */ 16 | class Node { 17 | public: 18 | 19 | 20 | int data; 21 | 22 | Node* next; 23 | 24 | 25 | Node(int data1, Node* next1) { 26 | data = data1; 27 | next = next1; 28 | } 29 | 30 | 31 | Node(int data1) { 32 | data = data1; 33 | next = nullptr; 34 | } 35 | }; 36 | 37 | 38 | Node* reverseLinkedList(Node *head) 39 | { 40 | 41 | Node* temp = head; 42 | 43 | Node* prev = NULL; 44 | 45 | 46 | while(temp != NULL){ 47 | 48 | Node* front = temp->next; 49 | 50 | temp->next = prev; 51 | 52 | prev = temp; 53 | 54 | temp = front; 55 | } 56 | 57 | 58 | return prev; 59 | } 60 | 61 | // Function to print the linked list 62 | void printLinkedList(Node* head) { 63 | Node* temp = head; 64 | while (temp != nullptr) { 65 | cout << temp->data << " "; 66 | temp = temp->next; 67 | } 68 | cout << endl; 69 | } 70 | 71 | int main() { 72 | 73 | Node* head = new Node(1); 74 | head->next = new Node(3); 75 | head->next->next = new Node(2); 76 | head->next->next->next = new Node(4); 77 | 78 | 79 | cout << "Original Linked List: "; 80 | printLinkedList(head); 81 | 82 | 83 | head = reverseLinkedList(head); 84 | 85 | cout << "Reversed Linked List: "; 86 | printLinkedList(head); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /C/MatrixChainMultiplication.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void MatrixChainMultiplication(int p[], int n) { 6 | int m[n][n]; 7 | int s[n][n]; 8 | 9 | for (int i = 0; i < n; i++) { 10 | for (int j = 0; j < n; j++) { 11 | m[i][j]=0; 12 | } 13 | } 14 | 15 | for (int i = 0; i < n; i++) { 16 | for (int j = 0; j < n; j++) { 17 | s[i][j]=0; 18 | } 19 | } 20 | 21 | 22 | int j,q,min; 23 | for(int d=1;d 2 | #include 3 | 4 | void printSolution(int N, int board[N][N]) { 5 | for (int i = 0; i < N; i++) { 6 | for (int j = 0; j < N; j++) 7 | printf("%2d ", board[i][j]); 8 | printf("\n"); 9 | } 10 | } 11 | 12 | bool isSafe(int N, int board[N][N], int row, int col) { 13 | // Check this row on the left side 14 | for (int i = 0; i < col; i++) 15 | if (board[row][i]) 16 | return false; 17 | 18 | // Check upper diagonal on the left side 19 | for (int i = row, j = col; i >= 0 && j >= 0; i--, j--) 20 | if (board[i][j]) 21 | return false; 22 | 23 | // Check lower diagonal on the left side 24 | for (int i = row, j = col; i < N && j >= 0; i++, j--) 25 | if (board[i][j]) 26 | return false; 27 | 28 | return true; 29 | } 30 | 31 | bool solveNQueensUtil(int N, int board[N][N], int col) { 32 | if (col >= N) 33 | return true; 34 | 35 | for (int i = 0; i < N; i++) { 36 | if (isSafe(N, board, i, col)) { 37 | board[i][col] = 1; 38 | 39 | if (solveNQueensUtil(N, board, col + 1)) 40 | return true; 41 | 42 | board[i][col] = 0; // Backtrack 43 | } 44 | } 45 | 46 | return false; 47 | } 48 | 49 | bool solveNQueens(int N) { 50 | int board[N][N]; 51 | 52 | for (int i = 0; i < N; i++) 53 | for (int j = 0; j < N; j++) 54 | board[i][j] = 0; 55 | 56 | if (!solveNQueensUtil(N, board, 0)) { 57 | printf("Solution does not exist.\n"); 58 | return false; 59 | } 60 | 61 | printf("Solution for %d-Queens problem:\n", N); 62 | printSolution(N, board); 63 | return true; 64 | } 65 | 66 | int main() { 67 | int N; 68 | 69 | printf("Enter the value of N: "); 70 | scanf("%d", &N); 71 | 72 | solveNQueens(N); 73 | 74 | return 0; 75 | } -------------------------------------------------------------------------------- /C/reverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void reverseArrayExtraArray(int arr[], int size) 4 | { 5 | int reversedArr[size]; 6 | for (int i = 0; i < size; i++) { 7 | reversedArr[i] = arr[size - i - 1]; 8 | } 9 | 10 | // Print reversed array 11 | printf("Reversed Array: "); 12 | for (int i = 0; i < size; i++) { 13 | printf("%d ", reversedArr[i]); 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | int originalArr[] = { 1, 2, 3, 4, 5 }; 20 | int size = sizeof(originalArr) / sizeof(originalArr[0]); 21 | 22 | reverseArrayExtraArray(originalArr, size); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Java/Best_Time_to_Buy_and_Sell_Stock.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | int maxProfit = 0; 4 | int minValue = 100001; 5 | for(int i=0;i prices[i]){ 7 | minValue = prices[i]; 8 | } 9 | if(maxProfit < prices[i] - minValue){ 10 | maxProfit = prices[i] - minValue; 11 | } 12 | } 13 | return maxProfit; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Java/Combination Sum.java: -------------------------------------------------------------------------------- 1 | // this was the most common and highlt asked problem on FAANG Interviews from Leetcode 2 | // Approach - BackTracking 3 | 4 | class Solution { 5 | public List> combinationSum(int[] candidates, int target) { 6 | 7 | List active = new ArrayList<>(); 8 | List> ans = new ArrayList<>(); 9 | helper(0, target, candidates, active, ans); 10 | return ans; 11 | } 12 | static void helper (int index, int target, int[] candidates, List active, List> ans) { 13 | 14 | if (target == 0) { 15 | ans.add(new ArrayList<>(active)); 16 | return; 17 | } 18 | 19 | if (index == candidates.length) { 20 | return; 21 | } 22 | 23 | if (candidates[index] <= target) { 24 | active.add(candidates[index]); 25 | helper (index, target - candidates[index], candidates, active, ans); 26 | active.remove(active.size() - 1); 27 | } 28 | helper (index + 1, target, candidates, active, ans); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Java/Maximum_Subarray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxSubArray(int[] nums) { 3 | int len = nums.length; 4 | int currentMax = 0; 5 | int max = Integer.MIN_VALUE; 6 | 7 | for(int i:nums){ 8 | currentMax += i; 9 | if(max < currentMax){ 10 | max = currentMax; 11 | } 12 | if(currentMax < 0){ 13 | currentMax = 0; 14 | } 15 | } 16 | return max; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java/power_of_a_number.java: -------------------------------------------------------------------------------- 1 | public class PowerUsingLoop { 2 | public static void main(String[] args) { 3 | int base = 2; 4 | int exponent = 3; 5 | long result = 1; 6 | 7 | for (int i = 1; i <= exponent; i++) { 8 | result *= base; 9 | } 10 | 11 | System.out.println("Result: " + result); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java/two_sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] arr, int target) { 3 | int len = arr.length; 4 | int[] res = new int[2]; 5 | HashMap map = new HashMap(); 6 | 7 | for(int i=0; i < len; i++){ 8 | if(map.containsKey(target - arr[i])){ 9 | res[0] = (int) map.get(target - arr[i]); 10 | res[1] = i; 11 | return res; 12 | } 13 | map.put(arr[i],i); 14 | } 15 | return res; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Python/3d_Kadane's_Algorithm_code.py: -------------------------------------------------------------------------------- 1 | def findMaxSubCubeSum(matrix, M, N, O): 2 | # Initialize the maximum sum to the smallest possible integer 3 | maxSum = -(1 << 60) 4 | 5 | # Iterate over the first dimension of the 3D array 6 | for i in range(M): 7 | # Initialize a 2D temporary array to store intermediate sums 8 | temp = [[0] * N for _ in range(N)] 9 | 10 | # Iterate over the first dimension again 11 | for j in range(i, M): 12 | # Iterate over the second and third dimensions 13 | for k in range(N): 14 | for l in range(O): 15 | # Add the current element to the temporary array 16 | temp[k][l] += matrix[j][k][l] 17 | 18 | # Iterate over the second dimension 19 | for k in range(N): 20 | # Initialize another temporary array to store intermediate sums 21 | innerTemp = [0] * O 22 | kadane2 = [0] * O 23 | 24 | # Iterate over the second dimension again 25 | for l in range(k, N): 26 | # Iterate over the third dimension 27 | for m in range(O): 28 | # Add the current element to the inner temporary array 29 | innerTemp[m] += temp[l][m] 30 | 31 | # Copy the inner temporary array to another array 32 | kadane2 = innerTemp[:] 33 | 34 | for m in range(O): 35 | # If not the first element, add the previous element to the current element 36 | if m > 0: 37 | kadane2[m] += kadane2[m - 1] 38 | # If the current element is greater than the maximum sum, update the maximum sum 39 | if kadane2[m] > maxSum: 40 | maxSum = kadane2[m] 41 | # If the current element is less than 0, set it to 0 42 | if kadane2[m] < 0: 43 | kadane2[m] = 0 44 | 45 | # Return the maximum sum 46 | return maxSum 47 | 48 | 49 | # Example inputs 50 | M = 3 51 | N = 3 52 | O = 3 53 | matrix = [ 54 | [[-1, -2, 3], [-4, -5, 6], [7, 8, 9]], 55 | [[-9, -8, 7], [-6, -5, 4], [3, 2, 1]], 56 | [[-1, -3, 5], [-7, -9, 2], [4, 6, 8]] 57 | ] 58 | 59 | # Call the function to find the maximum sum of a sub-cube in the 3D array 60 | result = findMaxSubCubeSum(matrix, M, N, O) 61 | 62 | # Output the result 63 | print("The maximum sum of a sub-cube in the 3D array is:", result) 64 | # This code is contributed by Rupesh Kumar(kumarrupesh2310) 65 | -------------------------------------------------------------------------------- /Python/Binary-Search.py: -------------------------------------------------------------------------------- 1 | array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 2 | target = 7 3 | left = 0 4 | right = len(array) - 1 5 | found = False 6 | 7 | while left <= right: 8 | mid = left + (right - left) // 2 9 | if array[mid] == target: 10 | found = True 11 | break 12 | elif array[mid] < target: 13 | left = mid + 1 14 | else: 15 | right = mid - 1 16 | 17 | if found: 18 | print("Element found at index:", mid) 19 | else: 20 | print("Element not found") 21 | -------------------------------------------------------------------------------- /Python/Binary_Search_Tree.py: -------------------------------------------------------------------------------- 1 | def create_node(value): 2 | return {'value': value, 'left': None, 'right': None} 3 | 4 | def insert(root, value): 5 | if root is None: 6 | return create_node(value) 7 | if value < root['value']: 8 | root['left'] = insert(root['left'], value) 9 | else: 10 | root['right'] = insert(root['right'], value) 11 | return root 12 | 13 | def search(root, value): 14 | if root is None: 15 | return "Not Found" 16 | if root['value'] == value: 17 | return "Found" 18 | if value < root['value']: 19 | return search(root['left'], value) 20 | else: 21 | return search(root['right'], value) 22 | 23 | def find_min(root): 24 | while root['left'] is not None: 25 | root = root['left'] 26 | return root 27 | 28 | def delete(root, value): 29 | if root is None: 30 | return root 31 | if value < root['value']: 32 | root['left'] = delete(root['left'], value) 33 | elif value > root['value']: 34 | root['right'] = delete(root['right'], value) 35 | else: 36 | if root['left'] is None: 37 | return root['right'] 38 | elif root['right'] is None: 39 | return root['left'] 40 | min_node = find_min(root['right']) 41 | root['value'] = min_node['value'] 42 | root['right'] = delete(root['right'], min_node['value']) 43 | return root 44 | 45 | def in_order(root, result=[]): 46 | if root is not None: 47 | in_order(root['left'], result) 48 | result.append(root['value']) 49 | in_order(root['right'], result) 50 | return result 51 | 52 | root = None 53 | root = insert(root, 20) 54 | root = insert(root, 10) 55 | root = insert(root, 30) 56 | root = insert(root, 25) 57 | 58 | print(search(root, 25)) 59 | 60 | root = delete(root, 10) 61 | 62 | print(in_order(root)) 63 | -------------------------------------------------------------------------------- /Python/Create BFS.py: -------------------------------------------------------------------------------- 1 | graph = { 2 | '1' : ['2','3','4'], 3 | '2' : ['5', '6'], 4 | '3' : ['7','8'], 5 | '4' : ['9'], 6 | '5' : ['10','11'], 7 | '6' : [], 8 | '7' : ['12'], 9 | '8' : [], 10 | '9' : ['13'], 11 | '10' : [], 12 | '11' : ['14'], 13 | '12' : [], 14 | '13' : [], 15 | '14' : [] 16 | } 17 | 18 | visited = [] # this line is for visited list 19 | queue = [] # Initializing queue 20 | 21 | def bfs(visited, graph, node): 22 | visited.append(node) 23 | queue.append(node) 24 | 25 | while queue: 26 | s = queue.pop(0) 27 | print (s, end = " ") 28 | 29 | for neighbour in graph[s]: # here s is already popped out 30 | if neighbour not in visited: 31 | visited.append(neighbour) 32 | queue.append(neighbour) 33 | 34 | print("Following is the Breadth-First Search") 35 | bfs(visited, graph, '1') 36 | -------------------------------------------------------------------------------- /Python/Divide_Players_Into_Teams_Of_Equal_Skills.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def dividePlayers(self, skill: List[int]) -> int: 3 | # Step 1: Sort the skill array 4 | skill.sort() 5 | 6 | total_skill = skill[0] + skill[-1] # Required sum for each pair 7 | chemistry_sum = 0 8 | 9 | # Step 2: Pair players using two pointers 10 | for i in range(len(skill) // 2): 11 | # Check if the sum of current pair matches the required total_skill 12 | if skill[i] + skill[-i - 1] != total_skill: 13 | return -1 # Invalid configuration, return -1 14 | # Calculate the chemistry (product of pair) and add it to the sum 15 | chemistry_sum += skill[i] * skill[-i - 1] 16 | 17 | return chemistry_sum # Return total chemistry -------------------------------------------------------------------------------- /Python/Guessing_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess_the_number(): 4 | # Set the range for the random number 5 | lower_bound = 1 6 | upper_bound = 100 7 | 8 | # Generate a random number 9 | random_number = random.randint(lower_bound, upper_bound) 10 | 11 | # Set the number of attempts 12 | attempts = 7 13 | print(f"Guess the number between {lower_bound} and {upper_bound}. You have {attempts} attempts.") 14 | 15 | for attempt in range(1, attempts + 1): 16 | try: 17 | guess = int(input(f"Attempt {attempt}: Enter your guess: ")) 18 | if guess < lower_bound or guess > upper_bound: 19 | print(f"Please guess a number between {lower_bound} and {upper_bound}.") 20 | continue 21 | # Check if the guess is correct 22 | if guess == random_number: 23 | print(f"Congratulations! You guessed the correct number {random_number} in {attempt} attempts!") 24 | break 25 | elif guess < random_number: 26 | print("Too low! Try a higher number.") 27 | else: 28 | print("Too high! Try a lower number.") 29 | except ValueError: 30 | print("Please enter a valid number.") 31 | 32 | if attempt == attempts: 33 | print(f"Sorry, you've used all {attempts} attempts. The correct number was {random_number}. Better luck next time!") 34 | guess_the_number() 35 | -------------------------------------------------------------------------------- /Python/Min_elem_rotated_array.py: -------------------------------------------------------------------------------- 1 | def find_min_in_rotated_array(arr): 2 | low = 0 3 | high = len(arr) - 1 4 | 5 | if arr[low] <= arr[high]: 6 | return arr[low] 7 | 8 | while low <= high: 9 | mid = (low + high) // 2 10 | 11 | if mid > 0 and arr[mid] < arr[mid - 1]: 12 | return arr[mid] 13 | 14 | if mid < len(arr) - 1 and arr[mid] > arr[mid + 1]: 15 | return arr[mid + 1] 16 | 17 | if arr[mid] >= arr[low]: 18 | low = mid + 1 19 | else: 20 | high = mid - 1 21 | 22 | return -1 23 | 24 | rotated_array = [4, 5, 6, 7, 0, 1, 2] 25 | min_element = find_min_in_rotated_array(rotated_array) 26 | print("The minimum element is:", min_element) 27 | -------------------------------------------------------------------------------- /Python/Power_Of_Heros.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfPower(self, nums: List[int]) -> int: 3 | # Initialize the result variable 'ans' to store the final sum of power 4 | # 't' is a temporary variable to accumulate the sum of powers 5 | # 'base' is used to perform modulo 10^9 + 7 to prevent integer overflow 6 | ans, t, base = 0, 0, 10**9 + 7 7 | 8 | # Iterate over the sorted 'nums' list (sorting ensures elements are processed in ascending order) 9 | for c in sorted(nums): 10 | # Update 'ans' by adding the current power contribution for this element 'c' 11 | # Power contribution formula: (previous_sum + current_element) * current_element^2 12 | # This ensures we are calculating the power for each element and previous sums 13 | ans = (ans + (t + c) * c * c) % base 14 | 15 | # Update 't' which is used in the next iteration 16 | # 't' keeps track of the accumulated sum from previous iterations 17 | # Formula: 2 * previous_sum + current_element (to account for future contributions) 18 | t = (2 * t + c) % base 19 | 20 | # Return the final sum of powers modulo 10^9 + 7 21 | return ans 22 | -------------------------------------------------------------------------------- /Python/Score_of_string.py: -------------------------------------------------------------------------------- 1 | def scoreOfString(self, s): 2 | res = 0 3 | for i in range(len(s)-1): 4 | res += abs(ord(s[i]) - ord(s[i+1])) 5 | return res 6 | -------------------------------------------------------------------------------- /Python/Set_Matrix_Zeros.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | class Solution: 4 | def setZeroes(self, matrix: List[List[int]]) -> None: 5 | # Step 1: Handle edge case for an empty matrix 6 | if not matrix: 7 | return 8 | 9 | # Step 2: Get the dimensions of the matrix 10 | rows, cols = len(matrix), len(matrix[0]) 11 | 12 | # Step 3: Create a deep copy of the original matrix 13 | copy_matrix = [row[:] for row in matrix] 14 | 15 | # Step 4: Traverse the original matrix to find zeros 16 | for row in range(rows): 17 | for col in range(cols): 18 | if matrix[row][col] == 0: 19 | # Step 5: Mark the entire row with zeros in the copied matrix 20 | for k in range(cols): 21 | copy_matrix[row][k] = 0 22 | # Step 6: Mark the entire column with zeros in the copied matrix 23 | for k in range(rows): 24 | copy_matrix[k][col] = 0 25 | 26 | # Step 7: Copy the updated values back to the original matrix 27 | for row in range(rows): 28 | for col in range(cols): 29 | matrix[row][col] = copy_matrix[row][col] 30 | 31 | # Test cases 32 | def print_matrix(matrix): 33 | for row in matrix: 34 | print(row) 35 | print() 36 | 37 | # Example 1 38 | matrix1 = [[1,1,1], [1,0,1], [1,1,1]] 39 | print("Input:") 40 | print_matrix(matrix1) 41 | 42 | Solution().setZeroes(matrix1) 43 | print("Output:") 44 | print_matrix(matrix1) 45 | 46 | # Example 2 47 | matrix2 = [[0,1,2,0], [3,4,5,2], [1,3,1,5]] 48 | print("Input:") 49 | print_matrix(matrix2) 50 | 51 | Solution().setZeroes(matrix2) 52 | print("Output:") 53 | print_matrix(matrix2) 54 | -------------------------------------------------------------------------------- /Python/TicTacToeGUI.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | 3 | def set_title(row,column): 4 | if game_over: 5 | return 6 | global currentPlayer 7 | 8 | # Taken spot 9 | if board[row][column]["text"] != "": 10 | return 11 | 12 | board[row][column]["text"] = currentPlayer 13 | 14 | #switch player 15 | if currentPlayer == playerO: 16 | currentPlayer = playerX 17 | else: 18 | currentPlayer = playerO 19 | 20 | label["text"] = currentPlayer+"'s turn" 21 | 22 | # check winner 23 | check_winner() 24 | 25 | def check_winner(): 26 | global turns, game_over 27 | turns += 1 28 | 29 | # horizontally check 3 rows 30 | for row in range(3): 31 | if board[row][0]["text"]== board[row][1]["text"] == board[row][2]["text"] and board[row][0]["text"]!="": 32 | label.config(text=board[row][0]["text"]+" is the winner!", foreground=color_yellow) 33 | for column in range(3): 34 | board[row][column].config(foreground=color_yellow,background=color_ligh_gray) 35 | game_over = True 36 | return 37 | 38 | # vertically check 3 columns 39 | for column in range(3): 40 | if board[0][column]["text"] == board[1][column]["text"] == board[2][column]["text"] and board[0][column]["text"] != "": 41 | label.config(text=board[0][column]["text"]+" is the winner!", foreground=color_yellow) 42 | for row in range(3): 43 | board[row][column].config(foreground=color_yellow,background=color_ligh_gray) 44 | game_over = True 45 | return 46 | 47 | # Diagonally check 48 | if board[0][0]["text"] == board[1][1]["text"] == board[2][2]["text"] and board[0][0]["text"] !="": 49 | label.config(text=board[0][0]["text"]+" is the winner!", foreground=color_yellow) 50 | for i in range(3): 51 | board[i][i].config(foreground=color_yellow,background=color_ligh_gray) 52 | game_over = True 53 | return 54 | 55 | #anti-diagionally 56 | if (board[0][2]["text"] == board[1][1]["text"] == board[2][0]["text"] 57 | and board[0][2]["text"] != ""): 58 | label.config(text=board[0][2]["text"]+" is the winner!", foreground=color_yellow) 59 | board[0][2].config(foreground=color_yellow, background=color_ligh_gray) 60 | board[1][1].config(foreground=color_yellow, background=color_ligh_gray) 61 | board[2][0].config(foreground=color_yellow, background=color_ligh_gray) 62 | game_over = True 63 | return 64 | 65 | 66 | #tie 67 | if (turns == 9): 68 | game_over = True 69 | label.config(text="Tie!", foreground=color_yellow) 70 | 71 | def new_game(): 72 | global game_over,turns 73 | turns = 0 74 | game_over = False 75 | 76 | label.config(text=currentPlayer+"'s turn", foreground="white") 77 | for row in range(3): 78 | for column in range(3): 79 | board[row][column].config(text="", foreground=color_blue, background=color_gray) 80 | 81 | playerX = "X" 82 | playerO = "O" 83 | currentPlayer = playerX 84 | 85 | board = [["0","0","0"], 86 | ["0","0","0"], 87 | ["0","0","0"]] 88 | 89 | turns = 0 90 | game_over = False 91 | 92 | color_blue = "#4584b6" 93 | color_yellow = "#ffde57" 94 | color_gray = "#343434" 95 | color_ligh_gray = "#646464" 96 | 97 | window = tkinter.Tk() 98 | window.title("Tic Tac Toe") 99 | window.resizable(False,False) 100 | 101 | 102 | frame = tkinter.Frame(window) 103 | label = tkinter.Label(frame,text=currentPlayer+"'s turn",font=("Consolas",20), background= color_gray,foreground="white") 104 | label.grid(row=0,column=0,columnspan=3,sticky="we") 105 | 106 | for row in range(3): 107 | for column in range(3): 108 | board[row][column] = tkinter.Button(frame,text="",font=("Consolas",50,"bold"),background= color_gray,foreground=color_blue,width=4,height=1, 109 | command=lambda row=row, column=column:set_title(row,column)) 110 | board[row][column].grid(row = row+1,column = column) 111 | 112 | button = tkinter.Button(frame,text="Restart",font=("Consolas",20), background= color_gray,foreground="white",command=new_game) 113 | button.grid(row=4,column=0,columnspan=3,sticky="we") 114 | 115 | frame.pack() 116 | 117 | # center the window 118 | 119 | window.update() 120 | window_width = window.winfo_width() 121 | window_height = window.winfo_height() 122 | screen_width = window.winfo_screenwidth() 123 | screen_height = window.winfo_screenheight() 124 | 125 | window_x = int((screen_width/2) - (window_width/2)) 126 | window_y = int((screen_height/2) - (window_height/2)) 127 | 128 | #formate 129 | window.geometry(f"{window_width}x{window_height}+{window_x}+{window_y}") 130 | window.mainloop() -------------------------------------------------------------------------------- /Python/Tim_Sort.py: -------------------------------------------------------------------------------- 1 | MIN_RUN = 32 2 | 3 | def insertion_sort(arr, left, right): 4 | """ 5 | Perform insertion sort on a subarray from index 'left' to 'right'. 6 | 7 | Args: 8 | arr (list): The list to be sorted. 9 | left (int): The starting index of the subarray. 10 | right (int): The ending index of the subarray. 11 | """ 12 | for i in range(left + 1, right + 1): 13 | key_item = arr[i] 14 | j = i - 1 15 | while j >= left and arr[j] > key_item: 16 | arr[j + 1] = arr[j] 17 | j -= 1 18 | arr[j + 1] = key_item 19 | 20 | def merge(arr, left, mid, right): 21 | """ 22 | Merge two sorted subarrays into a single sorted array. 23 | 24 | Args: 25 | arr (list): The original array with two sorted subarrays. 26 | left (int): The starting index of the left subarray. 27 | mid (int): The ending index of the left subarray and middle point. 28 | right (int): The ending index of the right subarray. 29 | """ 30 | left_part = arr[left:mid + 1] 31 | right_part = arr[mid + 1:right + 1] 32 | 33 | i = 0 34 | j = 0 35 | k = left 36 | 37 | while i < len(left_part) and j < len(right_part): 38 | if left_part[i] <= right_part[j]: 39 | arr[k] = left_part[i] 40 | i += 1 41 | else: 42 | arr[k] = right_part[j] 43 | j += 1 44 | k += 1 45 | 46 | 47 | while i < len(left_part): 48 | arr[k] = left_part[i] 49 | i += 1 50 | k += 1 51 | 52 | while j < len(right_part): 53 | arr[k] = right_part[j] 54 | j += 1 55 | k += 1 56 | 57 | def tim_sort(arr): 58 | """ 59 | Perform TimSort on the input array. 60 | 61 | TimSort is a hybrid sorting algorithm derived from merge sort and insertion sort. It sorts smaller chunks using insertion sort, then merges them using a merge sort. 62 | 63 | Args: 64 | arr (list): The list to be sorted. 65 | """ 66 | n = len(arr) 67 | 68 | 69 | for start in range(0, n, MIN_RUN): 70 | end = min(start + MIN_RUN - 1, n - 1) 71 | insertion_sort(arr, start, end) 72 | 73 | 74 | size = MIN_RUN 75 | while size < n: 76 | for left in range(0, n, 2 * size): 77 | mid = min(n - 1, left + size - 1) 78 | right = min(left + 2 * size - 1, n - 1) 79 | 80 | if mid < right: 81 | merge(arr, left, mid, right) 82 | 83 | size *= 2 84 | 85 | # Test cases 86 | if __name__ == "__main__": 87 | def test_tim_sort(): 88 | test_cases = [ 89 | ([12, 11, 13, 5, 6, 7], [5, 6, 7, 11, 12, 13]), # Random order 90 | ([], []), # Empty array 91 | ([1], [1]), # Single element 92 | ([3, 1, 2], [1, 2, 3]), # Small array 93 | ([5, 5, 5, 5], [5, 5, 5, 5]), # All elements the same 94 | ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]), # Already sorted 95 | ([9, 7, 5, 3, 1], [1, 3, 5, 7, 9]) # Reverse order 96 | ] 97 | 98 | for i, (input_data, expected) in enumerate(test_cases): 99 | tim_sort(input_data) 100 | assert input_data == expected, f"Test case {i+1} failed: {input_data} != {expected}" 101 | print(f"Test case {i+1} passed.") 102 | 103 | test_tim_sort() 104 | -------------------------------------------------------------------------------- /Python/Valid_Number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isNumber(self, s: str) -> bool: 3 | # Define state transitions for the finite state machine 4 | transitions = { 5 | 'Start': {'digit': 'Integer', 'sign': 'Sign', 'dot': 'Dot'}, 6 | 'Sign': {'digit': 'Integer', 'dot': 'Dot'}, 7 | 'Integer': {'digit': 'Integer', 'dot': 'Fraction', 'e': 'Exponent'}, 8 | 'Dot': {'digit': 'Fraction'}, 9 | 'Fraction': {'digit': 'Fraction', 'e': 'Exponent'}, 10 | 'Exponent': {'digit': 'Exp_number', 'sign': 'Exp_sign'}, 11 | 'Exp_sign': {'digit': 'Exp_number'}, 12 | 'Exp_number': {'digit': 'Exp_number'} 13 | } 14 | 15 | # Define valid ending states for a valid number 16 | valid_end_states = {'Integer', 'Fraction', 'Exp_number'} 17 | 18 | # Function to determine the type of character 19 | def get_char_type(char): 20 | if char.isdigit(): 21 | return 'digit' 22 | if char in '+-': 23 | return 'sign' 24 | if char in 'eE': 25 | return 'e' 26 | if char == '.': 27 | return 'dot' 28 | return None # Invalid character 29 | 30 | # Start in the 'Start' state 31 | current_state = 'Start' 32 | 33 | # Process each character in the input string 34 | for char in s: 35 | char_type = get_char_type(char) # Get the character type 36 | # If the character type is invalid or not allowed from the current state 37 | if not char_type or char_type not in transitions[current_state]: 38 | return False 39 | # Move to the next state based on the current state and character type 40 | current_state = transitions[current_state][char_type] 41 | 42 | # Check if the final state is one of the valid end states 43 | return current_state in valid_end_states 44 | 45 | 46 | # Test cases 47 | solution = Solution() 48 | 49 | # Example 1 50 | print(solution.isNumber("0")) # Output: True 51 | 52 | # Example 2 53 | print(solution.isNumber("e")) # Output: False 54 | 55 | # Example 3 56 | print(solution.isNumber(".")) # Output: False 57 | 58 | # Additional test cases 59 | print(solution.isNumber("3.14")) # Output: True 60 | print(solution.isNumber("-42")) # Output: True 61 | print(solution.isNumber("1e10")) # Output: True 62 | print(solution.isNumber("1E-10")) # Output: True 63 | print(solution.isNumber("+.8")) # Output: True 64 | print(solution.isNumber("-.5e2")) # Output: True 65 | print(solution.isNumber("+-5")) # Output: False 66 | print(solution.isNumber("12e")) # Output: False 67 | print(solution.isNumber("1.2.3")) # Output: False 68 | -------------------------------------------------------------------------------- /Python/mergesort.py: -------------------------------------------------------------------------------- 1 | def merge_sort(arr): 2 | if len(arr) > 1: 3 | # Finding the middle of the array 4 | mid = len(arr) // 2 5 | 6 | # Dividing the array elements into 2 halves 7 | left_half = arr[:mid] 8 | right_half = arr[mid:] 9 | 10 | # Recursively sorting the two halves 11 | merge_sort(left_half) 12 | merge_sort(right_half) 13 | 14 | i = j = k = 0 15 | 16 | # Merging the sorted halves 17 | while i < len(left_half) and j < len(right_half): 18 | if left_half[i] < right_half[j]: 19 | arr[k] = left_half[i] 20 | i += 1 21 | else: 22 | arr[k] = right_half[j] 23 | j += 1 24 | k += 1 25 | 26 | # Checking if any element was left 27 | while i < len(left_half): 28 | arr[k] = left_half[i] 29 | i += 1 30 | k += 1 31 | 32 | while j < len(right_half): 33 | arr[k] = right_half[j] 34 | j += 1 35 | k += 1 36 | 37 | # Example usage: 38 | arr = [12, 11, 13, 5, 6, 7] 39 | print("Given array is", arr) 40 | merge_sort(arr) 41 | print("Sorted array is", arr) 42 | -------------------------------------------------------------------------------- /Python/multilevel queue scheduling.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter the number of processes : ")) 2 | #print(n) 3 | p = [0] * n 4 | bt = [0] * n 5 | wt = [0] * n 6 | tat = [0] * n 7 | su = [0] * n 8 | for i in range(n): 9 | p[i] = i+1 10 | bt[i] = int(input("Enter the burst time for process " + str(i+1) + ": ")) 11 | su[i] = int(input("System/User process (0/1) ? ")) 12 | 13 | for i in range(n): 14 | for j in range(i+1, n): 15 | if su[i] > su[j]: 16 | p[i], p[j] = p[j], p[i] 17 | bt[i], bt[j] = bt[j], bt[i] 18 | su[i], su[j] = su[j], su[i] 19 | 20 | wtavg = 0 21 | tatavg = 0 22 | 23 | for i in range(1, n): 24 | wt[i] = wt[i-1] + bt[i-1] 25 | tat[i] = tat[i-1] + bt[i] 26 | wtavg += wt[i] 27 | tatavg += tat[i] 28 | 29 | print("PROCESS\tSYSTEM/USER PROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n") 30 | 31 | for i in range(n): 32 | print(str(p[i]) + "\t\t" + str(su[i]) + "\t\t" + str(bt[i]) + "\t\t" + str(wt[i]) + "\t\t" + str(tat[i])) 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🎃 Welcome to **HacktoberFest Contribution 2024**! 🎃 2 | [![Hacktoberfest](https://img.shields.io/badge/Hacktoberfest-2024-orange?style=for-the-badge)](https://hacktoberfest.com) 3 | [![Star this Repo](https://img.shields.io/github/stars/harsh-dart/HactoberFest2024)](https://github.com/Lavanyasuc31/HactoberFestContribution2024) 4 | 5 | Hey there, awesome people! 👋 Welcome to **HacktoberFest 2024**! 🚀 This is a fun and beginner-friendly repository designed for you to make your very first Pull Request (PR) and join the world of open source! 🌍✨ 6 | 7 | --- 8 | 9 | ## 🍁 What is Hacktoberfest? 10 | 11 | **Hacktoberfest** is an amazing event that happens every October, where developers from all over the world contribute to open-source projects and get rewarded with **cool swags** 🛍️ like **T-shirts**, **stickers**, and so much more! 12 | 13 | ### 🏆 How to Win Swag 14 | Make **4 valid pull requests** in any open-source projects during October, and you'll earn **exclusive** Hacktoberfest swag! 💥 15 | 16 | 👉 Check out the details and register [here](https://hacktoberfest.com/). Go grab that swag! 💪🎁 17 | 18 | --- 19 | 20 | ### 🌟 Remember: Keep your projects beginner-friendly, well-commented, and submit your own original work! 21 | 22 | --- 23 | 24 | ## 💡 Why Contribute? 25 | 26 | - 🥳 Gain experience with Git and GitHub. 27 | - 🎁 Win cool Hacktoberfest swag! 28 | - 🤝 Meet and collaborate with awesome developers worldwide! 29 | - ⭐ Earn a **star** for contributing to this project! 30 | - 🏅 And of course, brag about your **first PR**! 31 | 32 | --- 33 | 34 | ## 🌈 Join the Fun – Follow Me! 🌈 35 | -------------------------------------------------------------------------------- /WebProjects/birthday-invite-project.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Happy Birthday! 7 | 67 | 68 | 69 |
70 |

It's my birthday!

71 |

On the 12th of May

72 | Birthday Cake 73 |

What to bring:

74 |
    75 |
  • Balloons
  • 76 |
  • Cake
  • 77 |
  • Appetite
  • 78 |
79 |

This is where you need to go:

80 | Google Map Link 81 |
82 | 83 | 84 | -------------------------------------------------------------------------------- /WebProjects/dice game/images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/WebProjects/dice game/images/1.jpg -------------------------------------------------------------------------------- /WebProjects/dice game/images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/WebProjects/dice game/images/2.jpg -------------------------------------------------------------------------------- /WebProjects/dice game/images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/WebProjects/dice game/images/3.jpg -------------------------------------------------------------------------------- /WebProjects/dice game/images/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/WebProjects/dice game/images/4.jpg -------------------------------------------------------------------------------- /WebProjects/dice game/images/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/WebProjects/dice game/images/5.jpg -------------------------------------------------------------------------------- /WebProjects/dice game/images/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh-dart/HactoberFest2024/cc3d085b3fbbe1b36e7079f741c7395c148689b9/WebProjects/dice game/images/6.jpg -------------------------------------------------------------------------------- /WebProjects/dice game/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DICE-GAME 7 | 8 | 9 | 10 |

PLAY TO WIN

11 |
12 |
13 | 14 |

PLAYER1

15 |
16 |
17 | 18 |

PLAYER2

19 |
20 |
21 |
JUST REFRESH ME!
22 | 23 | 24 | -------------------------------------------------------------------------------- /WebProjects/dice game/main.js: -------------------------------------------------------------------------------- 1 | let image1 = document.querySelector(".dice1 img"); 2 | let image2 = document.querySelector(".dice2 img"); 3 | let num1=Math.floor(Math.random()*6+1); 4 | let newsrc1="images/"+num1+".jpg"; 5 | image1.setAttribute("src",newsrc1); 6 | let num2=Math.floor(Math.random()*6+1); 7 | let newsrc2="images/"+num2+".jpg"; 8 | image2.setAttribute("src",newsrc2); 9 | let el = document.createElement("div"); 10 | el.classList.add("winningmessage"); 11 | el.style.backgroundColor = "yellow"; 12 | el.style.fontFamily = "cursive"; 13 | el.style.fontSize = "50px"; 14 | el.style.textAlign = "center"; 15 | document.body.appendChild(el); 16 | if (num1 > num2) { 17 | el.innerHTML = "Player 1 is the winner"; 18 | } else if (num1 < num2) { 19 | el.innerHTML = "Player 2 is the winner"; 20 | } else { 21 | el.innerHTML = "It is a draw"; 22 | } -------------------------------------------------------------------------------- /WebProjects/dice game/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | background-color: grey; 5 | } 6 | 7 | h1 { 8 | font-family: cursive; 9 | font-size: 70px; 10 | color: black; 11 | font-weight: 300; 12 | text-align: center; 13 | text-decoration: underline; 14 | margin-top: 0; 15 | padding-top: 0; 16 | } 17 | 18 | .container { 19 | display: flex; 20 | justify-content: center; 21 | align-items: center; 22 | flex-wrap: wrap; 23 | padding: 30px; 24 | margin: 20px; 25 | min-height: 40vh; 26 | gap: 70px; 27 | } 28 | 29 | .dice1, 30 | .dice2 { 31 | display: flex; 32 | flex-direction: column; 33 | object-fit: cover; 34 | justify-content: center; 35 | align-items: center; 36 | margin: 30px; 37 | padding: 20px; 38 | border: 3px solid black; 39 | } 40 | 41 | .dice1 img, 42 | .dice2 img { 43 | height: 150px; 44 | width: 150px; 45 | border-radius: 5%; 46 | } 47 | 48 | .dice1 p, 49 | .dice2 p, 50 | h6 { 51 | font-family: cursive; 52 | font-size: 24px; 53 | text-align: center; 54 | margin: 10px 0 0 0; 55 | padding: 10px; 56 | } 57 | 58 | @media (max-width: 575.98px) { 59 | .container { 60 | padding: 5px; 61 | margin: 5px; 62 | gap: 10px; 63 | } 64 | 65 | .dice1, 66 | .dice2 { 67 | margin: 5px; 68 | padding: 5px; 69 | } 70 | } 71 | 72 | @media (min-width: 576px) and (max-width: 767.98px) { 73 | .container { 74 | padding: 10px; 75 | margin: 10px; 76 | gap: 20px; 77 | } 78 | 79 | .dice1, 80 | .dice2 { 81 | margin: 10px; 82 | padding: 10px; 83 | } 84 | } 85 | 86 | @media (min-width: 768px) and (max-width: 991.98px) { 87 | .container { 88 | padding: 15px; 89 | margin: 15px; 90 | gap: 30px; 91 | } 92 | 93 | .dice1, 94 | .dice2 { 95 | margin: 15px; 96 | padding: 15px; 97 | } 98 | } 99 | 100 | @media (min-width: 992px) and (max-width: 1199.98px) { 101 | .container { 102 | padding: 20px; 103 | margin: 20px; 104 | gap: 40px; 105 | } 106 | 107 | .dice1, 108 | .dice2 { 109 | margin: 20px; 110 | padding: 20px; 111 | } 112 | } 113 | 114 | @media (min-width: 1200px) { 115 | .container { 116 | padding: 30px; 117 | margin: 30px; 118 | gap: 60px; 119 | } 120 | 121 | .dice1, 122 | .dice2 { 123 | margin: 30px; 124 | padding: 30px; 125 | } 126 | } 127 | --------------------------------------------------------------------------------