├── C++ ├── Binary Search ├── Binary_to_Decimal.cpp ├── Decimal_to_Binary.cpp ├── Deque.cpp ├── Factorial │ ├── usingRecursion.cpp │ ├── usingRecursion.exe │ ├── usingRecusrsionOptimized.cpp │ └── usingRecusrsionOptimized.exe ├── HCF_of_two_numbers.cpp ├── HeapSort.cpp ├── InsertionSort.cpp ├── Largest_element_in_array.cpp ├── Leap_Year_Program.cpp ├── Linear_Search.cpp ├── Number_of _words_in_String.cpp ├── Program To Find LCM of Two Numbers.cpp ├── Program for Linear Search.cpp ├── Program to create Floyd's Triangle ├── Reverse_the_array.cpp ├── binary search.cpp ├── bubble_sort.cpp ├── checkDecreasing ├── checkDecreasing.cpp ├── checkEvenOdd ├── checkEvenOdd.cpp ├── checkIncreasing ├── checkIncreasing.cpp ├── checkPrime ├── checkPrime.cpp ├── count_divisible_pairs_in_an_array ├── count_sort.cpp ├── decimalToBinary.cpp ├── factorial using recursion.cpp ├── floyds.cpp ├── floyds.exe ├── helloWorld.cpp ├── linear search.cpp ├── palindrome.cpp ├── queueDS_Array.cpp ├── queueDS_LL.cpp ├── reverse_word.cpp ├── reversearray.cpp ├── reverseinteger.cpp ├── seive_of_eratosthenes.cpp ├── stack.cpp ├── string revresal.cpp ├── twinPrime └── twinPrime.cpp ├── Java ├── Dque.java ├── LCM_2_numbers.java ├── SecondLargestArray │ ├── secondLargestArray.class │ └── secondLargestArray.java ├── Stack │ └── Implement stack using dynamic array.java ├── binarysearch.java ├── bubblesort.java ├── daemontable.java ├── helloWorld.java ├── integertoroman.java ├── lengthOfLastWord.java ├── lowestCommonAncestor.java ├── perfectnumber.java ├── smallestInAnArray.java └── stack.java ├── JavaScript ├── GridSystem │ └── grid system fireship │ │ ├── animated-grid.css │ │ ├── animated-grid.html │ │ ├── base-grid.css │ │ ├── base.css │ │ ├── basegrid.html │ │ ├── photo-grid.css │ │ └── photo-grid.html └── WeatherApp │ └── Weather App │ ├── download.jfif │ ├── index.html │ └── script.js ├── Python ├── Alarm_Clock.py ├── Deque.py ├── factorial.py ├── helloWorld.py ├── password_generator.py ├── roadCrossing Game.py └── stack.py └── README.md /C++/Binary Search: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int arr[100],beg,mid,end,i,n,num; 8 | 9 | cout << "\n Enter the size of an array "; 10 | cin >> n; 11 | 12 | cout << "\n Enter the values in sorted order (asc or desc) \n"; 13 | 14 | for(i = 0; i < n;i++) 15 | { 16 | cin >> arr[i]; 17 | } 18 | 19 | 20 | /* Initialize beg and end value. */ 21 | 22 | beg = 0; 23 | end = n-1; 24 | 25 | cout << "\n Enter a value to be searched in an array "; 26 | cin >> num; 27 | 28 | /* Run loop, while beg is less than end. */ 29 | 30 | while( beg <= end) 31 | { 32 | 33 | /* Calculate mid. */ 34 | 35 | mid = (beg+end)/2; 36 | 37 | /* If value is found at mid index, 38 | the print the position and exit. */ 39 | 40 | if(arr[mid] == num) 41 | { 42 | cout << "\nItem found at position "<< (mid+1); 43 | 44 | exit(0); 45 | 46 | } else if(num > arr[mid]) { 47 | 48 | beg=mid+1; 49 | 50 | } else if (num < arr[mid]) { 51 | 52 | end=mid-1; 53 | 54 | } 55 | 56 | } 57 | 58 | cout << "Number does not found."; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /C++/Binary_to_Decimal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | string s; 8 | cin>>s; 9 | int size=s.size(); 10 | long long Decimal_Number=0; 11 | for(int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int decimal_number; 8 | cin>>decimal_number; 9 | int binary[32]={0}; 10 | int i=0; 11 | while(decimal_number>0) 12 | { 13 | binary[31-i]=decimal_number%2; 14 | decimal_number/=2; 15 | i++; 16 | } 17 | for(int i=0;i<32;i++) 18 | { 19 | cout< 4 | using namespace std; 5 | 6 | #define MAX 10 7 | 8 | class Deque { 9 | int arr[MAX]; 10 | int front; 11 | int rear; 12 | int size; 13 | 14 | public: 15 | Deque(int size) { 16 | front = -1; 17 | rear = 0; 18 | this->size = size; 19 | } 20 | 21 | void insertfront(int key); 22 | void insertrear(int key); 23 | void deletefront(); 24 | void deleterear(); 25 | bool isFull(); 26 | bool isEmpty(); 27 | int getFront(); 28 | int getRear(); 29 | }; 30 | 31 | bool Deque::isFull() { 32 | return ((front == 0 && rear == size - 1) || 33 | front == rear + 1); 34 | } 35 | 36 | bool Deque::isEmpty() { 37 | return (front == -1); 38 | } 39 | 40 | void Deque::insertfront(int key) { 41 | if (isFull()) { 42 | cout << "Overflow\n" 43 | << endl; 44 | return; 45 | } 46 | 47 | if (front == -1) { 48 | front = 0; 49 | rear = 0; 50 | } 51 | 52 | else if (front == 0) 53 | front = size - 1; 54 | 55 | else 56 | front = front - 1; 57 | 58 | arr[front] = key; 59 | } 60 | 61 | void Deque ::insertrear(int key) { 62 | if (isFull()) { 63 | cout << " Overflow\n " << endl; 64 | return; 65 | } 66 | 67 | if (front == -1) { 68 | front = 0; 69 | rear = 0; 70 | } 71 | 72 | else if (rear == size - 1) 73 | rear = 0; 74 | 75 | else 76 | rear = rear + 1; 77 | 78 | arr[rear] = key; 79 | } 80 | 81 | void Deque ::deletefront() { 82 | if (isEmpty()) { 83 | cout << "Queue Underflow\n" 84 | << endl; 85 | return; 86 | } 87 | 88 | if (front == rear) { 89 | front = -1; 90 | rear = -1; 91 | } else if (front == size - 1) 92 | front = 0; 93 | 94 | else 95 | front = front + 1; 96 | } 97 | 98 | void Deque::deleterear() { 99 | if (isEmpty()) { 100 | cout << " Underflow\n" 101 | << endl; 102 | return; 103 | } 104 | 105 | if (front == rear) { 106 | front = -1; 107 | rear = -1; 108 | } else if (rear == 0) 109 | rear = size - 1; 110 | else 111 | rear = rear - 1; 112 | } 113 | 114 | int Deque::getFront() { 115 | if (isEmpty()) { 116 | cout << " Underflow\n" 117 | << endl; 118 | return -1; 119 | } 120 | return arr[front]; 121 | } 122 | 123 | int Deque::getRear() { 124 | if (isEmpty() || rear < 0) { 125 | cout << " Underflow\n" 126 | << endl; 127 | return -1; 128 | } 129 | return arr[rear]; 130 | } 131 | 132 | int main() { 133 | Deque dq(4); 134 | 135 | cout << "insert element at rear end \n"; 136 | dq.insertrear(5); 137 | dq.insertrear(11); 138 | 139 | cout << "rear element: " 140 | << dq.getRear() << endl; 141 | 142 | dq.deleterear(); 143 | cout << "after deletion of the rear element, the new rear element: " << dq.getRear() << endl; 144 | 145 | cout << "insert element at front end \n"; 146 | 147 | dq.insertfront(8); 148 | 149 | cout << "front element: " << dq.getFront() << endl; 150 | 151 | dq.deletefront(); 152 | 153 | cout << "after deletion of front element new front element: " << dq.getFront() << endl; 154 | } -------------------------------------------------------------------------------- /C++/Factorial/usingRecursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // TIme complexity of factorial using recursion is O(2^n) and space complexity is O(n). 5 | // This is because for every call of the function, we are creating a new stack frame and storing the value of n in it. 6 | // This is not an efficient way of calculating factorial. 7 | 8 | int factorial(int n) 9 | { 10 | if (n == 0) // base case 11 | return 1; 12 | else 13 | return n * factorial(n - 1); // recursively calling the function for n-1 and multiplying it with n 14 | } 15 | 16 | int main() 17 | { 18 | int n, fact = 1; 19 | cout << "Enter a number: "; 20 | cin >> n; 21 | cout << factorial(n) << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++/Factorial/usingRecursion.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoolRekha/Programs/26d3262072240183e5dac383bdad3ff31f750d37/C++/Factorial/usingRecursion.exe -------------------------------------------------------------------------------- /C++/Factorial/usingRecusrsionOptimized.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // Optimized factorial using recursion where we are storing the value of n! in a vector 6 | // and then returning it when we need it again. 7 | // Time complexity of this approach is O(n) and space complexity is O(n) as well. 8 | 9 | int factorial(int n, vector &dp) 10 | { 11 | if (n == 0) // base case 12 | return 1; 13 | else if (dp[n] != -1) 14 | return dp[n]; 15 | else 16 | return n * factorial(n - 1, dp); // recursively calling the function for n-1 and multiplying it with n 17 | } 18 | 19 | int main() 20 | { 21 | int n, fact = 1; 22 | cout << "Enter a number: "; 23 | cin >> n; 24 | vector dp(n + 1, -1); 25 | cout << factorial(n, dp) << endl; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++/Factorial/usingRecusrsionOptimized.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoolRekha/Programs/26d3262072240183e5dac383bdad3ff31f750d37/C++/Factorial/usingRecusrsionOptimized.exe -------------------------------------------------------------------------------- /C++/HCF_of_two_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int num1 = 36, num2 = 60, hcf = 1; 7 | 8 | for(int i = 1; i <= num1 || i <= num2; i++) 9 | { 10 | if(num1 % i == 0 && num2 % i == 0) 11 | hcf = i; 12 | } 13 | 14 | cout<<"HCF of "< 4 | using namespace std; 5 | 6 | // To heapify a subtree rooted with node i 7 | // which is an index in arr[]. 8 | // n is size of heap 9 | void heapify(int arr[], int N, int i) 10 | { 11 | 12 | // Initialize largest as root 13 | int largest = i; 14 | 15 | // left = 2*i + 1 16 | int l = 2 * i + 1; 17 | 18 | // right = 2*i + 2 19 | int r = 2 * i + 2; 20 | 21 | // If left child is larger than root 22 | if (l < N && arr[l] > arr[largest]) 23 | largest = l; 24 | 25 | // If right child is larger than largest 26 | // so far 27 | if (r < N && arr[r] > arr[largest]) 28 | largest = r; 29 | 30 | // If largest is not root 31 | if (largest != i) { 32 | swap(arr[i], arr[largest]); 33 | 34 | // Recursively heapify the affected 35 | // sub-tree 36 | heapify(arr, N, largest); 37 | } 38 | } 39 | 40 | // Main function to do heap sort 41 | void heapSort(int arr[], int N) 42 | { 43 | 44 | // Build heap (rearrange array) 45 | for (int i = N / 2 - 1; i >= 0; i--) 46 | heapify(arr, N, i); 47 | 48 | // One by one extract an element 49 | // from heap 50 | for (int i = N - 1; i > 0; i--) { 51 | 52 | // Move current root to end 53 | swap(arr[0], arr[i]); 54 | 55 | // call max heapify on the reduced heap 56 | heapify(arr, i, 0); 57 | } 58 | } 59 | 60 | // A utility function to print array of size n 61 | void printArray(int arr[], int N) 62 | { 63 | for (int i = 0; i < N; ++i) 64 | cout << arr[i] << " "; 65 | cout << "\n"; 66 | } 67 | 68 | // Driver's code 69 | int main() 70 | { 71 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 72 | int N = sizeof(arr) / sizeof(arr[0]); 73 | 74 | // Function call 75 | heapSort(arr, N); 76 | 77 | cout << "Sorted array is \n"; 78 | printArray(arr, N); 79 | } 80 | // ayushi singh 81 | -------------------------------------------------------------------------------- /C++/InsertionSort.cpp: -------------------------------------------------------------------------------- 1 | // Time Complexity 2 | // Worst Case O(n^2) 3 | // Average Case θ(n^2) 4 | // Best Case Ω(n) 5 | 6 | // Space Complexity O(1) 7 | 8 | #include 9 | using namespace std; 10 | 11 | void file_i_o() { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | #ifndef ONLINE_JUDGE 16 | freopen("../Input.txt","r",stdin); 17 | freopen("../Output.txt","w",stdout); 18 | #endif 19 | } 20 | 21 | void InsertionSort(vector&arrayInt) { 22 | for(int i=1; i=0 && arrayInt[j]>temp) { 26 | arrayInt[j+1] = arrayInt[j]; 27 | j--; 28 | } 29 | arrayInt[j+1] = temp; 30 | } 31 | } 32 | 33 | void printArray(vectorarrayInt) { 34 | for(int i=0; i>size; 43 | vectorarrayInt(size); 44 | for(int i=0; i>arrayInt[i]; 46 | 47 | InsertionSort(arrayInt); 48 | printArray(arrayInt); 49 | return 0; 50 | } -------------------------------------------------------------------------------- /C++/Largest_element_in_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int size; 8 | cin>>size; 9 | int array[size]; 10 | int MAX_ELEMENT=-1e5; 11 | for(int i=0;i>array[i]; 14 | if(array[i]>MAX_ELEMENT) 15 | { 16 | MAX_ELEMENT=array[i]; 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int year; 7 | cout<<"enter the year : "; 8 | cin>>year; 9 | 10 | if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) 11 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int input[100], count, i, num; 6 | 7 | cout << "Enter Number of Elements in Array\n"; 8 | cin >> count; 9 | 10 | cout << "Enter " << count << " numbers \n"; 11 | 12 | // Read array elements 13 | for(i = 0; i < count; i++){ 14 | cin >> input[i]; 15 | } 16 | 17 | cout << "Enter a number to serach in Array\n"; 18 | cin >> num; 19 | 20 | // search num in inputArray from index 0 to elementCount-1 21 | for(i = 0; i < count; i++){ 22 | if(input[i] == num){ 23 | cout << "Element found at index " << i; 24 | break; 25 | } 26 | } 27 | 28 | if(i == count){ 29 | cout << "Element Not Present in Input Array\n"; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++/Number_of _words_in_String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | string s; 8 | cin>>s; 9 | int size=s.size(); 10 | int number_of_words=0; 11 | for(int i=0;i64) || (s[i]>96 && s[i]<123)){ 13 | number_of_words++; 14 | } 15 | 16 | } 17 | cout< 6 | using namespace std; 7 | 8 | 9 | long long gcd(long long int a, 10 | long long int b) 11 | { 12 | if (b == 0) 13 | return a; 14 | return gcd(b, a % b); 15 | } 16 | 17 | 18 | long long lcm(int a, int b) 19 | { 20 | return (a / gcd(a, b)) * b; 21 | } 22 | 23 | // Driver code 24 | int main() 25 | { 26 | int a = 15, b = 20; 27 | cout << "LCM of " << a << 28 | " and " << b << 29 | " is " << lcm(a, b); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C++/Program for Linear Search.cpp: -------------------------------------------------------------------------------- 1 | Program for Linear Search 2 | 3 | // code 4 | 5 | #include 6 | using namespace std; 7 | 8 | int search(int arr[], int n, int x) 9 | { 10 | int i; 11 | for (i = 0; i < n; i++) 12 | if (arr[i] == x) 13 | return i; 14 | return -1; 15 | } 16 | 17 | int main() 18 | { 19 | int arr[] = { 3, 4, 1, 7, 5 }; 20 | int n = sizeof(arr) / sizeof(arr[0]); 21 | int x = 4; 22 | 23 | int index = search(arr, n, x); 24 | if (index == -1) 25 | cout << "Element is not present in the array"; 26 | else 27 | cout << "Element found at position " << index; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C++/Program to create Floyd's Triangle: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, i, c, a = 1; 7 | 8 | cout << "Enter the number of rows of Floyd's triangle to print: "; cin >> n; 9 | 10 | for (i = 1; i <= n; i++) 11 | { 12 | for (c = 1; c <= i; c++) 13 | { 14 | cout << a; 15 | a++; 16 | } 17 | cout << endl; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C++/Reverse_the_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int size; 8 | cin>>size; 9 | int array[size]; 10 | int reversed_array[size]; 11 | for(int i=0;i>array[i]; 14 | reversed_array[size-1-i]=array[i]; 15 | } 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | /*This algorithim works on the concept that first the element at the mid is checked.If the element is not present 5 | at the mid position of the array then the element to be searched with the element in array at mid 6 | If the searching element is less than we will move to the left half of the array 7 | If the searching element is greater than the mid element than the search will shift to right half of the array 8 | */ 9 | 10 | int binarySearch(int *input, int n, int val) 11 | { 12 | //Write your code here 13 | int start = 0; 14 | int end = n-1; 15 | 16 | int middle = (start+end)/2; 17 | 18 | while(start <= end) 19 | { 20 | if(input[middle] < val) 21 | { 22 | start = middle + 1; 23 | } 24 | 25 | else if(input[middle] == val) 26 | { 27 | return middle; 28 | break; 29 | } 30 | 31 | else 32 | { 33 | end = middle - 1; 34 | } 35 | 36 | middle = (start + end)/2; 37 | } 38 | 39 | if(start > end) 40 | { 41 | return -1; 42 | } 43 | } 44 | 45 | int main() 46 | { 47 | 48 | int size; 49 | cin >> size; 50 | int *input = new int[size]; 51 | 52 | for(int i = 0; i < size; ++i) 53 | { 54 | cin >> input[i]; 55 | } 56 | 57 | int t; 58 | cin >> t; 59 | 60 | while (t--) 61 | { 62 | int val; 63 | cin >> val; 64 | cout << binarySearch(input, size, val) << endl; 65 | } 66 | 67 | delete [] input; 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /C++/bubble_sort.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | void bubble_sort(vector&input){ 6 | int i,j; 7 | for(i=0;iinput[j+1]){ 10 | /*swapping the elements without using an extra variable*/ 11 | input[j]=input[j]+input[j+1]; 12 | input[j+1]=input[j]-input[j+1]; 13 | input[j]=input[j]-input[j+1]; 14 | } 15 | } 16 | } 17 | 18 | } 19 | int main() 20 | { 21 | vectorv; 22 | int n; 23 | cout<<"Enter the number of elements to be entered:\n"; 24 | cin>>n; 25 | 26 | /*taking inputs of the elements from the user*/ 27 | for(int i=0;i>ele; 30 | v.push_back(ele);/*entering the elements in the vector*/ 31 | } 32 | bubble_sort(v);/*this will sort the elements of the vector*/ 33 | 34 | /*printing the elements after sorting*/ 35 | for(int i=0;i 2 | using namespace std; 3 | 4 | bool isDecreasing(string n) 5 | { 6 | for(int i=0; i>n; 21 | 22 | if(isDecreasing(n)) 23 | { 24 | cout< 2 | using namespace std; 3 | 4 | bool isEven(int n) 5 | { 6 | if(n%2 == 0) 7 | { 8 | return true; 9 | } 10 | else 11 | { 12 | return false; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | int n; 19 | 20 | cout<<"Enter a number:\n"; 21 | cin>>n; 22 | 23 | if(isEven(n)) 24 | { 25 | cout< 2 | using namespace std; 3 | 4 | bool isIncreasing(string n) 5 | { 6 | for(int i=0; in[i+1]) 9 | { 10 | return false; 11 | } 12 | } 13 | return true; 14 | } 15 | 16 | int main() 17 | { 18 | string n; 19 | cout<<"Enter a number:\n"; 20 | cin>>n; 21 | 22 | if(isIncreasing(n)) 23 | { 24 | cout< 2 | using namespace std; 3 | 4 | bool isPrime(int n) 5 | { 6 | for(int i=2; i>n; 22 | 23 | if(isPrime(n)) 24 | { 25 | cout< 3 | using namespace std; 4 | 5 | int countDivisibles(int arr[], int n) 6 | { 7 | int res = 0; 8 | 9 | // Iterate through all pairs 10 | for (int i=0; i 9 | using namespace std; 10 | 11 | void display(int *array, int n) 12 | { 13 | for (int i = 1; i <= n; i++) 14 | cout << array[i] << " "; 15 | cout << endl; 16 | } 17 | 18 | int getMax(int array[], int n) 19 | { 20 | int max = array[1]; 21 | for (int i = 2; i <= n; i++) 22 | { 23 | if (array[i] > max) 24 | max = array[i]; 25 | } 26 | return max; // the max element from the array 27 | } 28 | 29 | // counting sort sorting algorithm 30 | void CountingSort(int *array, int n) 31 | { 32 | int max = getMax(array, n); 33 | int count[max + 1]; // create count array (max+1 number of elements) 34 | 35 | // initialize all elements to 0 in count array 36 | for (int i = 0; i <= max; i++) 37 | count[i] = 0; 38 | 39 | for (int i = 1; i <= n; i++) 40 | count[array[i]]++; // increase number count in count array. 41 | 42 | // cummulative count of count array to get the 43 | // positions of elements to be stored in the output array 44 | for (int i = 1; i <= max; i++) 45 | count[i] += count[i - 1]; // find cumulative frequency 46 | 47 | int output[n + 1]; 48 | for (int i = n; i >= 1; i--) 49 | { 50 | output[count[array[i]]] = array[i]; 51 | count[array[i]] -= 1; // decrease count for same numbers 52 | } 53 | 54 | // copy output array elements to input array 55 | for (int i = 1; i <= n; i++) 56 | { 57 | array[i] = output[i]; // store output array to main array 58 | } 59 | } 60 | 61 | 62 | int main() 63 | { 64 | int n; 65 | cout << "Enter the number of elements: "; 66 | cin >> n; 67 | int arr[n + 1]; // create an array with given number of elements 68 | cout << "Enter elements:" << endl; 69 | for (int i = 1; i <= n; i++) 70 | { 71 | cin >> arr[i]; 72 | } 73 | cout << "Array before Sorting: "; 74 | display(arr, n); 75 | CountingSort(arr, n); 76 | cout << "Array after Sorting: "; 77 | display(arr, n); 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /C++/decimalToBinary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void decimalToBinary(int n) 5 | { 6 | // array to store binary number 7 | int binaryNum[32]; 8 | 9 | // counter for binary array 10 | int i = 0; 11 | while (n > 0) { 12 | 13 | // storing remainder in binary array 14 | binaryNum[i] = n % 2; 15 | n = n / 2; 16 | i++; 17 | } 18 | 19 | // printing binary array in reverse order 20 | for (int j = i - 1; j >= 0; j--) 21 | cout << binaryNum[j]; 22 | } 23 | 24 | 25 | int main() 26 | { 27 | int n; 28 | cin >> n; 29 | decimalToBinary(n); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C++/factorial using recursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | /*this function is a recursive function which run untill the value of n becomes 0 untill then it goes on decrementing 6 | and gets multiplied */ 7 | int factorial(int n){ 8 | if(n==0){ 9 | return 1; 10 | } 11 | return(n*factorial(n-1)); 12 | } 13 | 14 | int main() { 15 | int n; 16 | cout<<"Enter the number whose factorial to be found:\n"; 17 | 18 | 19 | cin >> n; 20 | cout<<"FACTORIAL:"< 2 | using namespace std ; 3 | 4 | /// floyds cycle detection is a process in which we have to detect the part where the ther eis a circular linked list 5 | 6 | // process is that ki 7 | // we take two pointer slow and fast and both fast will move twice the slow then if slow and fast pointer meet then 8 | // the linked list is circular 9 | 10 | class node{ 11 | public: 12 | int d; 13 | node *next; 14 | node(int a){ 15 | d=a; 16 | next=NULL; 17 | } 18 | 19 | }; 20 | 21 | void insertion_head(node *&head,int d){ 22 | if(head==NULL){ 23 | head = new node(d); 24 | return; 25 | } 26 | node *n =new node(d); 27 | n->next=head; 28 | head=n; 29 | 30 | } 31 | 32 | /// inserting a linked list with element d 33 | void inserCir(node*&head,int d){ 34 | node*n=new node(d); 35 | node*temp=head; 36 | n->next=head; 37 | if(temp!=NULL){ 38 | while(temp->next!=head){ 39 | temp=temp->next; 40 | } 41 | temp->next=n; 42 | } 43 | else{ 44 | n->next=n; 45 | } 46 | head=n; 47 | // return; 48 | 49 | } 50 | node*getnode(node*head,int data){ 51 | node*temp=head; 52 | while(temp->next!=head){ 53 | if(temp->d==data){ 54 | return temp; 55 | } 56 | temp=temp->next; 57 | // /. in this case we are not considering the last node 58 | } 59 | if(temp->d==data){ 60 | return temp; 61 | } 62 | return NULL; 63 | 64 | 65 | } 66 | 67 | 68 | void deletefun(node*&head,int data){ 69 | node*temp=head; 70 | node*del=getnode(head,data); 71 | if(del==NULL){ 72 | return ; 73 | } 74 | while(temp->next!=del){ 75 | temp=temp->next; 76 | } 77 | temp->next=temp->next->next; 78 | delete del; 79 | return; 80 | 81 | } 82 | 83 | 84 | void print(node*head){ 85 | while(head!=NULL){ 86 | cout<d<next; 88 | } 89 | } 90 | 91 | 92 | // /// tring to make connect the list 93 | // void link(node *&head){ 94 | // if(head==NULL){ 95 | // return; 96 | // } 97 | // node*temp=head; 98 | // if(temp->next != NULL){ 99 | // temp=temp->next; 100 | // } 101 | // temp->next=head; 102 | // } 103 | 104 | /// checking if linked list contain cycle 105 | 106 | bool floyds_cycle(node*head){ 107 | node*it2=head; 108 | node*it1=head; 109 | while(it2->next!=NULL && it2!= NULL){ 110 | it2->next->next; // the fast one takes two step 111 | it1->next; // slow arrow takes one step 112 | if(it1==it2){ 113 | return true; 114 | } 115 | } 116 | return false; 117 | 118 | } 119 | 120 | // to break the cycle 121 | node*del(node*head){ 122 | node*it2=head; 123 | node*it1=head; 124 | while(it2->next!=NULL && it2!= NULL){ 125 | it2->next->next; // the fast one takes two step 126 | it1->next; // slow arrow takes one step 127 | if(it1==it2){ 128 | break; 129 | } 130 | } 131 | while(it1==it2){ 132 | it2->next->next; 133 | it1->next; 134 | } 135 | while(it2->next!=it1){ 136 | it2=it2->next; 137 | } 138 | it2->next=NULL; 139 | return head; 140 | 141 | } 142 | 143 | 144 | void printCir(node*head){ 145 | node*temp=head; 146 | do{ 147 | cout<d<next; 149 | } 150 | while(temp !=head); 151 | 152 | return; 153 | } 154 | 155 | int main(){ 156 | node*head=NULL; 157 | inserCir(head,3); 158 | inserCir(head,1); 159 | inserCir(head,2); 160 | inserCir(head,0); 161 | inserCir(head,9); 162 | inserCir(head,8); 163 | inserCir(head,7); 164 | deletefun(head,0); 165 | // printCir(head); 166 | cout< 3 | 4 | using namespace std; 5 | 6 | 7 | /*Time complexity: 8 | The best case time complexity:0(1) 9 | Worst case time complexity:0(n) 10 | Space complexity:O(1)*/ 11 | int linear_search(int arr[],int n,int ele){ 12 | /*A variable position is created such that if the element is not there in the array it returns -1 else returns the index*/ 13 | int pos=-1; 14 | for(int i=0;i>n; 25 | int*arr=new int[n]; 26 | for(int i=0;i>arr[i]; 28 | } 29 | int ele; 30 | cout<<"Enter the element to be searched:\n"; 31 | cin>>ele; 32 | cout<<"Index of element:"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cout<<"Enter the number:\n"; 7 | cin>>n; 8 | 9 | int orig=n; 10 | int rev=0; 11 | while(orig>0){ 12 | 13 | /*(orig%10)will give me the last digit of the orig number this number is added with 14 | rev*10 15 | intitally rev=0 and as loop runs it gets updated by 16 | 1 intitally then 12 and then 121 for eg*/ 17 | rev=rev*10+(orig%10); 18 | 19 | orig=orig/10; 20 | /*after retrieval of last digit in every iteration the last digit is removed from orig by dividing it by 10*/ 21 | 22 | } 23 | /* A number is a palindrome if rev and orig number is same */ 24 | if(n==rev){ 25 | cout<<"Number:"< 19 | using namespace std; 20 | 21 | #define n 20 22 | 23 | class queue { 24 | int* arr; 25 | int front; 26 | int back; 27 | 28 | public: 29 | queue(){ 30 | arr = new int(n); 31 | front = -1; 32 | back = -1; 33 | } 34 | 35 | void push(int x) { 36 | if(back == n-1){ 37 | cout<<"Queue Overflow"<back){ 51 | cout<<"No elements in queue"<back){ 60 | cout<<"No elements in queue"<back){ 69 | return true; 70 | } 71 | 72 | return false; 73 | } 74 | }; 75 | 76 | int main(){ 77 | 78 | queue q; 79 | q.push(1); 80 | q.push(2); 81 | q.push(3); 82 | q.push(4); 83 | 84 | cout< 6 | using namespace std; 7 | 8 | class node{ 9 | public: 10 | int data; 11 | node* next; 12 | 13 | node(int val){ 14 | data = val; 15 | next = NULL; 16 | } 17 | }; 18 | 19 | class queue{ 20 | node* front; 21 | node* back; 22 | 23 | public: 24 | queue(){ 25 | front = NULL; 26 | back = NULL; 27 | } 28 | 29 | void push(int x){ 30 | node* n = new node(x); 31 | 32 | if(front == NULL){ // when queue is empty 33 | back = n; 34 | front = n; 35 | return; 36 | } 37 | 38 | back->next = n; 39 | back = n; 40 | } 41 | 42 | void pop(){ 43 | if(front == NULL){ 44 | cout<<"Queue Underflow"<next; 50 | 51 | delete todelete; 52 | } 53 | 54 | int peek(){ 55 | if(front == NULL){ 56 | cout<<"No element in queue"<data; 61 | } 62 | 63 | bool empty(){ 64 | if(front == NULL){ 65 | return true; 66 | } 67 | 68 | return false; 69 | } 70 | }; 71 | 72 | int main(){ 73 | queue q; 74 | q.push(1); 75 | q.push(2); 76 | q.push(3); 77 | q.push(4); 78 | 79 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int i; 6 | string s; 7 | cin>>s; 8 | string b=""; 9 | for(i=s.length()-1;i>=0;i--) 10 | b=b+s[i]; 11 | cout< INT_MAX/10 || (res == INT_MAX/10 && last > 7)){ 9 | return 0; 10 | } 11 | 12 | if (res < INT_MIN/10 || (res == INT_MIN/10 && last < -8)){ 13 | return 0; 14 | } 15 | res = res*10 + last; 16 | x /= 10; 17 | } 18 | return res; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /C++/seive_of_eratosthenes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | #define fastIO \ 5 | { \ 6 | ios_base ::sync_with_stdio(false); \ 7 | cin.tie(NULL); \ 8 | cout.tie(NULL); \ 9 | } 10 | #define yes "Yes" 11 | #define no "No" 12 | #define pb push_back 13 | #define mp make_pair 14 | #define all(v) (v.begin(), v.end()) 15 | typedef vector vi; 16 | typedef vector vl; 17 | vector> v; 18 | 19 | void SieveOfEratosthenes(int n) 20 | { 21 | bool prime[n + 1]; 22 | memset(prime, true, sizeof(prime)); 23 | for (int p = 2; p * p <= n; p++) 24 | { 25 | if (prime[p] == true) 26 | { 27 | for (int i = p * p; i <= n; i += p) 28 | { 29 | prime[i] = false; 30 | } 31 | } 32 | } 33 | for (int p = 2; p <= n; p++) 34 | { 35 | if (prime[p]) 36 | { 37 | cout << p << " "; 38 | } 39 | } 40 | } 41 | 42 | void solve() 43 | { 44 | int n; 45 | cin >> n; // Enter the value of n upto which you need prime_numbers 46 | SieveOfEratosthenes(n); 47 | cout << endl; 48 | } 49 | 50 | //<><><><><><><><><><><><>><><>><><><><><><><> 51 | 52 | int32_t main() 53 | { 54 | fastIO; 55 | auto start = std::chrono::high_resolution_clock::now(); 56 | int t; 57 | t = 1; 58 | cin >> t; 59 | while (t--) 60 | { 61 | solve(); 62 | } 63 | 64 | return 0; 65 | } -------------------------------------------------------------------------------- /C++/stack.cpp: -------------------------------------------------------------------------------- 1 | /* C++ program to implement basic stack 2 | operations */ 3 | #include 4 | 5 | using namespace std; 6 | 7 | #define MAX 1000 8 | 9 | class Stack { 10 | int top; 11 | 12 | public: 13 | int a[MAX]; // Maximum size of Stack 14 | 15 | Stack() { top = -1; } 16 | bool push(int x); 17 | int pop(); 18 | int peek(); 19 | bool isEmpty(); 20 | }; 21 | 22 | bool Stack::push(int x) 23 | { 24 | if (top >= (MAX - 1)) { 25 | cout << "Stack Overflow"; 26 | return false; 27 | } 28 | else { 29 | a[++top] = x; 30 | cout << x << " pushed into stack\n"; 31 | return true; 32 | } 33 | } 34 | 35 | int Stack::pop() 36 | { 37 | if (top < 0) { 38 | cout << "Stack Underflow"; 39 | return 0; 40 | } 41 | else { 42 | int x = a[top--]; 43 | return x; 44 | } 45 | } 46 | int Stack::peek() 47 | { 48 | if (top < 0) { 49 | cout << "Stack is Empty"; 50 | return 0; 51 | } 52 | else { 53 | int x = a[top]; 54 | return x; 55 | } 56 | } 57 | 58 | bool Stack::isEmpty() 59 | { 60 | return (top < 0); 61 | } 62 | 63 | // Driver program to test above functions 64 | int main() 65 | { 66 | class Stack s; 67 | s.push(10); 68 | s.push(20); 69 | s.push(30); 70 | cout << s.pop() << " Popped from stack\n"; 71 | 72 | //print top element of stack after poping 73 | cout << "Top element is : " << s.peek() << endl; 74 | 75 | //print all elements in stack : 76 | cout <<"Elements present in stack : "; 77 | while(!s.isEmpty()) 78 | { 79 | // print top element in stack 80 | cout << s.peek() <<" "; 81 | // remove top element in stack 82 | s.pop(); 83 | } 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /C++/string revresal.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | string s; 9 | cout<<"Enter the string:\n"; 10 | 11 | getline(cin,s);/*this function is used to get whitespaces in the string and prevents its termination as soon 12 | the white space is encountered*/ 13 | int si=0; 14 | int ei=s.length()-1; 15 | /*this loop deals with two pointers one at start and one at end and after every iteration 16 | si is incremented and ei is decremented*/ 17 | while(si<=ei){ 18 | /*swapping of characters*/ 19 | char temp=s[si]; 20 | s[si]=s[ei]; 21 | s[ei]=temp; 22 | si++; 23 | ei--; 24 | } 25 | cout<<"String after reversal:\n"; 26 | cout< 2 | using namespace std; 3 | 4 | bool isPrime(int a) 5 | { 6 | for(int i=2; i>a>>b; 31 | 32 | if(isTwinPrime(a, b)) 33 | { 34 | cout<= 0; i++) { 13 | if (i % n1 == 0 & i % n2 == 0) { 14 | lcm = lcm + i; 15 | break; 16 | } 17 | 18 | } 19 | System.out.println("LCM of the numbers is: " + lcm); 20 | } else if (n1 > n2) { 21 | for (int i = n1; i >= 0; i++) { 22 | if (i % n1 == 0 & i % n2 == 0) { 23 | lcm = lcm + i; 24 | break; 25 | } 26 | 27 | } 28 | System.out.println("LCM of the numbers is: " + lcm); 29 | } else { 30 | System.out.println("LCM of the numbers is: " + n1); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Java/SecondLargestArray/secondLargestArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoolRekha/Programs/26d3262072240183e5dac383bdad3ff31f750d37/Java/SecondLargestArray/secondLargestArray.class -------------------------------------------------------------------------------- /Java/SecondLargestArray/secondLargestArray.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class secondLargestArray 3 | { 4 | public static void main(String args[]) { 5 | System.out.println("Enter no. of elements of array:"); 6 | int n; 7 | Scanner sc=new Scanner(System.in); 8 | n=sc.nextInt(); 9 | int[] a=new int[n]; 10 | System.out.println("Enter elements of the array:"); 11 | for(int i=0;imax) 19 | { 20 | max=a[i]; 21 | } 22 | } 23 | System.out.println("Largest element is : "+max); 24 | int second=0; 25 | for(int i=0;isecond)&&(a[i]= l) { 6 | int mid = l + (r - l) / 2; 7 | 8 | // If the element is present at the 9 | // middle itself 10 | if (arr[mid] == x) 11 | return mid; 12 | 13 | // If element is smaller than mid, then 14 | // it can only be present in left subarray 15 | if (arr[mid] > x) 16 | return binarySearch(arr, l, mid - 1, x); 17 | 18 | // Else the element can only be present 19 | // in right subarray 20 | return binarySearch(arr, mid + 1, r, x); 21 | } 22 | 23 | // We reach here when element is not present 24 | // in array 25 | return -1; 26 | } 27 | 28 | 29 | public static void main(String args[]) 30 | { 31 | BinarySearch ob = new BinarySearch(); 32 | int arr[] = { 2, 3, 4, 10, 40 }; 33 | int n = arr.length; 34 | int x = 10; 35 | int result = ob.binarySearch(arr, 0, n - 1, x); 36 | if (result == -1) 37 | System.out.println("Element not present"); 38 | else 39 | System.out.println("Element found at index " 40 | + result); 41 | } 42 | } -------------------------------------------------------------------------------- /Java/bubblesort.java: -------------------------------------------------------------------------------- 1 | package com.kraken; 2 | import java.util.*; 3 | public class bubblesort { 4 | public static void sort(int arr[]) 5 | { 6 | 7 | for(int i = 0; i=0; i--) 21 | { 22 | System.out.print(arr[i]+" "); 23 | } 24 | } 25 | public static void main(String args []) 26 | { 27 | Scanner sc = new Scanner(System.in); 28 | int arr [] = new int [5]; 29 | for(int i = 0; i0){ 9 | len= len-1; 10 | c=s.charAt(len); 11 | } 12 | int k =len; 13 | while(c!=' ' && len >0){ 14 | len= len-1; 15 | c= s.charAt(len); 16 | } 17 | if(len==0 && s.charAt(0)!=' ') 18 | return k-len+1; 19 | else 20 | return k-len; 21 | } 22 | } 23 | public class lengthoflastword { 24 | public static void main(String[] args) throws IOException { 25 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 26 | String str= br.readLine(); 27 | Solution s = new Solution(); 28 | int ss = s.lengthOfLastWord(str); 29 | System.out.println(ss); 30 | } 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Java/lowestCommonAncestor.java: -------------------------------------------------------------------------------- 1 | //Given a binary tree, find the lowest common ancestor (LCA) of two given nodes P and Q in the tree. 2 | public class TreeNode { 3 | int val; 4 | TreeNode left; 5 | TreeNode right; 6 | TreeNode(int x) { val = x; } 7 | } 8 | 9 | class Solution { 10 | 11 | /*1. We traverse in our tree using dfs. 12 | 2. We return root if if find our p or q node. 13 | 3. if we get only one root from our tree that means another node is child of that node and therefore that root is our ans. 14 | 4. if we get two different root for P and Q from left and right of a root it means that our current node is LCA for them and we return current node. 15 | */ 16 | 17 | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { 18 | if(root ==p || root== q || root== null){ 19 | return root; 20 | } 21 | TreeNode left = lowestCommonAncestor(root.left,p,q); 22 | TreeNode right = lowestCommonAncestor(root.right,p,q); 23 | 24 | if(left != null && right != null){ 25 | return root; 26 | } 27 | 28 | if(left == null){ 29 | return right; 30 | }else{ 31 | return left; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Java/perfectnumber.java: -------------------------------------------------------------------------------- 1 | public class Main 2 | { 3 | public static void main (String[]args) 4 | { 5 | 6 | int n = 28, sum = 0; 7 | 8 | for (int i = 1; i < n; i++) 9 | { 10 | if (n % i == 0) 11 | sum = sum + i; 12 | } 13 | 14 | if (sum == n) 15 | System.out.println (n + " Is a perfect number"); 16 | else 17 | System.out.println (n + " Is not a perfect number"); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Java/smallestInAnArray.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class smallestInAnArray 4 | { 5 | public static void main(String args[]) 6 | { 7 | 8 | int arr[] = {12, 13, 1, 10, 34, 10}; 9 | 10 | int min = arr[0]; 11 | 12 | for(int i=0; i arr[i]) 14 | { 15 | min = arr[i]; 16 | } 17 | 18 | } 19 | 20 | System.out.print(min); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/stack.java: -------------------------------------------------------------------------------- 1 | /* Java program to implement basic stack 2 | operations */ 3 | class Stack { 4 | static final int MAX = 1000; 5 | int top; 6 | int a[] = new int[MAX]; // Maximum size of Stack 7 | 8 | boolean isEmpty() 9 | { 10 | return (top < 0); 11 | } 12 | Stack() 13 | { 14 | top = -1; 15 | } 16 | 17 | boolean push(int x) 18 | { 19 | if (top >= (MAX - 1)) { 20 | System.out.println("Stack Overflow"); 21 | return false; 22 | } 23 | else { 24 | a[++top] = x; 25 | System.out.println(x + " pushed into stack"); 26 | return true; 27 | } 28 | } 29 | 30 | int pop() 31 | { 32 | if (top < 0) { 33 | System.out.println("Stack Underflow"); 34 | return 0; 35 | } 36 | else { 37 | int x = a[top--]; 38 | return x; 39 | } 40 | } 41 | 42 | int peek() 43 | { 44 | if (top < 0) { 45 | System.out.println("Stack Underflow"); 46 | return 0; 47 | } 48 | else { 49 | int x = a[top]; 50 | return x; 51 | } 52 | } 53 | 54 | void print(){ 55 | for(int i = top;i>-1;i--){ 56 | System.out.print(" "+ a[i]); 57 | } 58 | } 59 | } 60 | 61 | // Driver code 62 | class Main { 63 | public static void main(String args[]) 64 | { 65 | Stack s = new Stack(); 66 | s.push(10); 67 | s.push(20); 68 | s.push(30); 69 | System.out.println(s.pop() + " Popped from stack"); 70 | System.out.println("Top element is :" + s.peek()); 71 | System.out.print("Elements present in stack :"); 72 | s.print(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/animated-grid.css: -------------------------------------------------------------------------------- 1 | .animated-grid{ 2 | height: 85vh; 3 | margin-bottom: 200px; 4 | 5 | display: grid; 6 | gap: 1rem; 7 | 8 | /* Explicit grid */ 9 | grid-template-areas: 10 | 'a b c d' 11 | 'l 🌟 🌟 e' 12 | 'k 🌟 🌟 f' 13 | 'j i h g'; 14 | grid-template-rows: repeat(4,25%); 15 | grid-template-rows: 240px auto auto 240px; /*distribution logic explained in 1st one*/ 16 | 17 | --staggered-delay:100ms; /* variable */ 18 | } 19 | 20 | @keyframes cardEntrance{ 21 | from{ 22 | opacity: 0; 23 | transform: scale(0.3); 24 | filter: hue-rotate(180deg); /*that changing color animation comes from here*/ 25 | } 26 | to{ 27 | opacity: 1; 28 | transform: scale(1); 29 | filter: hue-rotate(0deg); 30 | } 31 | } 32 | 33 | .card{ 34 | background-color: rgb(36,243, 147); 35 | animation: cardEntrance 700ms ease-out; /*adding animation to this class*/ 36 | animation-fill-mode: backwards; /*to ensure cards are invisible before animation starts*/ 37 | } 38 | .card:nth-child(1){ 39 | grid-area:a; 40 | animation-delay: calc(1 * var(--staggered-delay)); 41 | } 42 | .card:nth-child(2){ 43 | grid-area: b; 44 | animation-delay: calc(2*var(--staggered-delay)); 45 | } 46 | .card:nth-child(3){ 47 | grid-area:c; 48 | animation-delay: calc(3 * var(--staggered-delay)); 49 | } 50 | .card:nth-child(4){ 51 | grid-area: d; 52 | animation-delay: calc(4 * var(--staggered-delay)); 53 | } 54 | .card:nth-child(5){ 55 | grid-area: e; 56 | animation-delay: calc( 5* var(--staggered-delay)); 57 | } 58 | .card:nth-child(6){ 59 | grid-area:f; 60 | animation-delay: calc(6 * var(--staggered-delay)); 61 | } 62 | .card:nth-child(7){ 63 | grid-area:g; 64 | animation-delay: calc(7 * var(--staggered-delay)); 65 | } 66 | .card:nth-child(8){ 67 | grid-area:h; 68 | animation-delay: calc(8 * var(--staggered-delay)); 69 | } 70 | .card:nth-child(9){ 71 | grid-area:i; 72 | animation-delay: calc(9 * var(--staggered-delay)); 73 | } 74 | .card:nth-child(10){ 75 | grid-area:j; 76 | animation-delay: calc( 10* var(--staggered-delay)); 77 | } 78 | .card:nth-child(11){ 79 | grid-area:k; 80 | animation-delay: calc( 11* var(--staggered-delay)); 81 | } 82 | .card:nth-child(12){ 83 | grid-area:l; 84 | animation-delay: calc(12 * var(--staggered-delay)); 85 | } 86 | .card:last-child{ 87 | grid-area: 🌟; 88 | animation-delay: calc(13 * var(--staggered-delay)); 89 | } 90 | -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/animated-grid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | animated-grid 8 | 12 | 13 | 14 |
15 |
a
16 |
b
17 |
c
18 |
d
19 |
e
20 |
f
21 |
g
22 |
h
23 |
i
24 |
j
25 |
k
26 |
l
27 |
main
28 |
29 | 30 | -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/base-grid.css: -------------------------------------------------------------------------------- 1 | .base-grid { 2 | display: grid; 3 | gap: 1rem; /*ensuring 1rem space b/w grids 4 | 5 | explicitly defining number of column 6 | 7 | grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr; 8 | assigning space to num of fr, more fr less and more divided space 9 | or 10 | grid-template-columns: repeat(12, 1fr); 11 | 12 | implicitly defining*/ 13 | grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 14 | 15 | /* autofit will consume whole space whereas if we wana leave space 16 | we can use autofill which will leave space when available */ 17 | 18 | } -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/base.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css?family=Noto+Sans&display=swap'); 2 | 3 | body { 4 | background: rgb(19, 19, 19); 5 | color: #fff; 6 | font-family: 'Noto Sans', sans-serif; 7 | } 8 | 9 | .card { 10 | display: flex; 11 | flex-direction: column; 12 | justify-content: center; 13 | align-items: center; 14 | background: #353535; 15 | font-size: 3rem; 16 | color: #fff; 17 | box-shadow: rgba(3, 8, 20, 0.1) 0px 0.15rem 0.5rem, rgba(2, 8, 20, 0.1) 0px 0.075rem 0.175rem; 18 | height: 100%; 19 | width: 100%; 20 | border-radius: 4px; 21 | transition: all 500ms; 22 | overflow: hidden; 23 | 24 | background-size: cover; 25 | background-position: center; 26 | background-repeat: no-repeat; 27 | } 28 | 29 | .card:hover { 30 | box-shadow: rgba(2, 8, 20, 0.1) 0px 0.35em 1.175em, rgba(2, 8, 20, 0.08) 0px 0.175em 0.5em; 31 | transform: translateY(-3px) scale(1.1); 32 | } -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/basegrid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | grid demo 8 | 12 | 13 | 14 |
15 |
1
16 |
2
17 |
3
18 |
4
19 |
5
20 |
6
21 |
7
22 |
8
23 |
9
24 |
10
25 |
11
26 |
12
27 |
28 | 29 | -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/photo-grid.css: -------------------------------------------------------------------------------- 1 | .photo-grid { 2 | display: grid; 3 | gap: 1rem; 4 | 5 | grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 6 | grid-auto-rows: 240px; /*explicitly seting min ^|^ size for that most square grids*/ 7 | } 8 | 9 | .card-tall{ 10 | grid-row: span 2/auto; /*span- function to make element consume more grid than 1 11 | if element have this property it will use this class (apparently css have classes) 12 | its like span (number of grids.) / (ending pos.) (for rows in this case */ 13 | } 14 | 15 | .card-wide{ 16 | grid-column: span 2/auto; 17 | } -------------------------------------------------------------------------------- /JavaScript/GridSystem/grid system fireship/photo-grid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | photo-grid demo 8 | 12 | 13 | 14 |
15 |
19 | 1 20 |
21 |
25 | 2 26 |
27 |
31 | 3 32 |
33 |
37 | 4 38 |
39 |
43 | 5 44 |
45 |
49 | 6 50 |
51 |
55 | 7 56 |
57 |
61 | 8 62 |
63 |
67 | 9 68 |
69 |
73 | 10 74 |
75 |
79 | 11 80 |
81 |
85 | 12 86 |
87 |
88 | 89 | 90 | -------------------------------------------------------------------------------- /JavaScript/WeatherApp/Weather App/download.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoolRekha/Programs/26d3262072240183e5dac383bdad3ff31f750d37/JavaScript/WeatherApp/Weather App/download.jfif -------------------------------------------------------------------------------- /JavaScript/WeatherApp/Weather App/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 35 | 36 | 37 |
38 |
---
39 |
-°C
40 |
----
41 |
42 |
43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /JavaScript/WeatherApp/Weather App/script.js: -------------------------------------------------------------------------------- 1 | // Declaring the variables 2 | let lon; 3 | let lat; 4 | let temperature = document.querySelector(".temp"); 5 | let summary = document.querySelector(".summary"); 6 | let loc = document.querySelector(".location"); 7 | let icon = document.querySelector(".icon"); 8 | const kelvin = 273; 9 | 10 | window.addEventListener("load", () => { 11 | if (navigator.geolocation) { 12 | navigator.geolocation.getCurrentPosition((position) => { 13 | console.log(position); 14 | lon = position.coords.longitude; 15 | lat = position.coords.latitude; 16 | 17 | // API ID 18 | const api = "52143e905d237f972c7b0b763828bb82"; 19 | 20 | // API URL 21 | const base = 22 | `http://api.openweathermap.org/data/2.5/weather?lat=${lat}&` + 23 | `lon=${lon}&appid=52143e905d237f972c7b0b763828bb82`; 24 | 25 | // Calling the API 26 | fetch(base) 27 | .then((response) => { 28 | return response.json(); 29 | }) 30 | .then((data) => { 31 | console.log(data); 32 | temperature.textContent = 33 | Math.floor(data.main.temp - kelvin) + "°C"; 34 | summary.textContent = data.weather[0].description; 35 | loc.textContent = data.name + "," + data.sys.country; 36 | let icon1 = data.weather[0].icon; 37 | icon.innerHTML = 38 | ``; 39 | }); 40 | }); 41 | } 42 | }); 43 | -------------------------------------------------------------------------------- /Python/Alarm_Clock.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from playsound import playsound 3 | alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n") 4 | alarm_hour=alarm_time[0:2] 5 | alarm_minute=alarm_time[3:5] 6 | alarm_seconds=alarm_time[6:8] 7 | alarm_period = alarm_time[9:11].upper() 8 | print("Setting up alarm..") 9 | while True: 10 | now = datetime.now() 11 | current_hour = now.strftime("%I") 12 | current_minute = now.strftime("%M") 13 | current_seconds = now.strftime("%S") 14 | current_period = now.strftime("%p") 15 | if(alarm_period==current_period): 16 | if(alarm_hour==current_hour): 17 | if(alarm_minute==current_minute): 18 | if(alarm_seconds==current_seconds): 19 | print("Wake Up!") 20 | playsound('audio.mp3') 21 | break 22 | -------------------------------------------------------------------------------- /Python/Deque.py: -------------------------------------------------------------------------------- 1 | # Deque implementaion in python 2 | 3 | class Deque: 4 | def __init__(self): 5 | self.items = [] 6 | 7 | def isEmpty(self): 8 | return self.items == [] 9 | 10 | def addRear(self, item): 11 | self.items.append(item) 12 | 13 | def addFront(self, item): 14 | self.items.insert(0, item) 15 | 16 | def removeFront(self): 17 | return self.items.pop(0) 18 | 19 | def removeRear(self): 20 | return self.items.pop() 21 | 22 | def size(self): 23 | return len(self.items) 24 | 25 | 26 | d = Deque() 27 | print(d.isEmpty()) 28 | d.addRear(8) 29 | d.addRear(5) 30 | d.addFront(7) 31 | d.addFront(10) 32 | print(d.size()) 33 | print(d.isEmpty()) 34 | d.addRear(11) 35 | print(d.removeRear()) 36 | print(d.removeFront()) 37 | d.addFront(55) 38 | d.addRear(45) 39 | print(d.items) -------------------------------------------------------------------------------- /Python/factorial.py: -------------------------------------------------------------------------------- 1 | #taking an integer input from user 2 | num=int(input("Enter the whole number to find the factorial: ")) 3 | factorial = 1 4 | if num < 0: 5 | print("Factorial can't be calculated for negative number") 6 | elif num == 0: 7 | print("Factorial of 0 is 1") 8 | else: 9 | #calculating the factorial of the input number 10 | for i in range(1,num + 1): 11 | factorial = factorial*i 12 | print("Factorial of",num,"is",factorial) 13 | -------------------------------------------------------------------------------- /Python/helloWorld.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Python/password_generator.py: -------------------------------------------------------------------------------- 1 | import secrets 2 | import string 3 | import bcrypt 4 | 5 | # define alphabet 6 | letters = string.ascii_letters 7 | digits = string.digits 8 | special_chars = string.punctuation 9 | 10 | alphabet = letters + digits + special_chars 11 | 12 | def generate_password(): 13 | while True: 14 | try: 15 | pwd_length = int(input("How long would you like your password to be? ")) 16 | except ValueError: 17 | print("Please, enter a valid integer") 18 | continue 19 | else: 20 | print(f'You entered: {pwd_length}') 21 | break 22 | 23 | while True: 24 | pwd = '' 25 | for i in range(pwd_length): 26 | pwd += ''.join(secrets.choice(alphabet)) 27 | 28 | if (any(char in special_chars for char in pwd) and 29 | sum(char in digits for char in pwd)>=2): 30 | break 31 | print(pwd) 32 | 33 | bytePwd = pwd.encode('utf-8') 34 | 35 | salt = bcrypt.gensalt() 36 | hashed = bcrypt.hashpw(bytePwd, salt) 37 | 38 | pwCheck = bcrypt.checkpw(bytePwd, hashed) 39 | if (pwCheck == True) : 40 | print("The password was successfully hashed") 41 | elif (pwCheck == False) : 42 | print("The password can't be hashed") 43 | 44 | print(hashed) 45 | 46 | option = input("Do you want to generate a password? (Yes/No): ") 47 | 48 | if option == "Y": 49 | generate_password() 50 | elif option == "Yes": 51 | generate_password() 52 | else: 53 | print("Program ended") 54 | -------------------------------------------------------------------------------- /Python/roadCrossing Game.py: -------------------------------------------------------------------------------- 1 | import time 2 | from turtle import Screen,Turtle 3 | from random import randint,choice 4 | 5 | FONT = ("Courier", 24, "normal") 6 | 7 | class Scoreboard(Turtle): 8 | def __init__(self): 9 | super().__init__() 10 | self.score = 0 11 | self.color("black") 12 | self.penup() 13 | self.hideturtle() 14 | self.refresh() 15 | 16 | def refresh(self): 17 | self.goto(-280,260) 18 | self.write(arg=f"score:{self.score} ",font=FONT) 19 | 20 | def game_over(self): 21 | self.goto(0,0) 22 | self.write(arg=f"Game Over",align="center",font=FONT) 23 | 24 | def addScore(self): 25 | self.score += 1 26 | self.clear() 27 | self.refresh() 28 | 29 | STARTING_POSITION = (0, -280) 30 | MOVE_DISTANCE = 10 31 | FINISH_LINE_Y = 280 32 | 33 | class Player(Turtle): 34 | def __init__(self): 35 | super().__init__() 36 | self.shape("turtle") 37 | self.penup() 38 | self.right(-90) 39 | self.restart() 40 | 41 | def move(self): 42 | self.forward(MOVE_DISTANCE) 43 | 44 | def restart(self): 45 | self.goto(STARTING_POSITION) 46 | 47 | COLORS = ["red", "orange", "yellow", "green", "blue", "purple"] 48 | STARTING_MOVE_DISTANCE = 5 49 | MOVE_INCREMENT = 10 50 | 51 | class CarManager: 52 | def __init__(self): 53 | super().__init__() 54 | self.cars = [] 55 | self.distance = STARTING_MOVE_DISTANCE 56 | self.create() 57 | 58 | def create(self): 59 | c = Turtle("square") 60 | c.shapesize(1,2) 61 | c.penup() 62 | c.color(choice(COLORS)) 63 | c.setheading(180) 64 | c.goto(300,randint(-250,250)) 65 | self.cars.append(c) 66 | 67 | 68 | def move(self): 69 | for c in self.cars: 70 | c.forward(self.distance) 71 | 72 | def nextLevel(self): 73 | self.distance += MOVE_INCREMENT 74 | 75 | screen = Screen() 76 | screen.setup(width=600, height=600) 77 | screen.tracer(0) 78 | 79 | p = Player() 80 | c = CarManager() 81 | sc = Scoreboard() 82 | 83 | screen.listen() 84 | screen.onkey(p.move,"Up") 85 | 86 | game_is_on = True 87 | time_counter = 0 88 | while game_is_on: 89 | if time_counter % 6 == 5: 90 | c.create() 91 | time.sleep(0.1) 92 | screen.update() 93 | c.move() 94 | time_counter += 1 95 | 96 | for car in c.cars: 97 | if car.distance(p) < 20: 98 | game_is_on = False 99 | sc.game_over() 100 | 101 | if p.ycor() >= FINISH_LINE_Y: 102 | c.nextLevel() 103 | p.restart() 104 | sc.addScore() 105 | 106 | screen.exitonclick() 107 | -------------------------------------------------------------------------------- /Python/stack.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of stack 2 | 3 | # import maxsize from sys module 4 | # Used to return -infinite when stack is empty 5 | from sys import maxsize 6 | 7 | # Function to create a stack. It initializes size of stack as 0 8 | def createStack(): 9 | stack = [] 10 | return stack 11 | 12 | # Stack is empty when stack size is 0 13 | def isEmpty(stack): 14 | return len(stack) == 0 15 | 16 | # Function to add an item to stack. It increases size by 1 17 | def push(stack, item): 18 | stack.append(item) 19 | print(item + " pushed to stack ") 20 | 21 | # Function to remove an item from stack. It decreases size by 1 22 | def pop(stack): 23 | if (isEmpty(stack)): 24 | return str(-maxsize -1) # return minus infinite 25 | 26 | return stack.pop() 27 | 28 | # Function to return the top from stack without removing it 29 | def peek(stack): 30 | if (isEmpty(stack)): 31 | return str(-maxsize -1) # return minus infinite 32 | return stack[len(stack) - 1] 33 | 34 | # Driver program to test above functions 35 | stack = createStack() 36 | push(stack, str(10)) 37 | push(stack, str(20)) 38 | push(stack, str(30)) 39 | print(pop(stack) + " popped from stack") 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programs 2 | This repository is a collection of basic programs in any coding language. 3 | This will participate in hacktoberfest 2022. 4 | Try to solve the opened issues. 5 | You can provide your issues also. 6 | ONLY QUALITY PRs WILL BE ACCEPTED!! 7 | 8 | # Hacktoberfest 2022 9 | Hacktoberfest is the easiest way to get into open source! Hacktoberfest is a month long festival of open source code presented by Digital Ocean and DEV this year in 2022. 10 | 11 | During the entire month of October 2022, all you have to do is contribute to any open source projects and open at least 4 pull requests. Yes, any project and any kind of contributions. It can be a be a bug fix, improvement, or even a documentation change! And win a T-Shirt and awesome stickers. 12 | 13 | If you’ve never contributed to open source before, this is the perfect time to get started because Hacktoberfest provides a large list of available contribution opportunities (and yes, there are always plenty for beginners too). 14 | 15 | # How to contribute? 16 | 17 | 1. Star this repository. 18 | 19 | 2. Fork this repository. 20 | 21 | 3. Clone the forked repository. 22 | 23 | 4. Navigate to the project directory. 24 | 25 | 5. Create a new branch. 26 | 27 | 6. Make changes. 28 | 29 | 7. Stage your changes and commit 30 | 31 | 8. Push your local commits to the remote repo. 32 | 33 | 9. Create a Pull Request. 34 | 35 | Congratulations! 🎉 you've made your contribution, and it would be accepted very soon. 36 | 37 | # Code of Conduct 38 | 39 | Examples of behavior that contributes to creating a positive environment : 40 | 41 | 1. Using welcoming and inclusive language 42 | 2. Gracefully accepting constructive criticism 43 | 3. Focusing on what is best for the community 44 | 4. Being respectful of differing viewpoints and experiences 45 | 46 | Examples of unacceptable behavior by participants include: 47 | 48 | 1. Trolling, insulting/derogatory comments, and personal or political attacks 49 | 2. Public or private harassment 50 | 3. Publishing others' private information, such as a physical or electronic address, without explicit permission 51 | --------------------------------------------------------------------------------