├── C++ ├── Backtracking │ ├── Black_and_White.cpp │ ├── M Coloring Problem.cpp │ ├── N Queen Problem.cpp │ └── Sudoku_solver.cpp ├── BisectionMethod │ ├── bisectionMethod.cpp │ └── bisectionMethod.exe ├── Bubble_Sort.cpp ├── Count Instances of a Character in a String │ ├── LiveExample.PNG │ ├── README.md │ └── main.cpp ├── Dynamic Programming │ ├── Box_stacking_problem.cpp │ ├── Coin_change.cpp │ ├── Egg_dropping_puzzle.cpp │ ├── First_n_Fibonacci_Numbers.cpp │ ├── Longest_common_substring.cpp │ ├── Longest_increaing_subseqeunce.cpp │ └── min_jumps.cpp ├── Factorial │ └── Factorial.cpp ├── Fibonacci │ ├── Fibonacci_.cpp │ ├── Fibonacci_series.c │ ├── fib_recursive.cpp │ └── fibonacci.cpp ├── Graph Algorithms │ ├── bellmanford_algo.cpp │ ├── kruskal.cpp │ └── prim.cpp ├── Kruskal_Algorithm.cpp ├── LCS_DP.cpp ├── MatrixTranspose │ └── tranpose.cpp ├── Merge sort ├── Minimax_Algorithm │ └── Minimax.cpp ├── MultipleInheritance │ ├── Code.cpp │ └── Readme.md ├── NewtonRapshon │ ├── newtonRaphson.cpp │ └── newtonRaphson.exe ├── OperatorOverloadingProblem(Hackerrank-Problem).cpp ├── Overloading.cpp ├── Patterns.cpp ├── Possible_sum.cpp ├── Queue │ ├── queue.cpp │ └── queue.exe ├── README.md ├── RGBA_Image.cpp ├── ResortSortedArray │ └── resortsortedarray.cpp ├── SJF(Scheduling algo.) │ ├── Readme.md │ └── Shortest Job First Schedulling Algorithm(SJF - Non-Preemptive).cpp ├── SecentMethod │ ├── secentMethod.cpp │ └── secentMethod.exe ├── Selection Sort │ ├── SELECTION_SORT.cpp │ ├── SELECTION_SORT.md │ └── SelectionSort.cpp ├── Shortest Route Algorithm │ └── shortest route.cpp ├── Triangle_Pattern.cpp ├── armstrong.cpp ├── bubble_sort.cpp ├── calculator.cpp ├── cocktailSort.cpp ├── counting_bits.cpp ├── dmn.cpp ├── fibbonaci.cpp ├── greatest_number │ └── greatest-number.cpp ├── is_palindrome.cpp ├── lsy.cpp ├── maximumxorsub.cpp ├── palindrome_using_stack.cpp ├── pascal.cpp ├── pattern.cpp ├── repository.c ├── shell_sort.cpp ├── shellsort.cpp └── towerOfHanoi.cpp ├── C ├── ArmstrongNumber.c ├── Arr4 right shift.c ├── Array_in_C.c ├── Eval_Postfix.c ├── LinearSearch.c ├── Linked-List(All Fuctions).c ├── Priority scheduling │ ├── Priority based Scheduling (Non - Preemptive).c │ └── README.md ├── Queue using Arrays.c ├── Queue using Linked List.c ├── README.md ├── Remove-Duplicates-from-Sorted-Array.c ├── SJF(Scheduling algo.) │ ├── Readme.md │ └── Shortest Job First Scheduling Algorithm (SJF - Non-Preemptive).c ├── Shuffle.c ├── Strings │ └── StringTokenizer.c ├── Sum.c ├── Two-Arrays-And-Swaps.c ├── binarySearch.c ├── binarySearchTree.c ├── bracket_balance.c ├── converter.c ├── copyarray.c ├── general_radix_sort.c ├── greatest-number.cpp ├── matrix_operations.c ├── merging_2_arrays.c ├── name.c ├── revering_array.c ├── reverse_string.c ├── scan_ports.c ├── selection_sort.c ├── selection_sort │ ├── README.md │ └── selection_sort.c └── triangle.c ├── CONTRIBUTING.md ├── Java script ├── Data Structures │ ├── CircularQueue.js │ ├── Linked_list.js │ ├── Queues.js │ ├── Stacks.js │ ├── array.js │ └── arraybidimensional.js ├── Merge_sort_js │ ├── merge_sort.js │ └── merge_sort.md ├── Number_is_Prime │ ├── number_isPrime.js │ └── number_isPrime.md ├── README.md ├── Recursive Palindrome │ ├── recursive-palindrome.js │ └── recursive_palindrome.md ├── Second-Largest-Element-In-Array │ └── second_largest_element_in_array.js ├── String │ ├── FirstCharacterUpperCase.js │ └── FormatMoney.js ├── ThreeJs-Demo │ ├── Readme.md │ ├── ezgif.com-video-to-gif.gif │ └── threejs.html └── calculator.js ├── Python ├── Analysis on Parking dataset │ ├── .ipynb_checkpoints │ │ └── Parking-checkpoint.ipynb │ ├── Parking.ipynb │ └── parking.xls ├── Android sudoku solver │ ├── README.md │ ├── main.py │ ├── screen.png │ └── sudoku.py ├── BookStoreGUI │ ├── __pycache__ │ │ └── backend.cpython-38.pyc │ ├── backend.py │ ├── books.db │ └── frontend.py ├── CARTOONING-AN-IMAGE-USING-OPENCV-master │ ├── CARTOONING AN IMAGE USING OPENCV.ipynb │ ├── Cartoon_BIRD.png │ └── README.md ├── Dr. Semmelweis and the Discovery of Handwashing │ ├── Dr. Semmelweis and the Discovery of Handwashing.ipynb │ └── datasets │ │ ├── ignaz_semmelweis_1860.jpeg │ │ ├── monthly_deaths.csv │ │ ├── project_image.png │ │ └── yearly_deaths_by_clinic.csv ├── EDA-(GAPMINDER-DATASET) ├── Edge-Detection │ └── Edge-Detection-checkpoint.ipynb ├── Encryptor │ └── ed.py ├── Exploratory-Data-Analysis (Weather Trends).ipynb ├── Exploring 67 years of LEGO │ ├── datasets │ │ ├── adding-cells.gif │ │ ├── colors.csv │ │ ├── downloads_schema.png │ │ ├── lego-bricks.jpeg │ │ ├── notebook_inline.png │ │ ├── project_image.png │ │ ├── sets.csv │ │ └── success-large.gif │ └── notebook.ipynb ├── FaceRecognition │ ├── Barack.jpg │ ├── President.jpg │ ├── Trumph.jpg │ └── facerecognition.py ├── Jason-Parser │ └── jason-parser.py ├── Learning Rules │ └── Perceptron Rule.py ├── LinkedList │ ├── Linkedlist.py │ └── readme.md ├── MazeGenerator(Backtracking) │ └── Maze_Generator.py ├── Motion_detection │ ├── Detection.py │ ├── MotionDetection.md │ └── Output-1.m4v ├── N-Queens │ └── n_queens.py ├── Object_detection │ ├── objectdetectvideo.py │ ├── readme.md │ └── smarties.png ├── OpenCV │ ├── Image_editing.ipynb │ └── Image_prcoessing.md ├── Password_generator │ └── main.py ├── Plots │ └── bowling_scorecard ├── PokemonDataAnalysis │ ├── Data │ │ ├── Pokemon.csv │ │ └── chart.csv │ ├── README.md │ ├── images │ │ ├── Talonflame.png │ │ ├── blissey.jpg │ │ ├── cover.jpg │ │ ├── drag.jpg │ │ ├── team.png │ │ └── w_chart.jpg │ └── pokemon-data-analysis.ipynb ├── Quora Question Pair Similarity │ └── quora-question-pair-siamese.ipynb ├── README.md ├── Seive_Theorem │ ├── README.md │ ├── generating_primes.py │ └── prime.PNG ├── Smile_detector │ ├── Smile_detector.py │ ├── haarcascade_eye.xml │ ├── haarcascade_frontalface_default.xml │ ├── haarcascade_smile.xml │ └── readme.md ├── Snake Game │ ├── README.md │ └── snake.py ├── Spiral_Traversal_matrix │ └── Spiral_mat_traversal.py ├── Sports Avalytics │ ├── README.md │ ├── mfile.py │ ├── nn.py │ ├── requirements.txt │ └── sample_data.csv ├── Sudoko-solver-using-Backtracking │ └── Sudoko Solver using Backtracking.ipynb ├── Text_to_Speech │ └── text_to_speech.py ├── Web Scrapping │ └── Beautifulsoup │ │ └── main.py ├── YoutubeDownloader │ ├── Readme.md │ └── ytDownloader.py ├── alarm clock │ ├── alarm.mp3 │ └── alarm.py ├── datacleaning ├── digit-recognition-master │ ├── README.md │ ├── Untitled.ipynb │ ├── digits_cls.pkl │ ├── generateClassifier.py │ ├── performRecognition.py │ ├── photo_1.jpg │ └── photo_2.jpg ├── flight delay │ ├── Procfile │ ├── README.md │ ├── app.py │ ├── flightss.csv │ ├── project_RSIP.ipynb │ ├── requirements.txt │ ├── res.pkl │ ├── static │ │ └── css │ │ │ └── style.css │ └── templates │ │ └── index.html ├── get_step_count │ ├── dataset.txt │ ├── index.py │ ├── readme.md │ └── requirements.txt ├── importing numPy │ ├── numpy -8.ipynb │ ├── numpy-1.ipynb │ ├── numpy-2.ipynb │ ├── numpy-3.ipynb │ ├── numpy-4.ipynb │ ├── numpy-5.ipynb │ ├── numpy-6.ipynb │ ├── numpy-7.ipynb │ └── numpy-9.ipynb ├── is_prime.py ├── live_facial_recognition.py ├── medium_article_scraper │ ├── LICENCE │ ├── README.md │ ├── medium_scraper.py │ └── requirements.txt ├── nbase-to-decimal-converter.py ├── neural network visualizer │ ├── neuralnetworkvisual.py │ └── requirements.txt ├── neural_networks │ └── neural_network_from_scratch.py ├── opencvtextdetection │ ├── images │ │ └── sign.jpg │ ├── textdetection.py │ └── textdetectionvideo.py ├── password_generator │ ├── README.md │ └── passgen.py ├── sorting.py ├── speech_recog.py ├── torrent_search │ ├── LICENSE │ ├── README.md │ ├── requirements.txt │ └── torrent_search.py └── word-of-number.py ├── README.md ├── ShortestRoute Algorithms ├── 05.Kruskal.c ├── 06.prims.c └── shortest Path.cpp └── competative coding ├── KnightL on Chessboard.cpp ├── remove_all_char.c ├── rotation.c └── toggleEachChar.c /C++/Backtracking/Black_and_White.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | unsigned long long solve(int m,int n) 4 | { 5 | static int x_off[]{-2,-1,1,2}, y_off[]{1,2,2,1}; 6 | unsigned long long ret=0; 7 | for(int i=0;i=0 && x=0 && y>T; 28 | while(T--) 29 | { 30 | int m,n; 31 | cin>>m>>n; 32 | cout< 2 | #include 3 | 4 | // Number of vertices in the graph 5 | #define V 4 6 | 7 | void printSolution(int color[]); 8 | 9 | /* A utility function to check if the current color assignment is safe for vertex v i.e. checks whether the edge exists or not (i.e, graph[v][i]==1). If exist then checks whether the color to be filled in the new vertex(c is sent in the parameter) is already used by its adjacent vertices(i-->adj vertices) or not (i.e, color[i]==c) */ 10 | bool isSafe( 11 | int v, bool graph[V][V], 12 | int color[], int c) 13 | { 14 | for (int i = 0; i < V; i++) 15 | if ( 16 | graph[v][i] && c == color[i]) 17 | return false; 18 | return true; 19 | } 20 | bool graphColoringUtil( 21 | bool graph[V][V], int m, 22 | int color[], int v) 23 | { 24 | /* base case: If all vertices are 25 | assigned a color then return true */ 26 | if (v == V) 27 | return true; 28 | 29 | /* Consider this vertex v and 30 | try different colors */ 31 | for (int c = 1; c <= m; c++) { 32 | /* Check if assignment of color 33 | c to v is fine*/ 34 | if (isSafe( 35 | v, graph, color, c)) { 36 | color[v] = c; 37 | 38 | /* recur to assign colors to 39 | rest of the vertices */ 40 | if ( 41 | graphColoringUtil( 42 | graph, m, color, v + 1) 43 | == true) 44 | return true; 45 | 46 | /* If assigning color c doesn't 47 | lead to a solution then remove it */ 48 | color[v] = 0; 49 | } 50 | } 51 | 52 | /* If no color can be assigned to 53 | this vertex then return false */ 54 | return false; 55 | } 56 | 57 | /* This function solves the m Coloring problem using Backtracking. It mainly uses graphColoringUtil() to solve the problem. It returns false if the m colors cannot be assigned, otherwise return true and prints assignments of colors to all vertices. Please note that there may be more than one solutions, this function prints one of the feasible solutions.*/ 58 | bool graphColoring( 59 | bool graph[V][V], int m) 60 | { 61 | // Initialize all color values as 0. 62 | // This initialization is needed 63 | // correct functioning of isSafe() 64 | int color[V]; 65 | for (int i = 0; i < V; i++) 66 | color[i] = 0; 67 | 68 | // Call graphColoringUtil() for vertex 0 69 | if ( 70 | graphColoringUtil( 71 | graph, m, color, 0) 72 | == false) { 73 | printf("Solution does not exist"); 74 | return false; 75 | } 76 | 77 | // Print the solution 78 | printSolution(color); 79 | return true; 80 | } 81 | 82 | /* A utility function to print solution */ 83 | void printSolution(int color[]) 84 | { 85 | printf( 86 | "Solution Exists:" 87 | " Following are the assigned colors \n"); 88 | for (int i = 0; i < V; i++) 89 | printf(" %d ", color[i]); 90 | printf("\n"); 91 | } 92 | int main() 93 | { 94 | bool graph[V][V] = { 95 | { 0, 1, 1, 1 }, 96 | { 1, 0, 1, 0 }, 97 | { 1, 1, 0, 1 }, 98 | { 1, 0, 1, 0 }, 99 | }; 100 | int m = 3; // Number of colors 101 | graphColoring(graph, m); 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /C++/Backtracking/N Queen Problem.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void printSolution(int board[N][N]) 6 | { 7 | for (int i = 0; i < N; i++) { 8 | for (int j = 0; j < N; j++) 9 | printf(" %d ", board[i][j]); 10 | printf("\n"); 11 | } 12 | } 13 | 14 | bool isSafe(int board[N][N], int row, int col) 15 | { 16 | int i, j; 17 | 18 | /* Check this row on left side */ 19 | for (i = 0; i < col; i++) 20 | if (board[row][i]) 21 | return false; 22 | 23 | /* Check upper diagonal on left side */ 24 | for (i = row, j = col; i >= 0 && j >= 0; i--, j--) 25 | if (board[i][j]) 26 | return false; 27 | 28 | /* Check lower diagonal on left side */ 29 | for (i = row, j = col; j >= 0 && i < N; i++, j--) 30 | if (board[i][j]) 31 | return false; 32 | 33 | return true; 34 | } 35 | 36 | /* A recursive utility function to solve N 37 | Queen problem */ 38 | bool solveNQUtil(int board[N][N], int col) 39 | { 40 | /* base case: If all queens are placed 41 | then return true */ 42 | if (col >= N) 43 | return true; 44 | 45 | /* Consider this column and try placing 46 | this queen in all rows one by one */ 47 | for (int i = 0; i < N; i++) { 48 | /* Check if the queen can be placed on 49 | board[i][col] */ 50 | if (isSafe(board, i, col)) { 51 | /* Place this queen in board[i][col] */ 52 | board[i][col] = 1; 53 | 54 | /* recur to place rest of the queens */ 55 | if (solveNQUtil(board, col + 1)) 56 | return true; 57 | 58 | /* If placing queen in board[i][col] 59 | doesn't lead to a solution, then 60 | remove queen from board[i][col] */ 61 | board[i][col] = 0; // BACKTRACK 62 | } 63 | } 64 | 65 | /* If the queen cannot be placed in any row in 66 | this colum col then return false */ 67 | return false; 68 | } 69 | 70 | bool solveNQ() 71 | { 72 | int board[N][N] = { { 0, 0, 0, 0 }, 73 | { 0, 0, 0, 0 }, 74 | { 0, 0, 0, 0 }, 75 | { 0, 0, 0, 0 } }; 76 | 77 | if (solveNQUtil(board, 0) == false) { 78 | printf("Solution does not exist"); 79 | return false; 80 | } 81 | 82 | printSolution(board); 83 | return true; 84 | } 85 | s 86 | int main() 87 | { 88 | solveNQ(); 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /C++/BisectionMethod/bisectionMethod.cpp: -------------------------------------------------------------------------------- 1 | /* DRH2SO4 */ 2 | #include 3 | #include 4 | #include 5 | #define f(x) (3*x*x-4*x-5) 6 | #define E 0.00001 7 | int main() 8 | { 9 | float x0,x1,x,ecal; 10 | printf ("***************BISECTION METHOD*******************"); 11 | printf("\n Enter initial value ;- \n"); 12 | printf("\n x0 = "); 13 | scanf ("%f",&x0); 14 | printf("\n x1 = "); 15 | scanf("%f",&x1); 16 | if(f(x0)==0 || f(x1)==00) 17 | { 18 | printf("\n f(x0) or f(x1) =0 \n Please enter another initial values. \n"); 19 | } 20 | else 21 | { 22 | do{ 23 | x=(x0+x1)/2; 24 | if(f(x0)*f(x1)<0) 25 | { 26 | x1 = x; 27 | } 28 | else{ 29 | x0 = x; 30 | } 31 | ecal = fabs(x1-x0); 32 | printf("\n x0=%f \t x1=%f \t x=%f \t f(x0)=%f \t f(x1)=%f \t ecal=%f \n",x0,x1,f(x0),f(x1),ecal); 33 | }while(E> n; 8 | int arr[n]; 9 | for (i = 0; i < n; i++) 10 | { 11 | cout << "Enter " << i + 1 << " th element"; 12 | cin >> arr[i]; 13 | } 14 | 15 | for (i = n; i > 0; i--) 16 | { 17 | for (j = 0; j < i - 1; j++) 18 | { 19 | if (arr[j] > arr[j + 1]) 20 | { 21 | temp = arr[j]; 22 | arr[j] = arr[j + 1]; 23 | arr[j + 1] = temp; 24 | } 25 | } 26 | } 27 | cout << "\nSorted Elements are\n"; 28 | for (i = 0; i < n; i++) 29 | { 30 | cout << arr[i] << " "; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++/Count Instances of a Character in a String/LiveExample.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/C++/Count Instances of a Character in a String/LiveExample.PNG -------------------------------------------------------------------------------- /C++/Count Instances of a Character in a String/README.md: -------------------------------------------------------------------------------- 1 | # Count Instances of a given Character in a String or Paragraph. 2 | 3 | ## Thank you for giving me this task -------------------------------------------------------------------------------- /C++/Count Instances of a Character in a String/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | int charCount(char myChar, string str) { 6 | int length; 7 | length = str.length(); 8 | int Count = 0; 9 | 10 | for(int i =0;i>finding; 31 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int t,n; 7 | int currency[]={1,2,5,10,20,50,100,200,500,2000}; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n; 12 | int coins=0; 13 | vector ans; 14 | while(n>0) 15 | { 16 | for(int i=9;i>=0;i--) 17 | { 18 | coins=n/currency[i]; 19 | if(coins>0) 20 | { 21 | for(int j=1;j<=coins;j++) 22 | ans.push_back(currency[i]); 23 | n=n%currency[i]; 24 | } 25 | } 26 | } 27 | for(int i=0;i 2 | using namespace std; 3 | 4 | int max(int a, int b) 5 | { 6 | return (a > b) ? a : b; 7 | } 8 | 9 | // Function to get minimum 10 | // number of trials needed in worst 11 | // case with n eggs and k floors 12 | int eggDrop(int n, int k) 13 | { 14 | // If there are no floors, 15 | // then no trials needed. 16 | // OR if there is one floor, 17 | // one trial needed. 18 | if (k == 1 || k == 0) 19 | return k; 20 | 21 | // We need k trials for one 22 | // egg and k floors 23 | if (n == 1) 24 | return k; 25 | 26 | int min = INT_MAX, x, res; 27 | 28 | // Consider all droppings from 29 | // 1st floor to kth floor and 30 | // return the minimum of these 31 | // values plus 1. 32 | for (x = 1; x <= k; x++) { 33 | res = max(eggDrop(n - 1, x - 1),eggDrop(n, k - x)); 34 | if (res < min) 35 | min = res; 36 | } 37 | 38 | return min + 1; 39 | } 40 | 41 | int main() 42 | { 43 | int n; //Number of eggs 44 | int k; //Number of floors; 45 | cin>>n>>k; 46 | cout << "Minimum number of trials in worst case with " 47 | << n << " eggs and " << k 48 | << " floors is " 49 | << eggDrop(n, k) << endl; 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /C++/Dynamic Programming/First_n_Fibonacci_Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long int arr[85]; 4 | void fibo() 5 | { 6 | arr[1]=1; 7 | arr[2]=1; 8 | 9 | for(int i=3;i<85;i++) 10 | arr[i]=arr[i-1]+arr[i-2]; 11 | 12 | } 13 | 14 | int main() 15 | { 16 | 17 | int t; 18 | cin>>t; 19 | fibo(); 20 | 21 | while(t--) 22 | { 23 | int n; 24 | cin>>n; 25 | 26 | for(int i=1;i<=n;i++) 27 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int t,n,m; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n>>m; 11 | string x,y; 12 | cin>>x>>y; 13 | int result=0; 14 | int Longest[n+1][m+1]; 15 | for(int i=0;i<=n;i++) 16 | { 17 | for(int j=0;j<=n;j++) 18 | { 19 | if(i==0||j==0) 20 | Longest[i][j]=0; 21 | else if(x[i-1]==y[j-1]) 22 | { 23 | Longest[i][j]=Longest[i-1][j-1]+1; 24 | result=max(result,Longest[i][j]); 25 | } 26 | else 27 | Longest[i][j]=0; 28 | } 29 | } 30 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int t,n; 7 | cin>>t; 8 | while(t--){ 9 | cin>>n; 10 | int a[n]; 11 | for(int i=0;i>a[i]; 13 | int dp[n],result=0; 14 | dp[0]=1; 15 | int k=0; 16 | for(int i=1;i 2 | using namespace std; 3 | int Min_jump(int a[],int n) 4 | { 5 | int jum[n]; 6 | if(a[0]==0) 7 | return -1; 8 | for(int i=1;ii;j--) 15 | { 16 | if(j>t; 34 | while(t--) 35 | { 36 | cin>>n; 37 | int a[n]; 38 | for(int i=0;i>a[i]; 40 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int fact = 1; 8 | int n; 9 | cout << "Please enter an integer: "; 10 | cin >> n; 11 | 12 | for(int index = 1; index <= n; index++) 13 | { 14 | fact = fact * index; 15 | } 16 | 17 | cout << "The factorial of " << n << " is " << fact; 18 | return 0; 19 | } 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /C++/Fibonacci/Fibonacci_.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t1 = 0, t2 = 1, nextTerm = 0, n; 7 | 8 | cout << "Enter a positive number: "; 9 | cin >> n; 10 | 11 | // displays the first two terms which is always 0 and 1 12 | cout << "Fibonacci Series: " << t1 << ", " << t2 << ", "; 13 | 14 | nextTerm = t1 + t2; 15 | 16 | while(nextTerm <= n) 17 | { 18 | cout << nextTerm << ", "; 19 | t1 = t2; 20 | t2 = nextTerm; 21 | nextTerm = t1 + t2; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++/Fibonacci/Fibonacci_series.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fib(int n) 3 | { 4 | int t0=0,t1=1,s=0,i; 5 | if(n<=1) return n; 6 | for(i=2;i<=n;i++) 7 | { 8 | s=t0+t1; 9 | t0=t1; 10 | t1=s; 11 | } 12 | return s; 13 | } 14 | int rfib(int n) 15 | { 16 | if(n<=1)return n; 17 | return rfib(n-2)+rfib(n-1); 18 | } 19 | int F[10]; 20 | int mfib(int n) 21 | { 22 | if(n<=1) 23 | { 24 | F[n]=n; 25 | return n; 26 | } 27 | else 28 | { 29 | if(F[n-2]==-1) 30 | F[n-2]=mfib(n-2); 31 | if(F[n-1]==-1) 32 | F[n-1]=mfib(n-1); 33 | F[n]=F[n-2]+F[n-1]; 34 | return F[n-2]+F[n-1]; 35 | } 36 | } 37 | int main() 38 | { 39 | int i; 40 | for(i=0;i<10;i++) 41 | F[i]=-1; 42 | printf("%d \n",mfib(5)); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++/Fibonacci/fib_recursive.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to generate the fibonacci series in a given limit using recursion 2 | 3 | #include 4 | using namespace std; 5 | int Fib(int num) 6 | { 7 | if ( num == 0 ) 8 | return 0; 9 | else if ( num == 1 ) 10 | return 1; 11 | else 12 | return ( Fib(num-2) + Fib(num-1) ); 13 | } 14 | int main() 15 | { 16 | int i=0,limit,n=0; 17 | cout<<"Enter the limit: "; 18 | cin>>limit; 19 | cout<<"Fibonacci Series is:"< 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int limit; 8 | cout<<"Enter limit "; 9 | cin>>limit; 10 | int a=0,b=1,c=0; 11 | cout< 6 | #define MAX 10 7 | using namespace std; 8 | typedef struct edge 9 | { 10 | int src; 11 | int dest; 12 | int wt; 13 | }edge; 14 | void bellman_ford(int nv,edge e[],int src_graph,int ne) 15 | { 16 | int u,v,weight,i,j=0; 17 | int dis[MAX]; 18 | 19 | /* initializing array 'dis' with 999. 999 denotes infinite distance */ 20 | for(i=0;i>nv; 72 | 73 | /* if you enter no of vertices: 5 then vertices will be 1,2,3,4,5. so while giving input enter source and destination vertex accordingly */ 74 | printf("Enter the source vertex of the graph: "); 75 | cin>>src_graph; 76 | 77 | cout<<"\nEnter no. of edges: "; 78 | cin>>ne; 79 | 80 | for(int i=0;i"; 83 | cout<<"\nEnter source vertex :"; 84 | cin>>e[i].src; 85 | cout<<"Enter destination vertex :"; 86 | cin>>e[i].dest; 87 | cout<<"Enter weight :"; 88 | cin>>e[i].wt; 89 | } 90 | 91 | bellman_ford(nv,e,src_graph,ne); 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /C++/Graph Algorithms/kruskal.cpp: -------------------------------------------------------------------------------- 1 | //Minimum Spanning Tree Algorithm (MST) 2 | // Time Complexity: O(ElogE) 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct t_edge{ 9 | int dis; 10 | int x, y; 11 | }; 12 | 13 | bool comp(t_edge a, t_edge b){ return a.dis < b.dis; } 14 | 15 | //-------------------- 16 | #define MAXN 50500 17 | #define MAXM 200200 18 | 19 | int n, m; // number of nodes and edges 20 | t_edge edges[MAXM]; 21 | 22 | // for the union find 23 | int father[MAXN]; 24 | 25 | // the tree 26 | t_edge mst[MAXM]; 27 | //-------------------- 28 | 29 | // union find functions 30 | int find(int x){ 31 | if(father[x] == x) return x; 32 | return father[x] = find(father[x]); 33 | } 34 | 35 | void join(int a, int b){ 36 | 37 | a = find(a); 38 | b = find(b); 39 | 40 | father[a] = b; 41 | 42 | } 43 | 44 | 45 | int main(){ 46 | 47 | // input 48 | cin >> n >> m; 49 | 50 | for(int i = 1;i <= m;i++) 51 | cin >> edges[i].x >> edges[i].y >> edges[i].dis; 52 | 53 | 54 | // initialize parents to union-find 55 | for(int i = 1;i <= n;i++) father[i] = i; 56 | 57 | // order ther edges 58 | sort(edges+1, edges+m+1, comp); 59 | 60 | int size = 0; 61 | for(int i = 1;i <= m;i++){ 62 | 63 | if( find(edges[i].x) != find(edges[i].y) ){ //if they are in separate components 64 | join(edges[i].x, edges[i].y); 65 | 66 | mst[++size] = edges[i]; 67 | } 68 | 69 | } 70 | 71 | // print the MST 72 | for(int i = 1;i < n;i++){ 73 | cout << mst[i].x << " " << mst[i].y << " " << mst[i].dis << "\n"; 74 | } 75 | 76 | return 0; 77 | } -------------------------------------------------------------------------------- /C++/Graph Algorithms/prim.cpp: -------------------------------------------------------------------------------- 1 | // Minimum Spanning Tree (MST) - Prim 2 | // Time Complexity: O(MlogN) 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | typedef pair pii; 11 | //--------------------- 12 | #define MAXN 10100 13 | // As there is no Infinite on the computer, we will use a very large number 14 | #define INFINITY 999999999 15 | 16 | int n, m; // number of nodes and edges 17 | int dist[MAXN]; // distances to font 18 | int processed[MAXN]; // if the node was processed 19 | vector neighbors[MAXN]; //The first element of pair is the distance and the second the node 20 | //--------------------- 21 | 22 | int Prim(){ 23 | 24 | for(int i = 1;i <= n;i++) dist[i] = INFINITY; // we define all distances as infinite, except for S = 1. 25 | dist[1] = 0; // Thus, we guarantee that the first selected node will be 1 itself. 26 | 27 | priority_queue< pii, vector, greater > queue; // Created a priority queue where the smallest is at the top. 28 | queue.push( pii(dist[1], 1) ); // As you can see, we put the first element as the distance from the 29 | // node in the Minimum Generation Tree and the second as the vertex itself 30 | 31 | while(true){ // run "endlessly" 32 | 33 | int actual = -1; 34 | 35 | // we select the nearest node 36 | while(!queue.empty()){ 37 | 38 | int current = queue.top().second; 39 | queue.pop(); 40 | 41 | if(!processed[current]){ // we can use this node because it hasn't been processed yet 42 | actual = current; 43 | break; 44 | } 45 | 46 | // if not, we keep looking 47 | } 48 | 49 | if(actual == -1) break; // if not found anyone, it's the end of the algorithm 50 | 51 | processed[actual] = true; // we mark to not go back to this node 52 | 53 | //now, we'll try to update the distances 54 | for(int i = 0;i < (int)neighbors[actual].size();i++){ 55 | 56 | int distV = neighbors[actual][i].first; 57 | int current = neighbors[actual][i].second; 58 | 59 | // The new possible distance is distV. 60 | // We compare this with dist[current]. 61 | // However, it is important to check if the current node has not been processed yet 62 | 63 | if( dist[current] > distV && !processed[current]){ // we see if it is worth using the actual node 64 | dist[current] = distV; // update the distance 65 | queue.push( pii(dist[current], current) ); // add to the priority queue 66 | } 67 | } 68 | } 69 | 70 | int tree_cost = 0; 71 | for(int i = 1;i <= n;i++) tree_cost += dist[i]; 72 | 73 | return tree_cost; 74 | } 75 | 76 | int main(){ 77 | 78 | cin >> n >> m; 79 | 80 | for(int i = 1;i <= m;i++){ 81 | 82 | int x, y, weight; 83 | cin >> x >> y >> weight; 84 | 85 | neighbors[x].push_back( pii(weight, y) ); 86 | neighbors[y].push_back( pii(weight, x) ); 87 | } 88 | 89 | cout << Prim() << endl; // print the answer 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /C++/Kruskal_Algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | #define edge pair 7 | 8 | class Graph { 9 | private: 10 | vector > G; // graph 11 | vector > T; // mst 12 | int *parent; 13 | int V; // number of vertices/nodes in graph 14 | public: 15 | Graph(int V); 16 | void AddWeightedEdge(int u, int v, int w); 17 | int find_set(int i); 18 | void union_set(int u, int v); 19 | void kruskal(); 20 | void print(); 21 | }; 22 | Graph::Graph(int V) { 23 | parent = new int[V]; 24 | 25 | //i 0 1 2 3 4 5 26 | //parent[i] 0 1 2 3 4 5 27 | for (int i = 0; i < V; i++) 28 | parent[i] = i; 29 | 30 | G.clear(); 31 | T.clear(); 32 | } 33 | void Graph::AddWeightedEdge(int u, int v, int w) { 34 | G.push_back(make_pair(w, edge(u, v))); 35 | } 36 | int Graph::find_set(int i) { 37 | // If i is the parent of itself 38 | if (i == parent[i]) 39 | return i; 40 | else 41 | // Else if i is not the parent of itself 42 | // Then i is not the representative of his set, 43 | // so we recursively call Find on its parent 44 | return find_set(parent[i]); 45 | } 46 | 47 | void Graph::union_set(int u, int v) { 48 | parent[u] = parent[v]; 49 | } 50 | void Graph::kruskal() { 51 | int i, uRep, vRep; 52 | sort(G.begin(), G.end()); // increasing weight 53 | for (i = 0; i < G.size(); i++) { 54 | uRep = find_set(G[i].second.first); 55 | vRep = find_set(G[i].second.second); 56 | if (uRep != vRep) { 57 | T.push_back(G[i]); // add to tree 58 | union_set(uRep, vRep); 59 | } 60 | } 61 | } 62 | void Graph::print() { 63 | cout << "Edge :" 64 | << " Weight" << endl; 65 | for (int i = 0; i < T.size(); i++) { 66 | cout << T[i].second.first << " - " << T[i].second.second << " : " 67 | << T[i].first; 68 | cout << endl; 69 | } 70 | } 71 | int main() { 72 | Graph g(6); 73 | g.AddWeightedEdge(0, 1, 4); 74 | g.AddWeightedEdge(0, 2, 4); 75 | g.AddWeightedEdge(1, 2, 2); 76 | g.AddWeightedEdge(1, 0, 4); 77 | g.AddWeightedEdge(2, 0, 4); 78 | g.AddWeightedEdge(2, 1, 2); 79 | g.AddWeightedEdge(2, 3, 3); 80 | g.AddWeightedEdge(2, 5, 2); 81 | g.AddWeightedEdge(2, 4, 4); 82 | g.AddWeightedEdge(3, 2, 3); 83 | g.AddWeightedEdge(3, 4, 3); 84 | g.AddWeightedEdge(4, 2, 4); 85 | g.AddWeightedEdge(4, 3, 3); 86 | g.AddWeightedEdge(5, 2, 2); 87 | g.AddWeightedEdge(5, 4, 3); 88 | g.kruskal(); 89 | g.print(); 90 | return 0; 91 | } 92 | 93 | /* Output: 94 | Edge : Weight 95 | 1 - 2 : 2 96 | 2 - 5 : 2 97 | 2 - 3 : 3 98 | 3 - 4 : 3 99 | 0 - 1 : 4 */ 100 | -------------------------------------------------------------------------------- /C++/LCS_DP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // function to find the length of the largest common subsequence between 2 strings 5 | int LCS(string s,string t) 6 | { 7 | int n=s.size(),m=t.size(),i,j; 8 | 9 | if(!n || !m) 10 | return 0; 11 | 12 | vector> dp(n+1, vector (m+1)); 13 | for(i=1;i<=n;i++) 14 | { 15 | for(j=1;j<=m;j++) 16 | { 17 | if(s[i-1] == t[j-1]) 18 | dp[i][j] = dp[i-1][j-1]+1; 19 | else 20 | dp[i][j] = max(dp[i-1][j],dp[i][j-1]); 21 | } 22 | } 23 | return dp[n][m]; 24 | } 25 | 26 | int main() 27 | { 28 | string s,t; 29 | cin>>s>>t; 30 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int l,i,j; 6 | cout<<"Enter length of the square matrix (max 100) - \n"; 7 | cin>>l; 8 | int arr[100][100]; 9 | int tr[100][100]; 10 | cout<<"Enter the matrix row wise - \n"; 11 | for(i=0; i>arr[i][j]; 15 | } 16 | for(i=0; i1: 7 | m = len(values)//2 8 | left = values[:m] 9 | right = values[m:] 10 | left = merge_sort(left) 11 | right = merge_sort(right) 12 | 13 | values =[] 14 | 15 | while len(left)>0 and len(right)>0: 16 | if left[0] 2 | using namespace std; 3 | 4 | // Returns the optimal value a maximizer can obtain. 5 | // depth is current depth in game tree. 6 | // nodeIndex is index of current node in scores[]. 7 | // isMax is true if current move is 8 | // of maximizer, else false 9 | // scores[] stores leaves of Game tree. 10 | // h is maximum height of Game tree 11 | int minimax(int depth, int nodeIndex, bool isMax, 12 | int scores[], int h) 13 | { 14 | // Terminating condition. i.e 15 | // leaf node is reached 16 | if (depth == h) 17 | return scores[nodeIndex]; 18 | 19 | // If current move is maximizer, 20 | // find the maximum attainable 21 | // value 22 | if (isMax) 23 | return max(minimax(depth+1, nodeIndex*2, false, scores, h), 24 | minimax(depth+1, nodeIndex*2 + 1, false, scores, h)); 25 | 26 | // Else (If current move is Minimizer), find the minimum 27 | // attainable value 28 | else 29 | return min(minimax(depth+1, nodeIndex*2, true, scores, h), 30 | minimax(depth+1, nodeIndex*2 + 1, true, scores, h)); 31 | } 32 | 33 | // function to find Log n in base 2 34 | int log2(int n) 35 | { 36 | return (n==1)? 0 : 1 + log2(n/2); 37 | } 38 | 39 | int main() 40 | { 41 | // The number of elements in scores must be 42 | // a power of 2. 43 | int n,i,j; 44 | cout<<"Enter size of array(Must be in powers of 2)"; 45 | cin>>n; 46 | if(n%2==1) 47 | { 48 | cout<<"Invalid size"; 49 | return 0; 50 | } 51 | int scores[n]; 52 | cout<<"Enter scores:"; 53 | for(i=0;i>scores[i]; 55 | int h = log2(n); 56 | int res = minimax(0, 0, true, scores, h); 57 | cout << "The optimal value is : " << res << endl; 58 | return 0; 59 | } -------------------------------------------------------------------------------- /C++/MultipleInheritance/Code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class A 6 | { 7 | public: 8 | A(){ 9 | callA = 0; 10 | } 11 | private: 12 | int callA; 13 | void inc(){ 14 | callA++; 15 | } 16 | 17 | protected: 18 | void func(int & a) 19 | { 20 | a = a * 2; 21 | inc(); 22 | } 23 | public: 24 | int getA(){ 25 | return callA; 26 | } 27 | }; 28 | 29 | class B 30 | { 31 | public: 32 | B(){ 33 | callB = 0; 34 | } 35 | private: 36 | int callB; 37 | void inc(){ 38 | callB++; 39 | } 40 | protected: 41 | void func(int & a) 42 | { 43 | a = a * 3; 44 | inc(); 45 | } 46 | public: 47 | int getB(){ 48 | return callB; 49 | } 50 | }; 51 | 52 | class C 53 | { 54 | public: 55 | C(){ 56 | callC = 0; 57 | } 58 | private: 59 | int callC; 60 | void inc(){ 61 | callC++; 62 | } 63 | protected: 64 | void func(int & a) 65 | { 66 | a = a * 5; 67 | inc(); 68 | } 69 | public: 70 | int getC(){ 71 | return callC; 72 | } 73 | }; 74 | 75 | class D : public A, public B, public C 76 | 77 | { 78 | 79 | int val; 80 | public: 81 | //Initially val is 1 82 | D() 83 | { 84 | val = 1; 85 | } 86 | 87 | 88 | //Implement this function 89 | void update_val(int new_val) 90 | { 91 | while(new_val%2==0){ 92 | A::func(val); 93 | new_val/=2; 94 | 95 | 96 | } 97 | 98 | while(new_val%3 == 0) { 99 | 100 | 101 | B::func(val); 102 | 103 | 104 | new_val /= 3; 105 | 106 | 107 | } 108 | 109 | 110 | while(new_val%5 == 0) { 111 | 112 | 113 | C::func(val); 114 | 115 | 116 | new_val /= 5; 117 | 118 | 119 | } 120 | 121 | } 122 | //For Checking Purpose 123 | void check(int); //Do not delete this line. 124 | }; 125 | 126 | 127 | 128 | void D::check(int new_val) 129 | { 130 | update_val(new_val); 131 | cout << "Value = " << val << endl << "A's func called " << getA() << " times " << endl << "B's func called " << getB() << " times" << endl << "C's func called " << getC() << " times" << endl; 132 | } 133 | 134 | 135 | int main() 136 | { 137 | D d; 138 | int new_val; 139 | cin >> new_val; 140 | d.check(new_val); 141 | 142 | } 143 | -------------------------------------------------------------------------------- /C++/MultipleInheritance/Readme.md: -------------------------------------------------------------------------------- 1 | ***INHERITANCE 2 | 3 | The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important feature of Object Oriented Programming. 4 | 5 | ***MULTIPLE INHERITANCE 6 | 7 | Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes. i.e one sub class is inherited from more than one base classes. 8 | 9 | 10 | 11 | ***QUESTION : 12 | 13 | 14 | You need to modify the class D and implement the function update_val which sets D's val to new_val by manipulating the value by only calling the func defined in classes A, B and C. 15 | It is guaranteed that new_val has only and as its prime factors. 16 | Input Format 17 | Implement class D's function update_val. This function should update D's val only by calling A, B and C's func. 18 | Constraints 19 | new_val 20 | Note: The new_val only has and as its prime factors. 21 | Sample Input 22 | new_val 23 | Sample Output 24 | A's func will be called once. 25 | B's func will be called once. 26 | C's func will be called once. 27 | Explanation 28 | Initially, val . 29 | A's func is called once: 30 | val = val*2 31 | val = 2 32 | B's func is called once: 33 | val = val*3 34 | val = 6 35 | C's func is called once: 36 | val = val*5 37 | val = 30 38 | -------------------------------------------------------------------------------- /C++/NewtonRapshon/newtonRaphson.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define f(x) (5*x*x*x*x*x-3*x*x-100) 5 | #define g(x) (25*x*x*x*x-6*x) 6 | #define E 0.00001 7 | int main() 8 | { 9 | float ecal,xi,x0,count; 10 | printf("\n************************Newton Raphson Method**********************************\n"); 11 | printf("\n Enter initial value x0 = "); 12 | scanf("%f",&x0); 13 | if(g(x0)==0) 14 | { 15 | printf("\n Sorry the first derivative is zero, enter another initial value. \n"); 16 | } 17 | else 18 | { 19 | do{ 20 | xi = x0 -(f(x0)/g(x0)); 21 | ecal = fabs((xi-x0)/xi); 22 | x0 = xi; 23 | printf("\n x0=%f \t f(x0)=%f \t g(x0)=%f \t xi=%f \t ecal=%f \n",x0,f(x0),g(x0),xi,ecal); 24 | count += 1; 25 | }while(E 12) 27 | { 28 | printf("\n iterative more than 12. There is no solution. \n"); 29 | } 30 | printf("\n Root is %f",x0); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++/NewtonRapshon/newtonRaphson.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/C++/NewtonRapshon/newtonRaphson.exe -------------------------------------------------------------------------------- /C++/Overloading.cpp: -------------------------------------------------------------------------------- 1 | //C++ program to demo Operator Overloading 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class overloading 8 | { 9 | int value; 10 | public: 11 | void setValue(int temp) 12 | { 13 | value = temp; 14 | } 15 | overloading operator+(overloading& ob) 16 | { 17 | overloading t; 18 | t.value=value+ob.value; 19 | return(t); 20 | } 21 | void display() 22 | { 23 | cout<>a>>b; 35 | obj1.setValue(a); 36 | obj2.setValue(b); 37 | 38 | result = obj1+obj2; 39 | 40 | cout<<"Input Values:\n"; 41 | obj1.display(); 42 | obj2.display(); 43 | 44 | cout<<"Result:"; 45 | result.display(); 46 | 47 | getch(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /C++/Patterns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | cout<<"Enter height of pattern"; 7 | int n; 8 | cin>>n; 9 | for(int i=0;i 2 | 3 | #define pb push_back 4 | #define MAXN (int)1e5+100 5 | 6 | using namespace std; 7 | 8 | int n, s, x[30]; 9 | vectorans; 10 | bool rec(int pos, int sum) 11 | { 12 | if(pos==n) 13 | { 14 | if(sum==s)return true; 15 | return false; 16 | } 17 | 18 | if(rec(pos+1, sum+x[pos])){ans.pb('+');return true;} 19 | if(rec(pos+1, sum-x[pos])){ans.pb('-');return true;} 20 | } 21 | 22 | int main() 23 | { 24 | cin>>n>>s; 25 | for(int i=0; i>x[i]; 28 | } 29 | 30 | rec(1, x[0]); 31 | reverse(ans.begin(), ans.end()); 32 | if(!ans.empty()) 33 | { 34 | cout< 8 | #include 9 | #include 10 | 11 | // Function to generate PNG image 12 | void generate_PNG(int const width, 13 | int const height, 14 | std::string filepath) 15 | { 16 | 17 | // Print the filepath 18 | cout << endl << "Filepath: " << filepath.c_str(); 19 | 20 | // Generate the flag 21 | pngwriter flag{ width, height, 0, filepath.data() }; 22 | 23 | // Calculate sizes 24 | int const size = width / 3; 25 | 26 | // Fill the squares 27 | flag.filledsquare(0, 0, size, 2 * size, 0, 0, 65535); 28 | 29 | flag.filledsquare(size, 0, 2 * size, 2 * size, 0, 65535, 65535); 30 | 31 | flag.filledsquare(2 * size, 0, 3 * size, 2 * size, 65535, 0, 65535); 32 | 33 | // Close the flag 34 | flag.close(); 35 | } 36 | 37 | // Driver code 38 | int main() 39 | { 40 | // Given width and height 41 | int width = 300, height = 200; 42 | 43 | // Filepath 44 | std::string filepath; 45 | 46 | // Function call to generate PNG image 47 | generate_PNG(width, height, filepath); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /C++/ResortSortedArray/resortsortedarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n;//length of array 8 | cin>>n; 9 | int arr[n]; 10 | //example of input {-8, -5, -3, -1, 3, 6, 9} 11 | for(int i = 0; i< n; i++){//Input array to be in General sorted order 12 | cin>>arr[i]; 13 | } 14 | int x = -1; 15 | for(int i = 0; i< n; i++){//getting pointer to last negative element in array 16 | if(arr[i] < 0) { 17 | x++; 18 | } 19 | else{ 20 | break; 21 | } 22 | } 23 | int posi = x+1; 24 | vector res(n);//resultant resorted array 25 | int it = 0, m; 26 | while(x >= 0 && posi <= n-1){ 27 | if(abs(arr[x]) > abs(arr[posi])){ 28 | res[it] = arr[posi]; 29 | posi++; 30 | } 31 | else{ 32 | res[it] = arr[x]; 33 | x--; 34 | } 35 | it++; 36 | } 37 | while(it< n){ 38 | while(x >= 0){ 39 | res[it] = arr[x]; 40 | x--; 41 | it++; 42 | } 43 | while(posi <= n-1){ 44 | res[it] = arr[posi]; 45 | posi++; 46 | it++; 47 | } 48 | } 49 | 50 | for(int i = 0; i< n; i++){ 51 | cout<< res[i]<<" "; 52 | } 53 | //example of output {-1, -3, 3, -5, 6, -8, 9} 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /C++/SJF(Scheduling algo.)/Readme.md: -------------------------------------------------------------------------------- 1 | ## **Shortest Job First Scheduling Algorithm (SJF - Non-Preemptive) in C++** 2 | 3 | Time Complexity : O(n^2) 4 | 5 | Space Complexity : O(n) 6 | 7 | Description : To calculate the average waiting time using the SJF(Non- Preemption) 8 | algorithm. First sort the processes in ascending order of their burst time and the process having 9 | the shortest burst time is executed first and so on. Second waiting time of the first process is kept 10 | zero and the waiting time of the second process is the burst time of the first process and the 11 | waiting time of the third process is the sum of the burst time of the first and the second process 12 | and so on. After calculating all the waiting times the average waiting time is calculated as the 13 | average of all the waiting times. SJF mainly says shortest job first the algorithm. -------------------------------------------------------------------------------- /C++/SJF(Scheduling algo.)/Shortest Job First Schedulling Algorithm(SJF - Non-Preemptive).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int i,n,WaitT[20],BurstT[20],TurnaroundT[20],j,key; 9 | float AverageTT,AverageWT,TotalWT=0,TotalTT=0; 10 | cout << "Enter the number of processes : "; 11 | cin >> n; 12 | for(i=0;i 2 | #include 3 | #include 4 | #define f(x) (4*x*x-5*x-10) 5 | #define E 0.00001 6 | int main() 7 | { 8 | float x0,x1,x2,ecal,count; 9 | printf("\n ************Secent Method***************"); 10 | printf("\n Enter initial value :- \n"); 11 | printf("\n x0 = "); 12 | scanf("%f",&x0); 13 | printf("\n x1 = "); 14 | scanf("%f",&x1); 15 | do{ 16 | x2 = x1-((f(x1)*(x1-x0))/(f(x1)-f(x0))); 17 | ecal =fabs((x2-x1)/x2); 18 | x0 = x1; 19 | x1 = x2; 20 | printf("\n x0=%f \t x1=%f \t x2=%f \t ecal=%f \n",x0,x1,x2,ecal); 21 | count += 1; 22 | }while(E 12) 24 | { 25 | printf("\n Iteration moore than 12, no solution \n"); 26 | } 27 | printf("\n Root is %f",x2); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C++/SecentMethod/secentMethod.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/C++/SecentMethod/secentMethod.exe -------------------------------------------------------------------------------- /C++/Selection Sort/SELECTION_SORT.cpp: -------------------------------------------------------------------------------- 1 | // C++ program for implementation of selection sort 2 | #include 3 | using namespace std; 4 | 5 | void swap(int *xp, int *yp) 6 | { 7 | int temp = *xp; 8 | *xp = *yp; 9 | *yp = temp; 10 | } 11 | 12 | void selectionSort(int arr[], int n) 13 | { 14 | int i, j, min_idx; 15 | 16 | // One by one move boundary of unsorted subarray 17 | for (i = 0; i < n-1; i++) 18 | { 19 | // Find the minimum element in unsorted array 20 | min_idx = i; 21 | for (j = i+1; j < n; j++) 22 | if (arr[j] < arr[min_idx]) 23 | min_idx = j; 24 | 25 | // Swap the found minimum element with the first element 26 | swap(&arr[min_idx], &arr[i]); 27 | } 28 | } 29 | 30 | /* Display the array */ 31 | void printArray(int arr[], int size) 32 | { 33 | int i; 34 | for (i=0; i < size; i++) 35 | cout << arr[i] << " "; 36 | cout << endl; 37 | } 38 | 39 | // Driver program 40 | int main(){ 41 | int arr[] = {6, 23, 2, 32, 11}; 42 | int n = sizeof(arr)/sizeof(arr[0]); 43 | selectionSort(arr, n); 44 | cout << "Sorted array: \n"; 45 | printArray(arr, n); 46 | return 0; 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /C++/Selection Sort/SELECTION_SORT.md: -------------------------------------------------------------------------------- 1 | # Selection Sort 2 | 3 | The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array. 4 | 5 | 1) The subarray which is already sorted. 6 | 2) Remaining subarray which is unsorted. 7 | 8 | In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray. 9 | -------------------------------------------------------------------------------- /C++/Selection Sort/SelectionSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,min,temp; 7 | int a[n]; 8 | cin>>n; 9 | for(int i=0;i>a[i]; 12 | } 13 | 14 | for(int i=0;i 3 | #include 4 | using namespace std; 5 | #define vertex 7 6 | int minimumDist(int dist[], bool Dset[]) 7 | { 8 | int min=INT_MAX,index; 9 | for(int v=0;v 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int i,j,n; 8 | 9 | cin>>n; 10 | 11 | for(i=1;i<=n;i++) 12 | { 13 | for(j=n;j>=i;j--) 14 | cout<<" "; 15 | cout<<"*"; 16 | 17 | if(i!=n) 18 | { 19 | for(j=i-1;j>=1;j--) 20 | cout<<" "; 21 | 22 | for(j=i-2;j>=1;j--) 23 | cout<<" "; 24 | } 25 | else 26 | { 27 | for(j=n*2-3;j>=1;j--) 28 | cout<<"*"; 29 | } 30 | 31 | if(i!=1) 32 | cout<<"*"; 33 | 34 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int num, originalNum, remainder, result = 0; 6 | cout << "Enter a three-digit integer: "; 7 | cin >> num; 8 | originalNum = num; 9 | 10 | while (originalNum != 0) { 11 | // remainder contains the last digit 12 | remainder = originalNum % 10; 13 | 14 | result += remainder * remainder * remainder; 15 | 16 | // removing last digit from the orignal number 17 | originalNum /= 10; 18 | } 19 | 20 | if (result == num) 21 | cout << num << " is an Armstrong number."; 22 | else 23 | cout << num << " is not an Armstrong number."; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C++/bubble_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void swapping(int &a, int &b) { //swap the content of a and b 4 | int temp; 5 | temp = a; 6 | a = b; 7 | b = temp; 8 | } 9 | void display(int *array, int size) { 10 | for(int i = 0; i array[j+1]) { //when the current item is bigger than next 19 | swapping(array[j], array[j+1]); 20 | swaps = 1; //set swap flag 21 | } 22 | } 23 | if(!swaps) 24 | break; // No swap in this pass, so array is sorted 25 | } 26 | } 27 | int main() { 28 | int n; 29 | cout << "Enter the number of elements: "; 30 | cin >> n; 31 | int arr[n]; //create an array with given number of elements 32 | cout << "Enter elements:" << endl; 33 | for(int i = 0; i> arr[i]; 35 | } 36 | cout << "Array before Sorting: "; 37 | display(arr, n); 38 | bubbleSort(arr, n); 39 | cout << "Array after Sorting: "; 40 | display(arr, n); 41 | } -------------------------------------------------------------------------------- /C++/calculator.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | char op; 7 | float num1, num2; 8 | 9 | cout << "Enter operator either + or - or * or /: "; 10 | cin >> op; 11 | 12 | cout << "Enter two operands: "; 13 | cin >> num1 >> num2; 14 | 15 | switch(op) 16 | { 17 | case '+': 18 | cout << num1+num2; 19 | break; 20 | 21 | case '-': 22 | cout << num1-num2; 23 | break; 24 | 25 | case '*': 26 | cout << num1*num2; 27 | break; 28 | 29 | case '/': 30 | cout << num1/num2; 31 | break; 32 | 33 | default: 34 | // If the operator is other than +, -, * or /, error message is shown 35 | cout << "Error! operator is not correct"; 36 | break; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /C++/cocktailSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void numSwap(int &x, int &y){ 5 | int temp = 0; 6 | 7 | temp = x; 8 | x = y; 9 | y = temp; 10 | 11 | } 12 | 13 | void display (int arr[], int len){ 14 | int i; 15 | cout<<"Sorted array via Cocktail Sort - \n"; 16 | for(i=0; i> arrIn[ctr++]; 35 | } 36 | 37 | len = ctr; 38 | 39 | while (didItSwap) 40 | { 41 | didItSwap = 0; 42 | //even iterators will run the bubble sort swap from left to right 43 | if (i%2 == 0){ 44 | 45 | for (j=0; j arrIn [j+1]){ 47 | numSwap(arrIn[j], arrIn[j+1]); 48 | didItSwap = 1; 49 | } 50 | } 51 | 52 | //odd iterators will run the bubble sort swap from right to left 53 | } else if (i%2 != 0){ 54 | 55 | for (j=len-2; j>=0; j--){ 56 | if (arrIn[j] > arrIn [j + 1]){ 57 | numSwap(arrIn[j], arrIn[j + 1]); 58 | didItSwap = 1; 59 | } 60 | } 61 | 62 | 63 | } else{ 64 | cout << "Invalid"; 65 | } 66 | 67 | } 68 | 69 | display(arrIn, len); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /C++/counting_bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector countBits(int num) { 4 | vector dp(num+1); 5 | for(int i=1;i<=num;i++){ 6 | if(i%2==0){ 7 | int num=i-1; 8 | while(num&1)num>>=1; 9 | dp[i]=dp[num]+1; 10 | } 11 | else 12 | dp[i]=dp[i-1]+1; 13 | } 14 | return dp; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /C++/dmn.cpp: -------------------------------------------------------------------------------- 1 | // script for exercise "Domino" from contest ilocamp 3 grupa srenia 2 | // its content you can find there: https://szkopul.edu.pl/ 3 | #include 4 | #define pc putchar 5 | #define gc getchar 6 | #define gcu getchar_unlocked 7 | #define fi first 8 | #define se second 9 | #define pb push_back 10 | #define mod ((ll)1e9 + 7) 11 | typedef long long ll; 12 | typedef unsigned long long ull; 13 | using namespace std; 14 | //=============================================================================================== 15 | 16 | int n, base = 1; 17 | int d[3000009], a[1000009]; 18 | ll odl[3000009]; 19 | void zad(int x); 20 | int znajdz(int x); 21 | int dok(ll x, int l, int r, int v); 22 | void ustaw(int v, int l, int r, int x, int y, int val); 23 | 24 | //=============================================================================================== 25 | int main() 26 | { 27 | scanf("%d", &n); 28 | while (base < n) 29 | base <<= 1; 30 | for (int i = 0; i < base * 2; i++) 31 | d[i] = INT_MAX, odl[i] = LLONG_MAX; 32 | for (int i = 0, temp; i < n; i++) 33 | scanf("%d", &a[i]); 34 | for (int i = 1, temp; i < n; i++) 35 | { 36 | scanf("%d", &temp); 37 | odl[i + base] = temp; 38 | if (i > 1) 39 | odl[i + base] += odl[i + base - 1]; 40 | } 41 | odl[base] = 0; 42 | for (int i = base - 1; i; i--) 43 | odl[i] = min(odl[i * 2], odl[i * 2 + 1]); 44 | for (int i = 0; i < n; i++) 45 | zad(i); 46 | printf("%d\n", n - znajdz(n - 1) - 1); 47 | } 48 | //=============================================================================================== 49 | void zad(int x) 50 | { 51 | int y = znajdz(x) + 1; 52 | if (!x) 53 | y = 1; 54 | ll z = (ll)a[x] + odl[base + x]; 55 | int dokiedy = min(dok(z, 0, base - 1, 1), base - 1); 56 | ustaw(1, 0, base - 1, x + 1, dokiedy, y); 57 | } 58 | int znajdz(int x) 59 | { 60 | x += base; 61 | int ret = INT_MAX; 62 | while (x) 63 | { 64 | ret = min(ret, d[x]); 65 | x >>= 1; 66 | } 67 | return ret; 68 | } 69 | int dok(ll x, int l, int r, int v) 70 | { 71 | if (x <= odl[v]) 72 | return -1; 73 | if (l == r) 74 | return r; 75 | return max(dok(x, l, (l + r) / 2, v * 2), dok(x, (l + r) / 2 + 1, r, v * 2 + 1)); 76 | } 77 | void ustaw(int v, int l, int r, int x, int y, int val) 78 | { 79 | if (l > y || r < x) 80 | return; 81 | if (l >= x && r <= y) 82 | { 83 | d[v] = min(d[v], val); 84 | return; 85 | } 86 | ustaw(v * 2, l, (l + r) / 2, x, y, val); 87 | ustaw(v * 2 + 1, (l + r) / 2 + 1, r, x, y, val); 88 | } 89 | -------------------------------------------------------------------------------- /C++/fibbonaci.cpp: -------------------------------------------------------------------------------- 1 | //fibbonaci series 2 | using namespace std; 3 | #include 4 | class sam 5 | { 6 | int t1=0,t2=1,t3; 7 | public: 8 | int fib(int n) 9 | { 10 | cout<<"the terms of the fibbonaci series are "; 11 | cout<>n; 28 | obj.fib(n); 29 | return 0; 30 | } 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /C++/greatest_number/greatest-number.cpp: -------------------------------------------------------------------------------- 1 | //Greatest of two numbers 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int num1, num2; 9 | cout<<"Enter first number:"; 10 | cin>>num1; 11 | cout<<"Enter second number:"; 12 | cin>>num2; 13 | if(num1>num2) 14 | { 15 | cout<<"First number "< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | string s; 8 | cin>>s; 9 | 10 | int length_of_string = s.size(); 11 | bool is_palindrome=1; 12 | if(length_of_string%2==0 /*if length of string is even*/){ 13 | for(int i=0; i<=length_of_string/2; ++i){ 14 | if(s[i]!=s[length_of_string-i-1]){ 15 | is_palindrome=0; 16 | } 17 | } 18 | }else{ 19 | for(int i=0; i 4 | #define pc putchar 5 | #define gc getchar 6 | #define gcu getchar_unlocked 7 | #define fi first 8 | #define se second 9 | #define pb push_back 10 | #define mod ((ll)1e9 + 7) 11 | typedef long long ll; 12 | typedef unsigned long long ull; 13 | using namespace std; 14 | //=============================================================================================== 15 | 16 | int n, d, ans; 17 | int a[1009][1009]; 18 | pair> f[1009][1009]; 19 | vector>> v; 20 | void find(pair p); 21 | pair koniec(int x, int y); 22 | 23 | //=============================================================================================== 24 | int main() 25 | { 26 | ios_base::sync_with_stdio(0); 27 | cin.tie(NULL); 28 | cout.tie(NULL); 29 | cin >> n >> d; 30 | for (int i = 0; i < n; i++) 31 | for (int j = 0; j < n; j++) 32 | { 33 | cin >> a[i][j]; 34 | v.pb({a[i][j], {i, j}}); 35 | f[i][j] = {0, {i, j}}; 36 | } 37 | sort(v.begin(), v.end()); 38 | for (int i = 0; i < n * n; i++) 39 | { 40 | find(v[i].se); 41 | if (ans) 42 | { 43 | cout << v[i].fi; 44 | return 0; 45 | } 46 | } 47 | } 48 | //=============================================================================================== 49 | void find(pair p) 50 | { 51 | vector> vec; 52 | int x = p.fi, y = p.se; 53 | if (x - 1 >= 0) 54 | if (a[x - 1][y] <= a[x][y]) 55 | vec.pb(koniec(x - 1, y)); 56 | if (y + 1 < n) 57 | if (a[x][y + 1] <= a[x][y]) 58 | vec.pb(koniec(x, y + 1)); 59 | if (y - 1 >= 0) 60 | if (a[x][y - 1] <= a[x][y]) 61 | vec.pb(koniec(x, y - 1)); 62 | if (x + 1 < n) 63 | if (a[x + 1][y] <= a[x][y]) 64 | vec.pb(koniec(x + 1, y)); 65 | vec.pb({x, y}); 66 | sort(vec.begin(), vec.end()); 67 | for (int i = 1; i < vec.size(); i++) 68 | { 69 | if (vec[i] == vec[i - 1]) 70 | { 71 | vec.erase(vec.begin() + i); 72 | i--; 73 | } 74 | } 75 | for (int i = 1; i < vec.size(); i++) 76 | { 77 | f[vec[0].fi][vec[0].se].fi += f[vec[i].fi][vec[i].se].fi; 78 | f[vec[i].fi][vec[i].se] = {0, {vec[0].fi, vec[0].se}}; 79 | } 80 | f[vec[0].fi][vec[0].se].fi++; 81 | if (f[vec[0].fi][vec[0].se].fi >= d) 82 | ans++; 83 | } 84 | pair koniec(int x, int y) 85 | { 86 | if (f[x][y].se == make_pair(x, y)) 87 | return {x, y}; 88 | f[x][y].se = koniec(f[x][y].se.fi, f[x][y].se.se); 89 | return f[x][y].se; 90 | } 91 | -------------------------------------------------------------------------------- /C++/palindrome_using_stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | #define MAX 50 6 | 7 | class Stack { 8 | private: 9 | char data[MAX],str[MAX]; 10 | int top,length,count; 11 | 12 | void pushData(char); 13 | char popData(); 14 | 15 | public: 16 | Stack() { 17 | top=-1; 18 | length=0; 19 | count=0; 20 | } 21 | void getString(); 22 | void checkPalindrome(); 23 | void extractString(); 24 | void displayReverse(); 25 | }; 26 | 27 | int main() { 28 | Stack obj; 29 | obj.getString(); 30 | obj.extractString(); 31 | cout<<"\n String extracted after removing punctuations and symbols"; 32 | cout<<"\n String converted to lower case"; 33 | cout<<"\n Reverse of entered string: "; 34 | obj.displayReverse(); 35 | obj.checkPalindrome(); 36 | return 0; 37 | } 38 | 39 | void Stack::getString() { 40 | cout<<"\n Enter a String: "; 41 | cin.getline(str,MAX); 42 | 43 | length=strlen(str); 44 | } 45 | 46 | void Stack::extractString() { 47 | char temp[MAX]; 48 | int i,j; 49 | for(i=0; i=0; i--) 81 | cout< 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | int r, c = 1; 17 | 18 | cout << "Enter number of rows: "; 19 | cin >> r; 20 | 21 | for(int i = 0; i < r; i++) 22 | { 23 | for(int space = 1; space <= r-i; space++) 24 | cout <<" "; 25 | 26 | for(int j = 0; j <= i; j++) 27 | { 28 | if (j == 0 || i == 0) 29 | c = 1; 30 | else 31 | c = c*(i-j+1)/j; 32 | 33 | cout << c << " "; 34 | } 35 | cout << endl; 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /C++/pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | 22 | 23 | 24 | /* * 25 | * * 26 | * * * 27 | * * * * 28 | * * * * * */ 29 | -------------------------------------------------------------------------------- /C++/repository.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() { 4 | char c; 5 | int cnt = 0; 6 | FILE *fptr; 7 | 8 | fptr = fopen("text.txt", "w"); 9 | if (fptr == NULL) { 10 | printf("File can't be created\a"); 11 | getch(); 12 | exit(0); 13 | } 14 | printf("Enter some text and press enter key:\n"); 15 | while ((c = getche()) != '\r') { 16 | fputc(c, fptr); 17 | } 18 | fclose(fptr); 19 | fptr = fopen("text.txt", "r"); 20 | printf("\nContents of the File is:"); 21 | while ((c = fgetc(fptr)) != EOF) { 22 | cnt++; 23 | printf("%c", c); 24 | } 25 | fclose(fptr); 26 | printf("\nThe number of characters present in file is: %d", cnt); 27 | getch(); 28 | } 29 | -------------------------------------------------------------------------------- /C++/shell_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void Swap(int &a, int &b) { 4 | int temp; 5 | temp = a; 6 | a = b; 7 | b = temp; 8 | } 9 | void display(int *array, int size) { 10 | for(int i = 0; i 0; gap = gap / 2) { 17 | for(j = gap; j=0; k -= gap) { 19 | if(arr[k+gap] >= arr[k]) 20 | break; 21 | else 22 | Swap(arr[k+gap], arr[k]); 23 | } 24 | } 25 | } 26 | } 27 | int main() { 28 | int n; 29 | cout << "Enter the number of elements: "; 30 | cin >> n; 31 | int arr[n]; 32 | cout << "Enter elements:" << endl; 33 | for(int i = 0; i> arr[i]; 35 | } 36 | cout << "Orignal Array: "; 37 | display(arr, n); 38 | shellSort(arr, n); 39 | cout << "Sorting Array: "; 40 | display(arr, n); 41 | } 42 | -------------------------------------------------------------------------------- /C++/shellsort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void swapping(int &a, int &b) { //swap the content of a and b 4 | int temp; 5 | temp = a; 6 | a = b; 7 | b = temp; 8 | } 9 | void display(int *array, int size) { 10 | for(int i = 0; i 0; gap = gap / 2) { //initially gap = n/2, 17 | decreasing by gap /2 18 | for(j = gap; j=0; k -= gap) { 20 | if(arr[k+gap] >= arr[k]) 21 | break; 22 | else 23 | swapping(arr[k+gap], arr[k]); 24 | } 25 | } 26 | } 27 | } 28 | int main() { 29 | int n; 30 | cout << "Enter the number of elements: "; 31 | cin >> n; 32 | int arr[n]; //create an array with given number of elements 33 | cout << "Enter elements:" << endl; 34 | for(int i = 0; i> arr[i]; 36 | } 37 | cout << "Array before Sorting: "; 38 | display(arr, n); 39 | shellSort(arr, n); 40 | cout << "Array after Sorting: "; 41 | display(arr, n); 42 | } 43 | -------------------------------------------------------------------------------- /C++/towerOfHanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void towerOfHanoi(int n, char from_rod, 5 | char to_rod, char aux_rod) 6 | { 7 | if (n == 1) 8 | { 9 | cout << "Move disk 1 from rod " << from_rod << 10 | " to rod " << to_rod< 4 | 5 | #define MAX 5 6 | 7 | void AcceptArray(int *Arr1 , int n) 8 | { 9 | int cnt ; 10 | int x ; 11 | int *ptr = Arr1 ; 12 | printf("Accept an array"); 13 | for(cnt=0;cnt0 ; cnt--) 30 | { 31 | printf("cnt=%d ptr =%x ptr -1 %x \n ",cnt ,ptr ,(ptr-1)); 32 | x=*(ptr-1); 33 | *ptr=x; 34 | // printf("%d",*ptr); 35 | ptr--; 36 | } 37 | *ptr=-1; 38 | 39 | 40 | } 41 | void main(void) 42 | { 43 | int Arr[MAX]; 44 | int cnt ; 45 | int x ; 46 | 47 | printf("in main %x ",&Arr[0]); 48 | printf("\n enter your array \n"); 49 | AcceptArray(Arr,MAX); 50 | printf("\n you have entered \n "); 51 | DisplayArray(Arr,MAX ); 52 | 53 | 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /C/Array_in_C.c: -------------------------------------------------------------------------------- 1 | # Tried an array of Characters in a string example with my name. 2 | 3 | #include 4 | int main() 5 | { 6 | char str[100]="Shyamashrita"; 7 | int i = 0; 8 | 9 | printf("\nThe String: %s\n\n",str); 10 | 11 | while (str[i] != '\0') 12 | { 13 | printf("The Character at %d Index Position = %c \n", i+1, str[i]); 14 | i++; 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C/Eval_Postfix.c: -------------------------------------------------------------------------------- 1 | /*EVALUATING A POSTFIX EXPRESSION 2 | Author:Debargha Mukherjee 3 | GitHub: https://github.com/Debargha-arch 4 | */ 5 | #include 6 | #include 7 | #include 8 | #define max 50 9 | 10 | //A Stack ADT created for maintaining the expression 11 | struct stack 12 | { 13 | char s[max]; 14 | int top; 15 | }; 16 | 17 | 18 | //Function for postfix evaluation 19 | int eval_postfix(struct stack *p,char exp[max]) 20 | { 21 | int i; 22 | int n=strlen(exp); 23 | exp[n]=')'; 24 | for(i=0;exp[i]!=')';i++) 25 | { 26 | if(isdigit(exp[i])) 27 | push(p,exp[i]-'0'); 28 | else 29 | { 30 | int op1=pop(p); 31 | int op2=pop(p); 32 | switch(exp[i]) 33 | { 34 | case '+': 35 | push(p,op2+op1); 36 | break; 37 | case '-': 38 | push(p,op2-op1); 39 | break; 40 | case '*': 41 | push(p,op2*op1); 42 | break; 43 | case '/': 44 | push(p,op2/op1); 45 | break; 46 | } 47 | } 48 | } 49 | return pop(p); 50 | } 51 | 52 | 53 | //Function to push element into a stack 54 | void push(struct stack *p,int n) 55 | { 56 | if((*p).top==max-1) 57 | { 58 | printf("\nOVERFLOW\n"); 59 | } 60 | else 61 | { 62 | ((*p).top)++; 63 | (*p).s[(*p).top]=n; 64 | } 65 | } 66 | 67 | 68 | //Function to pop/remove element from a stack 69 | int pop(struct stack *p) 70 | { 71 | int n; 72 | if((*p).top==-1) 73 | { 74 | printf("\nUNDERFLOW\n"); 75 | return 0; 76 | } 77 | else 78 | { 79 | n=(*p).s[(*p).top]; 80 | ((*p).top)--; 81 | return n; 82 | } 83 | } 84 | 85 | int main() 86 | { 87 | struct stack p; 88 | p.top=-1; 89 | char exp[max]; 90 | printf("Enter Postfix Expression:\n"); 91 | gets(exp); 92 | int a=eval_postfix(&p,exp); //the poped element returned is stored in integer variable a 93 | printf("\nThe Evaluated Expression: %d",a); 94 | } 95 | -------------------------------------------------------------------------------- /C/LinearSearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int array[100], search, c, n; 5 | 6 | printf("Enter number of elements in array\n"); 7 | scanf("%d", &n); 8 | 9 | printf("Enter %d integer(s)\n", n); 10 | 11 | for (c = 0; c < n; c++) 12 | scanf("%d", &array[c]); 13 | 14 | printf("Enter a number to search\n"); 15 | scanf("%d", &search); 16 | 17 | for (c = 0; c < n; c++) 18 | { 19 | if (array[c] == search) 20 | { 21 | printf("%d is present at location %d.\n", search, c+1); 22 | break; 23 | } 24 | } 25 | if (c == n) 26 | printf("%d isn't present in the array.\n", search); 27 | 28 | return 0; 29 | } 30 | 31 | Sumanth Javvaji 32 | Github - https://github.com/JavvajiSumanth 33 | Location - India 34 | -------------------------------------------------------------------------------- /C/Priority scheduling/README.md: -------------------------------------------------------------------------------- 1 | # Priority based Scheduling (Non - Preemptive) in C 2 | 3 | TIME COMPLEXITY : O(n^2) 4 | 5 | SPACE COMPLEXITY : O(n) 6 | 7 | Description : To calculate the average waiting time using the priority queue algorithm. First sort 8 | the processes in ascending order of their priority time and the process having the shortest priority 9 | time is executed first and so on. Waiting time of the first process is kept zero and the waiting time of the second process is the burst time of the first process and the waiting time of the third process is the sum of the burst time of the first and the second process and so on. After calculating all the waiting times the average waiting time is calculated as the average of all the waiting times. -------------------------------------------------------------------------------- /C/Queue using Arrays.c: -------------------------------------------------------------------------------- 1 | /* 2 | * C Program to Implement a Queue using an Array 3 | */ 4 | #include 5 | 6 | #define MAX 50 7 | 8 | void insert(); 9 | void delete(); 10 | void display(); 11 | int queue_array[MAX]; 12 | int rear = - 1; 13 | int front = - 1; 14 | main() 15 | { 16 | int choice; 17 | while (1) 18 | { 19 | printf("1.Insert element to queue \n"); 20 | printf("2.Delete element from queue \n"); 21 | printf("3.Display all elements of queue \n"); 22 | printf("4.Quit \n"); 23 | printf("Enter your choice : "); 24 | scanf("%d", &choice); 25 | switch (choice) 26 | { 27 | case 1: 28 | insert(); 29 | break; 30 | case 2: 31 | delete(); 32 | break; 33 | case 3: 34 | display(); 35 | break; 36 | case 4: 37 | exit(1); 38 | default: 39 | printf("Wrong choice \n"); 40 | } /* End of switch */ 41 | } /* End of while */ 42 | } /* End of main() */ 43 | 44 | void insert() 45 | { 46 | int add_item; 47 | if (rear == MAX - 1) 48 | printf("Queue Overflow \n"); 49 | else 50 | { 51 | if (front == - 1) 52 | /*If queue is initially empty */ 53 | front = 0; 54 | printf("Inset the element in queue : "); 55 | scanf("%d", &add_item); 56 | rear = rear + 1; 57 | queue_array[rear] = add_item; 58 | } 59 | } /* End of insert() */ 60 | 61 | void delete() 62 | { 63 | if (front == - 1 || front > rear) 64 | { 65 | printf("Queue Underflow \n"); 66 | return ; 67 | } 68 | else 69 | { 70 | printf("Element deleted from queue is : %d\n", queue_array[front]); 71 | front = front + 1; 72 | } 73 | } /* End of delete() */ 74 | 75 | void display() 76 | { 77 | int i; 78 | if (front == - 1) 79 | printf("Queue is empty \n"); 80 | else 81 | { 82 | printf("Queue is : \n"); 83 | for (i = front; i <= rear; i++) 84 | printf("%d ", queue_array[i]); 85 | printf("\n"); 86 | } 87 | } /* End of display() */ 88 | -------------------------------------------------------------------------------- /C/Queue using Linked List.c: -------------------------------------------------------------------------------- 1 | // A C program to demonstrate linked list based implementation of queue 2 | #include 3 | #include 4 | 5 | // A linked list (LL) node to store a queue entry 6 | struct QNode { 7 | int key; 8 | struct QNode* next; 9 | }; 10 | 11 | // The queue, front stores the front node of LL and rear stores the 12 | // last node of LL 13 | struct Queue { 14 | struct QNode *front, *rear; 15 | }; 16 | 17 | // A utility function to create a new linked list node. 18 | struct QNode* newNode(int k) 19 | { 20 | struct QNode* temp = (struct QNode*)malloc(sizeof(struct QNode)); 21 | temp->key = k; 22 | temp->next = NULL; 23 | return temp; 24 | } 25 | 26 | // A utility function to create an empty queue 27 | struct Queue* createQueue() 28 | { 29 | struct Queue* q = (struct Queue*)malloc(sizeof(struct Queue)); 30 | q->front = q->rear = NULL; 31 | return q; 32 | } 33 | 34 | // The function to add a key k to q 35 | void enQueue(struct Queue* q, int k) 36 | { 37 | // Create a new LL node 38 | struct QNode* temp = newNode(k); 39 | 40 | // If queue is empty, then new node is front and rear both 41 | if (q->rear == NULL) { 42 | q->front = q->rear = temp; 43 | return; 44 | } 45 | 46 | // Add the new node at the end of queue and change rear 47 | q->rear->next = temp; 48 | q->rear = temp; 49 | } 50 | 51 | // Function to remove a key from given queue q 52 | void deQueue(struct Queue* q) 53 | { 54 | // If queue is empty, return NULL. 55 | if (q->front == NULL) 56 | return; 57 | 58 | // Store previous front and move front one node ahead 59 | struct QNode* temp = q->front; 60 | 61 | q->front = q->front->next; 62 | 63 | // If front becomes NULL, then change rear also as NULL 64 | if (q->front == NULL) 65 | q->rear = NULL; 66 | 67 | free(temp); 68 | } 69 | 70 | // Driver Program to test anove functions 71 | int main() 72 | { 73 | struct Queue* q = createQueue(); 74 | enQueue(q, 10); 75 | enQueue(q, 20); 76 | deQueue(q); 77 | deQueue(q); 78 | enQueue(q, 30); 79 | enQueue(q, 40); 80 | enQueue(q, 50); 81 | deQueue(q); 82 | printf("Queue Front : %d \n", q->front->key); 83 | printf("Queue Rear : %d", q->rear->key); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /C/README.md: -------------------------------------------------------------------------------- 1 | # Scripts and algorithms written in C 2 | - Create a separate folder for each script 3 | - Happy Hactober 2020 :) 4 | -------------------------------------------------------------------------------- /C/Remove-Duplicates-from-Sorted-Array.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length. 4 | Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | #define ll long long 19 | #define len length() 20 | #define vi vector 21 | #define vl vector 22 | 23 | #define fr(i,n) for(ll i=0;ij?i:j; 26 | } 27 | 28 | 29 | int removeDuplicates(vector& nums) { 30 | int ind=1; 31 | int n=nums.size(); 32 | if (n<=1) return n; 33 | for(int i=0;i>n; 50 | vector v(n,0); 51 | fr(i,n){ 52 | int x; cin>>x; 53 | v[i]=x; 54 | } 55 | 56 | sort(v.begin(),v.end()); 57 | removeDuplicates(v); 58 | for(int u =0;u 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | #define ll long long 19 | #define len length() 20 | #define vi vector 21 | #define vl vector 22 | 23 | #define fr(i,n) for(ll i=0;ij?i:j; 26 | } 27 | 28 | 29 | int main(){ 30 | 31 | int t; 32 | //t=1; 33 | cin>>t; 34 | while(t--){ 35 | 36 | ll n,x,m; cin>>n>>x>>m; 37 | ll mx=x, mn=x; 38 | 39 | while(m--){ 40 | ll l,r; 41 | cin>>l>>r; 42 | 43 | if(mn>=l&&mn<=r || mx>=l&&mx<=r){ 44 | 45 | mn=min(mn,l); mx=max(mx,r); 46 | 47 | } 48 | 49 | 50 | } 51 | ll ans=(mx-mn)+1; 52 | cout< 2 | #include 3 | #include 4 | 5 | int main(){ 6 | char str[] = "string-what-you-want"; 7 | char *token; 8 | printf("The String is : \n%s",str); 9 | token = strtok(str,"-"); 10 | 11 | while(token != NULL){ 12 | printf("Token : %s\n",token); 13 | token = strtok(NULL,"-"); 14 | } 15 | return 0; 16 | 17 | 18 | } 19 | 20 | 21 | // OUTPUT : 22 | // string-what-you-want 23 | // string 24 | // what 25 | // you 26 | // want 27 | -------------------------------------------------------------------------------- /C/Sum.c: -------------------------------------------------------------------------------- 1 | /*To calculate the sum of first n numbers*/ 2 | #include 3 | int main() { 4 | int n, i, sum = 0; 5 | 6 | printf("Enter a positive integer: "); 7 | scanf("%d", &n); 8 | 9 | for (i = 1; i <= n; ++i) { 10 | sum += i; 11 | } 12 | 13 | printf("Sum = %d", sum); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /C/Two-Arrays-And-Swaps.c: -------------------------------------------------------------------------------- 1 | /* 2 | You are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k. 3 | In one move, you can choose two indices i and j (1≤i,j≤n) and swap ai and bj (i.e. ai becomes bj and vice versa). Note that i and j can be equal or different (in particular, swap a2 with b2 or swap a3 and b9 both are acceptable moves). 4 | Your task is to find the maximum possible sum you can obtain in the array a if you can do no more than (i.e. at most) k such moves (swaps). 5 | You have to answer t independent test cases. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | #define ll long long 20 | #define len length() 21 | #define vi vector 22 | #define vl vector 23 | 24 | #define fr(i,n) for(ll i=0;i>t; 29 | 30 | while(t--){ 31 | ll n,k; cin>>n>>k; 32 | 33 | vl a(n,0),b(n,0); 34 | fr(i,n){ 35 | cin>>a[i]; 36 | } 37 | 38 | fr(i,n){ 39 | cin>>b[i]; 40 | } 41 | 42 | sort(a.begin(),a.end()); 43 | sort(b.begin(),b.end(),greater()); 44 | ll s=0,ans=0; 45 | ll j=0; 46 | fr(i,n){ 47 | if(s 2 | 3 | int binarySearch(int a[],int n,int x) // n=size of array , x= element to be searched in the array 4 | { 5 | int mid, l=0, r=n-1; 6 | while(l<=r) 7 | { 8 | mid = l + (r-l)/2; 9 | if(a[mid] == x) 10 | return mid; // return index at which the element is present 11 | if(a[mid]>x) 12 | r=mid-1; 13 | else 14 | l=mid+1; 15 | } 16 | return -1; // return -1 if the element is not present in the array 17 | } 18 | 19 | int main() 20 | { 21 | int n,i,x; // n= size of array, x= element to be searched in the array 22 | printf("Enter the size of the array: "); 23 | scanf("%d",&n); 24 | int a[n]; 25 | 26 | printf("\nEnter the elements of the array: "); 27 | for(i=0;i 8 | #include 9 | #include 10 | #define max 20 11 | 12 | //Stack ADT created to store the brackets 13 | struct stack 14 | { 15 | char stk[max]; 16 | int top; 17 | }; 18 | 19 | struct stack s; 20 | 21 | //Function to push element into a stack 22 | void push(char item) 23 | { 24 | if(s.top==(max-1)) 25 | { 26 | printf("OVERFLOW\n"); 27 | } 28 | else 29 | { 30 | s.top++; 31 | s.stk[s.top]=item; 32 | } 33 | } 34 | 35 | //Function to pop out element from a stack 36 | void pop() 37 | { 38 | if (s.top==-1) 39 | { 40 | printf("UNDERFLOW\n"); 41 | } 42 | else 43 | { 44 | s.top--; 45 | } 46 | } 47 | 48 | //Function for checking the balanced condition for brackets. 49 | void balance(char exp[max]) 50 | { 51 | int i=0; 52 | for(i=0;i 2 | int main(){ 3 | int first,second,third; 4 | printf("enter 3 digit number\n"); 5 | scanf("%1d%1d%1d",&first,&second,&third); 6 | switch(first%10) 7 | { 8 | case 1: printf(" One hundred"); 9 | break; 10 | case 2: printf(" Two hundred"); 11 | break; 12 | case 3: printf(" Three hundred"); 13 | break; 14 | case 4: printf(" Four hundred"); 15 | break; 16 | case 5: printf(" Five hundred"); 17 | break; 18 | case 6: printf(" Six hundred"); 19 | break; 20 | case 7: printf(" Seven hundred"); 21 | break; 22 | case 8: printf(" Eight hundred"); 23 | break; 24 | case 9: printf(" Nine hundred"); 25 | break; 26 | } 27 | switch(second%10){ 28 | case 0:break; 29 | 30 | case 1: switch(third%10){ 31 | printf("and"); 32 | case 0: printf(" ten");break; 33 | case 1: printf(" eleven");break; 34 | case 2: printf(" twelve"); 35 | break; 36 | case 3: printf("thirteen"); 37 | break; 38 | case 4: printf(" fourteen"); 39 | break; 40 | case 5: printf(" fifteen"); 41 | break; 42 | case 6: printf(" sixteen"); 43 | break; 44 | case 7: printf(" seventeen"); 45 | break; 46 | case 8: printf(" eighteen"); 47 | break; 48 | case 9: printf(" nineteen"); 49 | break; 50 | 51 | } 52 | return 0; 53 | 54 | break; 55 | case 2: printf(" tewnty"); 56 | break; 57 | case 3: printf(" thirty"); 58 | break; 59 | case 4: printf(" fourty"); 60 | break; 61 | case 5: printf(" fifty"); 62 | break; 63 | case 6: printf(" sixty"); 64 | break; 65 | case 7: printf(" seventy"); 66 | break; 67 | case 8: printf(" eighty"); 68 | break; 69 | case 9: printf(" ninety"); 70 | break; 71 | } 72 | switch(third%10){ 73 | case 0:break; 74 | printf("and"); 75 | case 1: printf(" one"); 76 | break; 77 | case 2: printf(" two"); 78 | break; 79 | case 3: printf(" three"); 80 | break; 81 | case 4: printf(" four"); 82 | break; 83 | case 5: printf(" five"); 84 | break; 85 | case 6: printf(" six"); 86 | break; 87 | case 7: printf(" seven"); 88 | break; 89 | case 8: printf(" eight"); 90 | break; 91 | case 9: printf(" nine"); 92 | break; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /C/copyarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr1[40],n,i,arr2[40]; 5 | 6 | printf("How many number :"); 7 | scanf("%d",&n); 8 | 9 | // scan array_1 Elements; 10 | for (i=0;i 2 | int max(int arr[],int n) 3 | { 4 | int maximum=arr[0]; 5 | for(int i=1;imaximum) 8 | maximum=arr[i]; 9 | } 10 | return maximum; 11 | } 12 | void countsort(int arr[],int n,int place) 13 | { 14 | int temp[n]; 15 | int count[10]; 16 | for(int i=0;i<10;i++) 17 | count[i]=0; 18 | for(int i=0;i=0;i--) 23 | temp[--count [ (arr[i] / place) % 10]] = arr[i]; 24 | for(int i=0;i 0 ; place = place * 10 ) 32 | countsort(arr,n,place); 33 | } 34 | int main() 35 | { 36 | int n; 37 | printf("ENTER THE NUMBERS WHICH U WANT TO SORT : "); 38 | scanf("%d",&n); 39 | int arr[n]; 40 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int num1, num2; 9 | cout<<"Enter first number:"; 10 | cin>>num1; 11 | cout<<"Enter second number:"; 12 | cin>>num2; 13 | if(num1>num2) 14 | { 15 | cout<<"First number "<length && jlength) 21 | { 22 | if(arr1->A[i]A[j]) 23 | arr3->A[k++]=arr1->A[i++]; 24 | else 25 | arr3->A[k++]=arr2->A[j++]; 26 | } 27 | for(;ilength;i++) 28 | arr3->A[k++]=arr1->A[i]; 29 | for(;jlength;j++) 30 | arr3->A[k++]=arr2->A[j]; 31 | arr3->length=arr1->length+arr2->length; 32 | arr3->size=10; 33 | return arr3; 34 | } 35 | int main() 36 | { 37 | struct Array arr1={{2,9,21,28,35},10,5}; 38 | struct Array arr1={{2,3,16,18,28},10,5}; 39 | struct Array *arr3; 40 | arr3=Merge(&arr1,&arr2); 41 | Display(*arr3); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /C/name.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char firstname[20], lastname[20]; 5 | int bir_year; 6 | printf("Input your firstname: "); 7 | scanf("%s", firstname); 8 | printf("Input your lastname: "); 9 | scanf("%s", lastname); 10 | printf("Input your year of birth: "); 11 | scanf("%d", &bir_year); 12 | printf("%s %s %d\n", firstname, lastname, bir_year); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /C/revering_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Array 4 | { 5 | int A[10]; 6 | int size; 7 | int length; 8 | }; 9 | void Display(struct Array arr) 10 | { 11 | int i; 12 | printf("\nElements are\n"); 13 | for(i=0;ilength*sizeof(int)); 27 | for(i=arr->length-1,j=0;i>=0;i--,j++) 28 | B[j]=arr->A[i]; 29 | for(i=0;ilength;i++) 30 | arr->A[i]=B[i]; 31 | } 32 | void Reverse2(struct Array *arr) 33 | { 34 | int i,j; 35 | for(i=0,j=arr->length-1;iA[i],&arr->A[j]); 38 | } 39 | } 40 | int main() 41 | { 42 | struct Array arr1={{2,3,9,16,18,21,28,32,35},10,9}; 43 | Reverse(&arr1); 44 | Display(arr1); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C/reverse_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char str[100]; 6 | char rev[100]; 7 | char *sptr = str; //base address of string 8 | char *rptr = rev; //base address of reverse 9 | 10 | int i = -1; 11 | 12 | printf("Enter a String: \n"); 13 | scanf("%s", str); 14 | 15 | // store the ending address of str in sptr 16 | while (*sptr) 17 | { 18 | sptr++; 19 | i++; 20 | } 21 | 22 | // store the string str in rev in reverse order 23 | while (i >= 0) 24 | { 25 | sptr--; 26 | *rptr = *sptr; 27 | rptr++; 28 | i--; 29 | } 30 | 31 | *rptr = '\0'; 32 | rptr = rev; // restoring the base address of the reverse string 33 | 34 | // storing the reverse string in the original string 35 | while (*rptr) 36 | { 37 | *sptr = *rptr; 38 | sptr++; 39 | rptr++; 40 | } 41 | 42 | // priting the reverse string 43 | printf("Reverse of the string is :\n%s", str); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /C/scan_ports.c: -------------------------------------------------------------------------------- 1 | /* 2 | TCP Connect portscanner with winsock 3 | */ 4 | 5 | #include 6 | #include 7 | #pragma comment(lib, "ws2_32.lib"); //To link the winsock library 8 | 9 | int main(int argc, char **argv) 10 | { 11 | WSADATA firstsock; 12 | SOCKET s; 13 | struct hostent *host; 14 | int err,i, startport , endport; 15 | struct sockaddr_in sa; //this stores the destination address 16 | char hostname[100]; 17 | 18 | strncpy((char *)&sa,"",sizeof sa); 19 | sa.sin_family = AF_INET; //this line must be like this coz internet 20 | 21 | //Initialise winsock 22 | if (WSAStartup(MAKEWORD(2,0),&firstsock) != 0) //CHECKS FOR WINSOCK VERSION 2.0 23 | { 24 | fprintf(stderr,"WSAStartup() failed"); //print formatted data specify stream and options 25 | exit(EXIT_FAILURE); //or exit(1); 26 | } 27 | 28 | printf("Enter hostname or ip to scan : "); 29 | gets(hostname); 30 | 31 | printf("Enter starting port : "); 32 | scanf("%d" , &startport); 33 | 34 | printf("Enter ending port : "); 35 | scanf("%d" , &endport); 36 | 37 | if(isdigit(hostname[0])) 38 | { 39 | printf("Doing inet_addr..."); 40 | sa.sin_addr.s_addr = inet_addr(hostname); //get ip into s_addr 41 | printf("Done\n"); 42 | } 43 | else if( (host=gethostbyname(hostname)) != 0) 44 | { 45 | printf("Doing gethostbyname()..."); 46 | strncpy((char *)&sa.sin_addr , (char *)host->h_addr_list[0] , sizeof sa.sin_addr); 47 | printf("Done\n"); 48 | } 49 | else 50 | { 51 | printf("Error resolving hostname"); 52 | exit(EXIT_FAILURE); 53 | } 54 | 55 | 56 | //Start the portscan loop 57 | printf("Starting the scan loop...\n"); 58 | for(i = startport ; i<= endport ; i++) 59 | { 60 | 61 | s = socket(AF_INET , SOCK_STREAM , 0); //make net a valid socket handle 62 | if(s < 0) //if not a socket 63 | { 64 | perror("\nSocket creation failed"); // perror function prints an error message to stderr 65 | exit(EXIT_FAILURE); //or exit(0); 66 | } 67 | 68 | sa.sin_port = htons(i); 69 | //connect to the server with that socket 70 | err = connect(s , (struct sockaddr *)&sa , sizeof sa); 71 | 72 | if(err == SOCKET_ERROR) //connection not accepted 73 | { 74 | printf("%s %-5d Winsock Error Code : %d\n" , hostname , i , WSAGetLastError()); 75 | fflush(stdout); 76 | } 77 | else //connection accepted 78 | { 79 | printf("%s %-5d accepted \n" , hostname , i); 80 | if( shutdown( s ,SD_BOTH ) == SOCKET_ERROR ) 81 | { 82 | perror("\nshutdown");// perror function prints an error message to stderr 83 | exit(EXIT_FAILURE); 84 | } 85 | } 86 | closesocket(s); //closes the net socket 87 | } 88 | 89 | fflush(stdout); //clears the contents of a buffer or flushes a stream 90 | return(0); 91 | } -------------------------------------------------------------------------------- /C/selection_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 100 //pre-defining size to be of 100 4 | 5 | // This program implements the selection sort algorithm 6 | // The size of the array is set to 100 7 | 8 | int n; //variable that is used to input the number of elements the user need to enter 9 | int list[SIZE]; //creating a variable named list with pre-defined size 100 that would be our array to store the input elements 10 | int i, j; 11 | int minimum_position; 12 | int temp; //temporary variable that would help us in swapping elements 13 | 14 | int main() 15 | { 16 | printf ("How many elements will be in this array? "); 17 | scanf ("%d", &n); 18 | 19 | printf ("Please type in one integer array element per line:\n"); 20 | for (i = 0; i < n; i++) 21 | { 22 | scanf ("%d", &list[i]); //this statement helps to take in input from the user in one line per element 23 | } 24 | 25 | for (i = 0; i < n - 1; i++) 26 | { 27 | minimum_position = i; 28 | for (j = i + 1; j < n; j++) 29 | { 30 | if (list[j] < list[min_pos]) 31 | { 32 | min_pos = j; 33 | } 34 | } 35 | temp = list[i]; //we swap the elements using temp variable---Step1 36 | list[i] = list[minimum_position]; //Step2 37 | list[minimum_position] = temp; //Final Step of swapping 38 | } 39 | 40 | printf ("\n"); //this provides a one-line gap between the input and output while being displayed on the compiler/ide output 41 | for (i = 0; i < n; i++) 42 | { 43 | printf ("%d\n", list[i]); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C/selection_sort/README.md: -------------------------------------------------------------------------------- 1 | # Selection sort in C 2 | The C implementation of the selection sort algorithm 3 | -------------------------------------------------------------------------------- /C/selection_sort/selection_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 100 4 | 5 | // This program implements the selection sort algorithm 6 | // The size of the array is set to 100 7 | 8 | int n; 9 | int list[SIZE]; 10 | int i, j; 11 | int minimum_position; 12 | int temp; 13 | 14 | int main() 15 | { 16 | printf ("How many elements will be in this array? "); 17 | scanf ("%d", &n); 18 | 19 | printf ("Please type in one integer array element per line:\n"); 20 | for (i = 0; i < n; i++) 21 | { 22 | scanf ("%d", &list[i]); 23 | } 24 | 25 | for (i = 0; i < n - 1; i++) 26 | { 27 | minimum_position = i; 28 | for (j = i + 1; j < n; j++) 29 | { 30 | if (list[j] < list[min_pos]) 31 | { 32 | min_pos = j; 33 | } 34 | } 35 | temp = list[i]; 36 | list[i] = list[minimum_position]; 37 | list[minimum_position] = temp; 38 | } 39 | 40 | printf ("\n"); 41 | for (i = 0; i < n; i++) 42 | { 43 | printf ("%d\n", list[i]); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C/triangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int i,j,k,l,n; 5 | system("cls"); 6 | printf("enter the range="); 7 | scanf("%d",&n); 8 | for(i=1;i<=n;i++) 9 | { 10 | for(j=1;j<=n-i;j++) 11 | { 12 | printf(" "); 13 | } 14 | for(k=1;k<=i;k++) 15 | { 16 | printf("%d",k); 17 | } 18 | for(l=i-1;l>=1;l--) 19 | { 20 | printf("%d",l); 21 | } 22 | printf("\n"); 23 | } 24 | return 0; 25 | } 26 | 27 | //Like alphabet triangle, we can write the c program to print the number triangle. The number triangle can be printed in different ways. 28 | 29 | //Let's see the c example to print number triangle. 30 | 31 | //enter the range=10 32 | // 1 33 | // 121 34 | // 12321 35 | // 1234321 36 | // 123454321 37 | // 12345654321 38 | // 1234567654321 39 | // 123456787654321 40 | // 12345678987654321 41 | //12345678910987654321 42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guidelines 2 | 3 | * Make sure you create a different branch for all your pull requsts. 4 | 5 | * Scripts to be added in there respective folder with proper doumentaion. 6 | 7 | * Please create a valid pull request by following all contribution guidelines mentioned by hacktoberfest organization 8 | 9 | * You can find guidelines https://hacktoberfest.digitalocean.com/details 10 | 11 | * Please don’t spam the repository 12 | 13 | * Create a new folder to your code in the particular base folder and create a PR 14 | 15 | * Star the repositary :sweat_smile: 16 | 17 | ### ALL THE BEST :heart: 18 | -------------------------------------------------------------------------------- /Java script/Data Structures/CircularQueue.js: -------------------------------------------------------------------------------- 1 | class CircularQueue { 2 | constructor(size) { 3 | 4 | this.queue = []; 5 | this.read = 0; 6 | this.write = 0; 7 | this.max = size - 1; 8 | this.count=0; 9 | 10 | while (size > 0) { 11 | this.queue.push(null); 12 | size--; 13 | } 14 | } 15 | checkEmpty(){ 16 | var count=0; 17 | for(let i=0;i<=this.max;i++){ 18 | if(this.queue[i]==null){ 19 | count++; 20 | } 21 | } 22 | if(count==this.max+1){ 23 | return true; 24 | } 25 | return false; 26 | } 27 | checkFull(){ 28 | var count=0; 29 | for(let i=0;i<=this.max;i++){ 30 | if(this.queue[i]==null){ 31 | count++; 32 | } 33 | } 34 | if(count>0) { 35 | return false; 36 | } 37 | return true; 38 | } 39 | 40 | print() { 41 | return this.queue; 42 | } 43 | 44 | enqueue(item) { 45 | if(!this.checkFull()){ 46 | this.queue[this.write]=item; 47 | this.write=(this.write+1)%(this.max+1); 48 | } 49 | } 50 | 51 | 52 | dequeue() { 53 | if(!this.checkEmpty()){ 54 | let val=this.queue[this.read]; 55 | this.queue[this.read]=null; 56 | this.read=(this.read+1)%(this.max+1); 57 | return val; 58 | } 59 | else return null; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Java script/Data Structures/Linked_list.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Java script/Data Structures/Queues.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Java script/Data Structures/Stacks.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Java script/Data Structures/array.js: -------------------------------------------------------------------------------- 1 | const names =['max','Manu','Julie','Max']; 2 | console.log(names[1]); 3 | console.log(names.length); 4 | 5 | // printing all values of array 6 | for(const el of names){ 7 | console.log(el); 8 | } 9 | 10 | // push value in array 11 | names.push('Julie'); 12 | console.log(names.length); 13 | 14 | const julieIndex = names.findIndex(el => el === 'Julie'); 15 | names.splice(2,1); 16 | console.log(names) 17 | -------------------------------------------------------------------------------- /Java script/Data Structures/arraybidimensional.js: -------------------------------------------------------------------------------- 1 | var avgTempWeek = [] 2 | 3 | var avgTempWeek1 = [33, 25.2, 19, 27, 23.4, 41.6, 25] 4 | var avgTempWeek2 = [41, 29, 33, 21.2, 19.5, 17, 33.8] 5 | 6 | avgTempWeek[0] = avgTempWeek1 7 | avgTempWeek[1] = avgTempWeek2 8 | 9 | for(var i = 0; i < avgTempWeek.length; i++) { 10 | for(var j = 0; j < avgTempWeek[i].length; j++) { 11 | console.log(avgTempWeek[i][j]) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java script/Merge_sort_js/merge_sort.js: -------------------------------------------------------------------------------- 1 | // 2 | // Merge Sort Implentation (Recursion) 3 | // 4 | 5 | function mergeSort (unsortedArray) { 6 | // No need to sort the array if the array only has one element or empty 7 | if (unsortedArray.length <= 1) { 8 | return unsortedArray; 9 | } 10 | // In order to divide the array in half, we need to figure out the middle 11 | const middle = Math.floor(unsortedArray.length / 2); 12 | 13 | // This is where we will be dividing the array into left and right 14 | const left = unsortedArray.slice(0, middle); 15 | const right = unsortedArray.slice(middle); 16 | 17 | // Using recursion to combine the left and right 18 | return merge( 19 | mergeSort(left), mergeSort(right) 20 | ); 21 | } 22 | 23 | // Merge the two arrays: left and right 24 | function merge (left, right) { 25 | let resultArray = [], leftIndex = 0, rightIndex = 0; 26 | 27 | // We will concatenate values into the resultArray in order 28 | while (leftIndex < left.length && rightIndex < right.length) { 29 | if (left[leftIndex] < right[rightIndex]) { 30 | resultArray.push(left[leftIndex]); 31 | leftIndex++; // move left array cursor 32 | } else { 33 | resultArray.push(right[rightIndex]); 34 | rightIndex++; // move right array cursor 35 | } 36 | } 37 | 38 | // We need to concat to the resultArray because there will be one element left over after the while loop 39 | return resultArray 40 | .concat(left.slice(leftIndex)) 41 | .concat(right.slice(rightIndex)); 42 | } -------------------------------------------------------------------------------- /Java script/Merge_sort_js/merge_sort.md: -------------------------------------------------------------------------------- 1 | # What is Merge Sort? 2 | ### Merge sort is one of the most popular sorting algorithms today and it uses the concept of divide and conquer to sort a list of elements. Meaning, it will divide the bigger problem into smaller problems and then solve each of the small problems in order to solve the bigger problem that we started out with. 3 | -------------------------------------------------------------------------------- /Java script/Number_is_Prime/number_isPrime.js: -------------------------------------------------------------------------------- 1 | function isPrime(nr) { 2 | if (typeof nr === "number" && nr > 1) { 3 | if (nr % 2 === 0) { 4 | return nr === 2; 5 | } 6 | for (let i = 3; i ** 2 < nr; i += 2) { 7 | if (nr % i === 0) { 8 | return false; 9 | } 10 | } 11 | return true; 12 | } 13 | return false; 14 | } 15 | -------------------------------------------------------------------------------- /Java script/Number_is_Prime/number_isPrime.md: -------------------------------------------------------------------------------- 1 | ### Number is prime 2 | 3 | This algorithm checks if the given number is a prime number 4 | -------------------------------------------------------------------------------- /Java script/README.md: -------------------------------------------------------------------------------- 1 | # HACTOBERFEST2020 2 | Repository for hacktoberfest 2020 3 | -------------------------------------------------------------------------------- /Java script/Recursive Palindrome/recursive-palindrome.js: -------------------------------------------------------------------------------- 1 | function recursivePalindrome(str) { 2 | if (typeof str === "string" || typeof str === "number") { 3 | str = str + ""; 4 | 5 | if (str.length <= 1) { 6 | return true; 7 | } 8 | 9 | if (str[0] === str[str.length - 1]) { 10 | return recursivePalindrome(str.substr(1, str.length - 2)); 11 | } 12 | } 13 | return false; 14 | } 15 | -------------------------------------------------------------------------------- /Java script/Recursive Palindrome/recursive_palindrome.md: -------------------------------------------------------------------------------- 1 | ### What is a palindrome? 2 | 3 | A palindrome is a word that is spelled the same forward and backward. For example, rotor is a palindrome, but motor is not. 4 | 5 | ### What is Recursion? 6 | 7 | The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function. 8 | -------------------------------------------------------------------------------- /Java script/Second-Largest-Element-In-Array/second_largest_element_in_array.js: -------------------------------------------------------------------------------- 1 | function getSecondLargest(nums) { 2 | let MAX = Number.MIN_VALUE; 3 | let MAX_2 = Number.MIN_VALUE; 4 | 5 | for (let val of nums) { 6 | if (val > MAX) { 7 | MAX_2 = MAX; 8 | MAX = val; 9 | } else if (val > MAX_2 && val !== MAX) MAX_2 = val; 10 | } 11 | 12 | return MAX_2; 13 | } 14 | 15 | console.log(getSecondLargest([5, 3, 6, 6, 2])); // should return 5 16 | -------------------------------------------------------------------------------- /Java script/String/FirstCharacterUpperCase.js: -------------------------------------------------------------------------------- 1 | const word = "lowercase"; 2 | 3 | const FirstCharacterUpperCase = `${word.charAt(0).toUpperCase()}${word.slice( 4 | 1 5 | )}`; 6 | 7 | console.log(FirstCharacterUpperCase); //Lowercase 8 | -------------------------------------------------------------------------------- /Java script/String/FormatMoney.js: -------------------------------------------------------------------------------- 1 | function formatNumber(num) { 2 | return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') 3 | } 4 | 5 | const num = 20000; 6 | 7 | console.log(formatNumber(num)); 8 | 9 | -------------------------------------------------------------------------------- /Java script/ThreeJs-Demo/Readme.md: -------------------------------------------------------------------------------- 1 | # TryingThreeJS 2 | The aim of the project is to create an easy to use, lightweight, 3D library with a default WebGL renderer.
3 | The library also provides Canvas 2D, SVG and CSS3D renderers in the examples. 4 | 5 | ## Library Used: 6 | [ThreeJS Library](https://github.com/mrdoob/three.js) 7 | 8 | ## Installation 9 | You can install three.js with npm and modern build tools, or get started quickly with just static hosting or a CDN. 10 | For most users, installing from npm is the best choice. Whichever you choose, be consistent and import all files from the same version of the library. 11 | Mixing files from different sources may cause duplicate code to be included, or even break the application in unexpected ways.
12 | For Installing refer the [CDN](https://threejs.org/docs/#manual/en/introduction/Installation) of ThreeJS. 13 | 14 | ## Demo: 15 | ![Output!](https://github.com/HeeteshSimon/HACTOBERFEST2020/blob/Heetesh-Contribution/Java%20script/ThreeJs-Demo/ezgif.com-video-to-gif.gif) 16 | -------------------------------------------------------------------------------- /Java script/ThreeJs-Demo/ezgif.com-video-to-gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Java script/ThreeJs-Demo/ezgif.com-video-to-gif.gif -------------------------------------------------------------------------------- /Java script/ThreeJs-Demo/threejs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ThreeJS 7 | 8 | 9 |
10 | 11 | 64 | 65 | -------------------------------------------------------------------------------- /Java script/calculator.js: -------------------------------------------------------------------------------- 1 | var app=angular.module('calculator', []) 2 | app.controller('count', function($scope) { 3 | $scope.result = function() { 4 | if ($scope.operation == '+') { 5 | return $scope.a + $scope.b; 6 | } 7 | if ($scope.operation == '-') { 8 | return $scope.a - $scope.b; 9 | } 10 | if ($scope.operation == '*') { 11 | return $scope.a * $scope.b; 12 | } 13 | if ($scope.operation == '/') { 14 | return $scope.a / $scope.b; 15 | } 16 | }; 17 | }); -------------------------------------------------------------------------------- /Python/Analysis on Parking dataset/parking.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/Analysis on Parking dataset/parking.xls -------------------------------------------------------------------------------- /Python/Android sudoku solver/README.md: -------------------------------------------------------------------------------- 1 | # sudoku-adb 2 | Python script to automate solving a sudoku game in android over ADB 3 | 4 | ### See it in action [here](https://www.linkedin.com/posts/sonalagr_python-sudoku-automated-activity-6710469597004488704--Oji). 5 | 6 | ## How does it work? 7 | - Extract the numbers into a 2D Matrix from the screenshot 8 | - Solve the incomplete grid using backtracking algoithm 9 | - Update the values by sending touch commands to device 10 | 11 | ### Game download [link](https://play.google.com/store/apps/details?id=com.hagstrom.henrik.sudoku) 12 | -------------------------------------------------------------------------------- /Python/Android sudoku solver/main.py: -------------------------------------------------------------------------------- 1 | # import required modules 2 | from ppadb.client import Client 3 | from PIL import Image 4 | import pytesseract 5 | import copy 6 | from sudoku import solve, print_board 7 | 8 | # connect to local adb server 9 | adb = Client() 10 | devices = adb.devices() 11 | if len(devices) == 0: 12 | print("No devices attached") 13 | quit() 14 | device = devices[0] 15 | 16 | # save a screenshot & load it using PIL 17 | result = device.screencap() 18 | with open("screen.png", "wb") as fp: 19 | fp.write(result) 20 | im = Image.open("screen.png") 21 | 22 | # starting position of the grid on screen 23 | x, y = 3, 285 24 | 25 | # width & height of single cell 26 | dx, dy = 112, 114 27 | 28 | # grid contains the incomplete sudoku (9x9 matrix) 29 | # touch is also a 9x9 matrix where each element is a tuple containing pixel coordinate 30 | grid, touch = [], [] 31 | 32 | for j in range(1,10): 33 | grid_row, t_row = [], [] 34 | xcopy = x 35 | 36 | for i in range(1,10): 37 | # crop & zoom into individual cells 38 | imcrop = im.crop((x,y,x+dx,y+dy)).crop((16,13,98,104)) 39 | 40 | t_row.append( ((2*x+dx)//2, (2*y+dy)//2) ) 41 | 42 | # every third vertical line is thicker 43 | x += 11 if i%3==0 else 7 44 | 45 | # extract the number from a cell 46 | temp = pytesseract.image_to_string(imcrop, config='--psm 10') 47 | temp = int(temp[0]) if temp[0].isnumeric() else 0 48 | 49 | grid_row.append(temp) 50 | x += dx 51 | x = xcopy 52 | 53 | # every third horizontal divider is thicker 54 | y += dy + (12 if j%3==0 else 8) 55 | 56 | grid.append(grid_row) 57 | touch.append(t_row) 58 | 59 | # solve & print the board 60 | orig_grid = copy.deepcopy(grid) 61 | solve(grid) 62 | print_board(grid) 63 | 64 | def click(i, j): 65 | device.shell(f'input touchscreen tap {touch[i][j][0]} {touch[i][j][1]}') 66 | 67 | def select(n): 68 | arr = [123, 212, 314, 410, 515, 623, 724, 839, 937] 69 | device.shell(f'input touchscreen tap {arr[n-1]} 1453') 70 | 71 | # update values on screen 72 | for i in range(len(grid)): 73 | for j in range(len(grid[0])): 74 | # only click on cells that were empty initially 75 | if (orig_grid[i][j] == 0): 76 | select(grid[i][j]) 77 | click(i, j) -------------------------------------------------------------------------------- /Python/Android sudoku solver/screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/Android sudoku solver/screen.png -------------------------------------------------------------------------------- /Python/Android sudoku solver/sudoku.py: -------------------------------------------------------------------------------- 1 | # copied from https://techwithtim.net/tutorials/python-programming/sudoku-solver-backtracking/ 2 | 3 | # board = [ 4 | # [7,8,0,4,0,0,1,2,0], 5 | # [6,0,0,0,7,5,0,0,9], 6 | # [0,0,0,6,0,1,0,7,8], 7 | # [0,0,7,0,4,0,2,6,0], 8 | # [0,0,1,0,5,0,9,3,0], 9 | # [9,0,4,0,6,0,0,0,5], 10 | # [0,7,0,3,0,0,0,1,2], 11 | # [1,2,0,0,0,7,4,0,0], 12 | # [0,4,9,2,0,6,0,0,7] 13 | # 14 | 15 | # board = [[6, 0, 0, 0, 9, 0, 0, 1, 0], [3, 9, 0, 5, 0, 2, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0, 4], [0, 0, 0, 9, 0, 5, 0, 2, 0], [0, 4, 0, 0, 2, 0, 7, 0, 3], [0, 0, 6, 0, 8, 0, 9, 4, 0], [0, 3, 0, 4, 0, 1, 0, 6, 7], [0, 5, 0, 0, 0, 0, 8, 0, 9], [0, 0, 7, 0, 0, 9, 4, 0, 1]] 16 | 17 | def solve(bo): 18 | find = find_empty(bo) 19 | if not find: 20 | return True 21 | else: 22 | row, col = find 23 | 24 | for i in range(1,10): 25 | if valid(bo, i, (row, col)): 26 | bo[row][col] = i 27 | 28 | if solve(bo): 29 | return True 30 | 31 | bo[row][col] = 0 32 | 33 | return False 34 | 35 | 36 | def valid(bo, num, pos): 37 | # Check row 38 | for i in range(len(bo[0])): 39 | if bo[pos[0]][i] == num and pos[1] != i: 40 | return False 41 | 42 | # Check column 43 | for i in range(len(bo)): 44 | if bo[i][pos[1]] == num and pos[0] != i: 45 | return False 46 | 47 | # Check box 48 | box_x = pos[1] // 3 49 | box_y = pos[0] // 3 50 | 51 | for i in range(box_y*3, box_y*3 + 3): 52 | for j in range(box_x * 3, box_x*3 + 3): 53 | if bo[i][j] == num and (i,j) != pos: 54 | return False 55 | 56 | return True 57 | 58 | 59 | def print_board(bo): 60 | for i in range(len(bo)): 61 | if i % 3 == 0 and i != 0: 62 | print("- - - - - - - - - - - - - ") 63 | 64 | for j in range(len(bo[0])): 65 | if j % 3 == 0 and j != 0: 66 | print(" | ", end="") 67 | 68 | if j == 8: 69 | print(bo[i][j]) 70 | else: 71 | print(str(bo[i][j]) + " ", end="") 72 | 73 | 74 | def find_empty(bo): 75 | for i in range(len(bo)): 76 | for j in range(len(bo[0])): 77 | if bo[i][j] == 0: 78 | return (i, j) # row, col 79 | 80 | return None 81 | 82 | # print_board(board) 83 | # solve(board) 84 | # print("___________________") 85 | # print_board(board) 86 | -------------------------------------------------------------------------------- /Python/BookStoreGUI/__pycache__/backend.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/BookStoreGUI/__pycache__/backend.cpython-38.pyc -------------------------------------------------------------------------------- /Python/BookStoreGUI/backend.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | def connect(): 4 | conn = sqlite3.connect("books.db") 5 | cur = conn.cursor() 6 | cur.execute("CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY,title text, author text,year integer,isbn integer )") 7 | conn.commit() 8 | conn.close() 9 | 10 | connect() 11 | 12 | def insert(title,author,year,isbn): 13 | conn = sqlite3.connect("books.db") 14 | cur = conn.cursor() 15 | cur.execute("INSERT INTO book VALUES (NULL,?,?,?,?)",(title,author,year,isbn)) 16 | conn.commit() 17 | conn.close() 18 | 19 | 20 | def update(id,title,author,year,isbn): 21 | conn = sqlite3.connect("books.db") 22 | cur = conn.cursor() 23 | cur.execute("UPDATE book SET title = ?, author = ? , year = ? , isbn =? WHERE id = ?",(title,author,year,isbn,id)) 24 | conn.commit() 25 | conn.close() 26 | 27 | 28 | def delete(id): 29 | conn = sqlite3.connect("books.db") 30 | cur = conn.cursor() 31 | cur.execute("DELETE FROM book WHERE id=?",(id,)) 32 | conn.commit() 33 | conn.close() 34 | 35 | 36 | def view(): 37 | conn = sqlite3.connect("books.db") 38 | cur = conn.cursor() 39 | cur.execute("SELECT * FROM book") 40 | rows = cur.fetchall() 41 | cur.close() 42 | 43 | return rows 44 | 45 | 46 | 47 | def search(title="",author="",year="",isbn=""): 48 | conn = sqlite3.connect("books.db") 49 | cur = conn.cursor() 50 | cur.execute("SELECT * FROM book WHERE title=? OR author = ? OR year = ? OR isbn = ?",(title,author,year,isbn)) 51 | rows = cur.fetchall() 52 | conn.close() 53 | 54 | return rows 55 | 56 | 57 | -------------------------------------------------------------------------------- /Python/BookStoreGUI/books.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/BookStoreGUI/books.db -------------------------------------------------------------------------------- /Python/CARTOONING-AN-IMAGE-USING-OPENCV-master/Cartoon_BIRD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/CARTOONING-AN-IMAGE-USING-OPENCV-master/Cartoon_BIRD.png -------------------------------------------------------------------------------- /Python/CARTOONING-AN-IMAGE-USING-OPENCV-master/README.md: -------------------------------------------------------------------------------- 1 | # CARTOONING-AN-IMAGE-USING-OPENCV -------------------------------------------------------------------------------- /Python/Dr. Semmelweis and the Discovery of Handwashing/datasets/monthly_deaths.csv: -------------------------------------------------------------------------------- 1 | date,births,deaths 2 | 1841-01-01,254,37 3 | 1841-02-01,239,18 4 | 1841-03-01,277,12 5 | 1841-04-01,255,4 6 | 1841-05-01,255,2 7 | 1841-06-01,200,10 8 | 1841-07-01,190,16 9 | 1841-08-01,222,3 10 | 1841-09-01,213,4 11 | 1841-10-01,236,26 12 | 1841-11-01,235,53 13 | 1842-01-01,307,64 14 | 1842-02-01,311,38 15 | 1842-03-01,264,27 16 | 1842-04-01,242,26 17 | 1842-05-01,310,10 18 | 1842-06-01,273,18 19 | 1842-07-01,231,48 20 | 1842-08-01,216,55 21 | 1842-09-01,223,41 22 | 1842-10-01,242,71 23 | 1842-11-01,209,48 24 | 1842-12-01,239,75 25 | 1843-01-01,272,52 26 | 1843-02-01,263,42 27 | 1843-03-01,266,33 28 | 1843-04-01,285,34 29 | 1843-05-01,246,15 30 | 1843-06-01,196,8 31 | 1843-07-01,191,1 32 | 1843-08-01,193,3 33 | 1843-09-01,221,5 34 | 1843-10-01,250,44 35 | 1843-11-01,252,18 36 | 1843-12-01,236,19 37 | 1844-01-01,244,37 38 | 1844-02-01,257,29 39 | 1844-03-01,276,47 40 | 1844-04-01,208,36 41 | 1844-05-01,240,14 42 | 1844-06-01,224,6 43 | 1844-07-01,206,9 44 | 1844-08-01,269,17 45 | 1844-09-01,245,3 46 | 1844-10-01,248,8 47 | 1844-11-01,245,27 48 | 1844-12-01,256,27 49 | 1845-01-01,303,23 50 | 1845-02-01,274,13 51 | 1845-03-01,292,13 52 | 1845-04-01,260,11 53 | 1845-05-01,296,13 54 | 1845-06-01,280,20 55 | 1845-07-01,245,15 56 | 1845-08-01,251,9 57 | 1845-09-01,237,25 58 | 1845-10-01,283,42 59 | 1845-11-01,265,29 60 | 1845-12-01,267,28 61 | 1846-01-01,336,45 62 | 1846-02-01,293,53 63 | 1846-03-01,311,48 64 | 1846-04-01,253,48 65 | 1846-05-01,305,41 66 | 1846-06-01,266,27 67 | 1846-07-01,252,33 68 | 1846-08-01,216,39 69 | 1846-09-01,271,39 70 | 1846-10-01,254,38 71 | 1846-11-01,297,32 72 | 1846-12-01,298,16 73 | 1847-01-01,311,10 74 | 1847-02-01,312,6 75 | 1847-03-01,305,11 76 | 1847-04-01,312,57 77 | 1847-05-01,294,36 78 | 1847-06-01,268,6 79 | 1847-07-01,250,3 80 | 1847-08-01,264,5 81 | 1847-09-01,262,12 82 | 1847-10-01,278,11 83 | 1847-11-01,246,11 84 | 1847-12-01,273,8 85 | 1848-01-01,283,10 86 | 1848-02-01,291,2 87 | 1848-03-01,276,0 88 | 1848-04-01,305,2 89 | 1848-05-01,313,3 90 | 1848-06-01,264,3 91 | 1848-07-01,269,1 92 | 1848-08-01,261,0 93 | 1848-09-01,312,3 94 | 1848-10-01,299,7 95 | 1848-11-01,310,9 96 | 1848-12-01,373,5 97 | 1849-01-01,403,9 98 | 1849-02-01,389,12 99 | 1849-03-01,406,20 100 | -------------------------------------------------------------------------------- /Python/Dr. Semmelweis and the Discovery of Handwashing/datasets/yearly_deaths_by_clinic.csv: -------------------------------------------------------------------------------- 1 | year,births,deaths,clinic 2 | 1841,3036,237,clinic 1 3 | 1842,3287,518,clinic 1 4 | 1843,3060,274,clinic 1 5 | 1844,3157,260,clinic 1 6 | 1845,3492,241,clinic 1 7 | 1846,4010,459,clinic 1 8 | 1841,2442,86,clinic 2 9 | 1842,2659,202,clinic 2 10 | 1843,2739,164,clinic 2 11 | 1844,2956,68,clinic 2 12 | 1845,3241,66,clinic 2 13 | 1846,3754,105,clinic 2 14 | -------------------------------------------------------------------------------- /Python/Edge-Detection/Edge-Detection-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# OpenCV program to perform Edge detection in real time \n", 10 | "# import libraries of python OpenCV \n", 11 | "# where its functionality resides \n", 12 | "import cv2 \n", 13 | " \n", 14 | "# np is an alias pointing to numpy library \n", 15 | "import numpy as np \n", 16 | " \n", 17 | " \n", 18 | "# capture frames from a camera \n", 19 | "cap = cv2.VideoCapture(0) \n", 20 | " \n", 21 | " \n", 22 | "# loop runs if capturing has been initialized \n", 23 | "while(1): \n", 24 | " \n", 25 | " # reads frames from a camera \n", 26 | " ret, frame = cap.read() \n", 27 | " \n", 28 | " # converting BGR to HSV \n", 29 | " hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) \n", 30 | " \n", 31 | " # define range of red color in HSV \n", 32 | " lower_red = np.array([30,150,50]) \n", 33 | " upper_red = np.array([255,255,180]) \n", 34 | " \n", 35 | " # create a red HSV colour boundary and \n", 36 | " # threshold HSV image \n", 37 | " mask = cv2.inRange(hsv, lower_red, upper_red) \n", 38 | " \n", 39 | " # Bitwise-AND mask and original image \n", 40 | " res = cv2.bitwise_and(frame,frame, mask= mask) \n", 41 | " \n", 42 | " # Display an original image \n", 43 | " cv2.imshow('Original',frame) \n", 44 | " \n", 45 | " # finds edges in the input image image and \n", 46 | " # marks them in the output map edges \n", 47 | " edges = cv2.Canny(frame,100,200) \n", 48 | " \n", 49 | " # Display edges in a frame \n", 50 | " cv2.imshow('Edges',edges) \n", 51 | " \n", 52 | " # Wait for Esc key to stop \n", 53 | " k = cv2.waitKey(5) & 0xFF\n", 54 | " if k == 27: \n", 55 | " break\n", 56 | " \n", 57 | " \n", 58 | "# Close the window \n", 59 | "cap.release() \n", 60 | " \n", 61 | "# De-allocate any associated memory usage \n", 62 | "cv2.destroyAllWindows() " 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [] 71 | } 72 | ], 73 | "metadata": { 74 | "kernelspec": { 75 | "display_name": "Python 3", 76 | "language": "python", 77 | "name": "python3" 78 | }, 79 | "language_info": { 80 | "codemirror_mode": { 81 | "name": "ipython", 82 | "version": 3 83 | }, 84 | "file_extension": ".py", 85 | "mimetype": "text/x-python", 86 | "name": "python", 87 | "nbconvert_exporter": "python", 88 | "pygments_lexer": "ipython3", 89 | "version": "3.7.6" 90 | } 91 | }, 92 | "nbformat": 4, 93 | "nbformat_minor": 2 94 | } 95 | -------------------------------------------------------------------------------- /Python/Encryptor/ed.py: -------------------------------------------------------------------------------- 1 | from tqdm import trange 2 | from time import sleep 3 | 4 | def encrypt(key, msg): 5 | encryped = [] 6 | for i, c in enumerate(msg): 7 | key_c = ord(key[i % len(key)]) 8 | msg_c = ord(c) 9 | encryped.append(chr((msg_c + key_c) % 64)) 10 | return ''.join(encryped) 11 | 12 | def decrypt(key, encryped): 13 | msg = [] 14 | 15 | for i, c in enumerate(encryped): 16 | key_c = ord(key[i % len(key)]) 17 | enc_c = ord(c) 18 | msg.append(chr((enc_c - key_c) % 64)) 19 | return ''.join(msg) 20 | 21 | if __name__ == '__main__': 22 | print(" Hi, I'm Mithil's Cryption ".center(100, '+')) 23 | print("\n\tKindly, choose \n\t\t1.For Encryption \n\t\t2.For Decrpytion") 24 | x = input("\n\tEnter your choice in Numeric Format: ") 25 | if int(x) == 1: 26 | msg = input('\n\tEnter the text to be encrypted:\t') 27 | key = input('\n\tEnter the Key(no spaces):\t') 28 | encrypted = encrypt(key, msg) 29 | for i in trange(15, desc="Encrypting", unit="data", unit_scale=1000, ascii=False): 30 | sleep(0.1) 31 | print('\n\tThe Encrypted Key:\t'+repr(encrypted)) 32 | print('\n\tNote: Remember both your password and Encrypted key.') 33 | elif int(x) == 2: 34 | encrypted = input('\n\tEnter the text to be decrypted:\t') 35 | key = input('\n\tEnter the Key(or the Password for the Text):\t') 36 | decrypted = decrypt(key, encrypted) 37 | for i in trange(15, desc="Decrypting", unit="data", unit_scale=1000, ascii=False): 38 | sleep(0.1) 39 | print('\n\tThe Original value:\t'+repr(decrypted)) 40 | else: 41 | print("I can't get you, try again!") 42 | -------------------------------------------------------------------------------- /Python/FaceRecognition/Barack.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/FaceRecognition/Barack.jpg -------------------------------------------------------------------------------- /Python/FaceRecognition/President.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/FaceRecognition/President.jpg -------------------------------------------------------------------------------- /Python/FaceRecognition/Trumph.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/FaceRecognition/Trumph.jpg -------------------------------------------------------------------------------- /Python/FaceRecognition/facerecognition.py: -------------------------------------------------------------------------------- 1 | import face_recognition 2 | 3 | image = face_recognition.load_image_file("Barack.jpg") 4 | unknown_image=face_recognition.load_image_file("Trumph.jpg") 5 | 6 | barack_encoding = face_recognition.face_encodings(image)[0] 7 | unknown_encoding = face_recognition.face_encodings(unknown_image)[0] 8 | 9 | results = face_recognition.compare_faces([barack_encoding],unknown_encoding) 10 | print(results) 11 | -------------------------------------------------------------------------------- /Python/Jason-Parser/jason-parser.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | response=requests.get("http://extreme-ip-lookup.com/json/119.160.198.197") 4 | #ipaddress in google what is my ip address then replace 5 | print('Response code:{}'.format(response.status_code)) 6 | todos=json.loads(response.text) 7 | print('lat:{}'.format(response.json()["lat"])) 8 | print('lon:{}'.format(response.json()["lon"])) 9 | print('businessName:{}'.format(response.json()["businessName"])) 10 | print('businessWebsite:{}'.format(response.json()["businessWebsite"])) 11 | print('City:{}'.format(response.json()["city"])) 12 | print('continent:{}'.format(response.json()["continent"])) 13 | print('countryCode:{}'.format(response.json()["countryCode"])) 14 | print('ipName:{}'.format(response.json()["ipName"])) 15 | print('ipType:{}'.format(response.json()["ipType"])) 16 | print('query:{}'.format(response.json()["query"])) 17 | print('region:{}'.format(response.json()["region"])) 18 | -------------------------------------------------------------------------------- /Python/Learning Rules/Perceptron Rule.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import math as math 3 | import matplotlib.pyplot as plt 4 | x1=np.array([1,1,-1,-1]) 5 | x2=np.array([1,-1,1,-1]) 6 | t=np.array([1,-1,-1,-1]) 7 | w1=int(0) 8 | w2=int(0) 9 | b=int(0) 10 | a=1 11 | for i in range(len(x1)): 12 | yin=(x1[i]*w1)+(x2[i]*w2)+b 13 | print(yin) 14 | if yin==0: 15 | y=int(0) 16 | elif yin>=0: 17 | y=int(1) 18 | elif yin<=0: 19 | y=int(-1) 20 | if y==t[i]: 21 | print("No weight updation needed") 22 | elif y!=t[i]: 23 | w1new=w1+(a*t[i]*x1[i]) 24 | w2new=w2+(a*t[i]*x2[i]) 25 | bnew=b+(a*t[i]) 26 | w1=w1new 27 | w2=w2new 28 | b=bnew 29 | print("Update the weights") 30 | print(w1) 31 | print(w2) 32 | print(b) 33 | slope=-w1/w2 34 | interc=-b/w2 35 | for ele in t: 36 | plt.plot(x1,x2,'.g') 37 | for i in range(-10,10): 38 | y0=(slope*i)+interc 39 | plt.plot(i,y0,'.b') 40 | plt.show() 41 | -------------------------------------------------------------------------------- /Python/LinkedList/Linkedlist.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self, data = None, next=None): 3 | self.data = data 4 | self.next = next 5 | 6 | class LinkedList: 7 | def __init__(self): 8 | self.head = None 9 | def insert(self, data): 10 | newNode = Node(data) 11 | if(self.head): 12 | current = self.head 13 | while(current.next): 14 | current = current.next 15 | current.next = newNode 16 | else: 17 | self.head = newNode 18 | def printLL(self): 19 | current = self.head 20 | while(current): 21 | print(current.data) 22 | current = current.next 23 | def removeNthFromEnd(self, n): 24 | temp = self.head 25 | k=0 26 | while temp!=None: 27 | k+=1 28 | temp=temp.next 29 | pos=k-n 30 | curr_pos=0 31 | prev=None 32 | temp=self.head 33 | while curr_pos!=pos: 34 | prev=temp 35 | temp=temp.next 36 | curr_pos+=1 37 | if prev: 38 | prev.next=temp.next 39 | else: 40 | self.head=self.head.next 41 | return self.head 42 | keys = list(map(int, input().split(" "))) 43 | LL = LinkedList() 44 | for key in keys: 45 | LL.insert(key) 46 | #LL.printLL() 47 | x=int(input()) 48 | LL.removeNthFromEnd(x) 49 | LL.printLL() -------------------------------------------------------------------------------- /Python/LinkedList/readme.md: -------------------------------------------------------------------------------- 1 | This python file has method to insert elements into linkedlist and deletion of nth node from the end. 2 | -------------------------------------------------------------------------------- /Python/Motion_detection/Detection.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | cap = cv2.VideoCapture('people.mp4') 5 | frame_width = int( cap.get(cv2.CAP_PROP_FRAME_WIDTH)) 6 | 7 | frame_height =int( cap.get( cv2.CAP_PROP_FRAME_HEIGHT)) 8 | 9 | fourcc = cv2.VideoWriter_fourcc('X','V','I','D') 10 | 11 | out = cv2.VideoWriter("output.avi", fourcc, 5.0, (1280,720)) 12 | #FOURCC is short for "four character code" - an identifier for a video codec, compression format, color 13 | # or pixel format used in media files. 14 | 15 | ret, frame1 = cap.read() 16 | ret, frame2 = cap.read() 17 | print(frame1.shape) 18 | print(frame2.shape) 19 | 20 | while cap.isOpened(): 21 | diff = cv2.absdiff(frame1, frame2) 22 | gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY) 23 | blur = cv2.GaussianBlur(gray, (5,5), 0) 24 | _, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY) 25 | #used to get a bi-level (binary) image out of a grayscale image 26 | 27 | dilated = cv2.dilate(thresh, None, iterations=3) 28 | contours, _ = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 29 | 30 | for contour in contours: 31 | (x, y, w, h) = cv2.boundingRect(contour) 32 | 33 | if cv2.contourArea(contour) < 900: 34 | continue 35 | cv2.rectangle(frame1, (x, y), (x+w, y+h), (0, 255, 0), 2) 36 | cv2.putText(frame1, "Status: {}".format('Movement'), (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 37 | 1, (0, 0, 255), 3) 38 | #cv2.drawContours(frame1, contours, -1, (0, 255, 0), 2) 39 | 40 | image = cv2.resize(frame1, (1280,720)) 41 | out.write(image) 42 | cv2.imshow("feed", frame1) 43 | frame1 = frame2 44 | ret, frame2 = cap.read() 45 | 46 | if cv2.waitKey(40) == 27: 47 | break 48 | 49 | cv2.destroyAllWindows() 50 | cap.release() 51 | out.release() -------------------------------------------------------------------------------- /Python/Motion_detection/MotionDetection.md: -------------------------------------------------------------------------------- 1 | # Motion Detection in Python 2 | ## By Harshal S Zodape 3 | 4 | ## Introduction 5 | For detecting motion, we will use the Open-CV module. We start with a baseline_image, which is the frame captured without any moving object inside it. As soon as the camera fires, the first image is set to our baseline_image, which means that we expect no moving object when our program first starts. Next, when somebody enters the frame, certain pixels in that frame will be different. We deduce this difference using the “cv2.absdiff” method. 6 | There are a few steps we will take to achieve this. 7 | 1. Capture the baseline_frame (with no object) 8 | 1.1 Convert the frame to Gray 9 | 1.2 Smoothen the frame to remove noise 10 | 2. Capture the new_frame (with object) 11 | 2.1 Convert the frame to Gray 12 | 2.2 Smoothen the frame to remove noise 13 | 3. Calculate the difference between the two frames 14 | 3.1 If difference is greater than the threshold, assume motion is detected 15 | 3.2 Else assume no motion detected 16 | 17 | ## Requirement: 18 | 1. Python3 19 | 2. OpenCV(libraries) 20 | 3. Pandas(libraries) 21 | 22 | ## Main Logic : 23 | Videos can be treated as stack of pictures called frames. Here I am comparing different frames(pictures) 24 | to the first frame which should be static(No movements initially). 25 | We compare two images by comparing the intensity value of each pixels. In python we can do 26 | it easily as you can see Dectecton.py file. 27 | 28 | ## For more Infomation: 29 | 30 | [Link1](https://www.geeksforgeeks.org/webcam-motion-detector-python/) 31 | [Link2](https://towardsdatascience.com/build-a-motion-triggered-alarm-in-5-minutes-342fbe3d5396) 32 | [Youtubelink1](https://www.youtube.com/watch?v=-RUu3EcielI) 33 | [Youtubelink2](https://www.youtube.com/watch?v=sRIdyfh3054) 34 | -------------------------------------------------------------------------------- /Python/Motion_detection/Output-1.m4v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/Motion_detection/Output-1.m4v -------------------------------------------------------------------------------- /Python/N-Queens/n_queens.py: -------------------------------------------------------------------------------- 1 | # TC:O(N^N) 2 | def queens_helper(n, row, col, asc_des, desc_des, possibilities): 3 | curr_row = len(possibilities) 4 | for curr_col in range(n): 5 | if col[curr_col] and row[curr_row] and asc_des[curr_col+curr_row] and desc_des[curr_row-curr_col]: 6 | row[curr_row] = False 7 | col[curr_col] = False 8 | asc_des[curr_col+curr_row] = False 9 | desc_des[curr_row-curr_col] = False 10 | possibilities.append((curr_row, curr_col)) 11 | possibilities = queens_helper( 12 | n, row, col, asc_des, desc_des, possibilities) 13 | # print(possibilities) 14 | if(len(possibilities) == n): 15 | return possibilities 16 | 17 | # Otherwise we are backtracking 18 | row[curr_row] = True 19 | col[curr_col] = True 20 | asc_des[curr_col+curr_row] = True 21 | desc_des[curr_row-curr_col] = True 22 | possibilities.pop() 23 | return possibilities 24 | 25 | 26 | def queens(n): 27 | col = [True]*n 28 | row = [True]*n 29 | asc_des = [True]*(n*2-1) 30 | desc_des = [True]*(n*2-1) 31 | return queens_helper(n, row, col, asc_des, desc_des, []) 32 | 33 | 34 | s = queens(4) 35 | l = "" 36 | ans = [] 37 | for i in range(4): 38 | for j in range(4): 39 | if((i, j) in s): 40 | l += "Q" 41 | else: 42 | l += "." 43 | ans.append(l) 44 | l = "" 45 | print(ans) 46 | # Output: 47 | ['.Q..', '...Q', 'Q...', '..Q.'] 48 | -------------------------------------------------------------------------------- /Python/Object_detection/objectdetectvideo.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | def nothing(x): 4 | pass 5 | cap=cv2.VideoCapture(0) 6 | cv2.namedWindow('Tracking') 7 | cv2.createTrackbar('LH','Tracking',0,255,nothing) 8 | cv2.createTrackbar('LS','Tracking',0,255,nothing) 9 | cv2.createTrackbar('LV','Tracking',0,255,nothing) 10 | cv2.createTrackbar('UH','Tracking',255,255,nothing) 11 | cv2.createTrackbar('US','Tracking',255,255,nothing) 12 | cv2.createTrackbar('UV','Tracking',255,255,nothing) 13 | while True: 14 | _, frame=cap.read() 15 | 16 | hsv=cv2.cvtColor(frame,cv2.COLOR_BGR2HSV) 17 | lh=cv2.getTrackbarPos('LH','Tracking') 18 | ls=cv2.getTrackbarPos('LS','Tracking') 19 | lv=cv2.getTrackbarPos('LV','Tracking') 20 | uh=cv2.getTrackbarPos('UH','Tracking') 21 | us=cv2.getTrackbarPos('US','Tracking') 22 | uv=cv2.getTrackbarPos('UV','Tracking') 23 | lb=np.array([lh,ls,lv]) 24 | up=np.array([uh,us,uv]) 25 | mask=cv2.inRange(hsv,lb,up) 26 | res=cv2.bitwise_and(frame,frame,mask=mask) 27 | cv2.imshow('Frame',frame) 28 | cv2.imshow('Mask',mask) 29 | cv2.imshow('Result',res) 30 | k=cv2.waitKey(1) 31 | if k==27: 32 | break 33 | cap.release() 34 | cv2.destroyAllWindows() 35 | -------------------------------------------------------------------------------- /Python/Object_detection/readme.md: -------------------------------------------------------------------------------- 1 | ===================================================================================================================== 2 | 3 | THIS IS A PYTHON SCRIPT WHY CAN DETECT OR ISOLATE CERTAIN AREA BASED UPON COLOR VALUE 4 | I made this script to detect some obstacles for a robot i'm working on. 5 | NOTE-You will need a webcam or video input to run this! 6 | 7 | ===================================================================================================================== -------------------------------------------------------------------------------- /Python/Object_detection/smarties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/Object_detection/smarties.png -------------------------------------------------------------------------------- /Python/Password_generator/main.py: -------------------------------------------------------------------------------- 1 | import string 2 | import random 3 | 4 | if __name__ == "__main__": 5 | set1 = string.ascii_lowercase 6 | # print(set1) 7 | set2 = string.ascii_uppercase 8 | # print(set2) 9 | set3 = string.digits 10 | # print(set3) 11 | set4 = string.punctuation 12 | # print(set4) 13 | 14 | pwd_len = int(input("Enter passward length\n")) 15 | 16 | s = [] 17 | s.extend(list(set1)) 18 | s.extend(list(set2)) 19 | s.extend(list(set3)) 20 | s.extend(list(set4)) 21 | # print(s) 22 | 23 | random.shuffle(s) 24 | # print(s) 25 | 26 | print("Your password is: ") 27 | print("".join(s[0:pwd_len])) 28 | 29 | 30 | # another method 31 | # print("".join(random.sample(s,pwd_len))) 32 | -------------------------------------------------------------------------------- /Python/Plots/bowling_scorecard: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | over = [] 5 | runs = [] 6 | 7 | # number of records which user wants to enter! 8 | records = int(input("Enter number of records : ")) 9 | 10 | # iterating till the range 11 | for i in range(0, records): 12 | print(" Enter the Bowler Name") 13 | overs = str(input()) 14 | over.append(overs) 15 | # adding the elements 16 | 17 | for i in range(0, records): 18 | print("Enter the runs given by the bowler") 19 | run = int(input()) 20 | runs.append(run) 21 | 22 | 23 | fig = plt.figure(figsize = (10, 5)) 24 | 25 | ax = fig.add_axes([0,0,1,1]) 26 | ax.bar(over,runs,color=['red','yellow']) 27 | plt.ylabel("Runs") 28 | plt.xlabel("Bowler") 29 | plt.title("Bowling Scorecard") 30 | plt.savefig("Result.jpeg") 31 | plt.show() 32 | -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/Data/chart.csv: -------------------------------------------------------------------------------- 1 | Attacking,Normal,Fire,Water,Electric,Grass,Ice,Fighting,Poison,Ground,Flying,Psychic,Bug,Rock,Ghost,Dragon,Dark,Steel,Fairy 2 | Normal,1,1,1,1,1,1,1,1,1,1,1,1,0.5,0,1,1,0.5,1 3 | Fire,1,0.5,0.5,1,2,2,1,1,1,1,1,2,0.5,1,0.5,1,2,1 4 | Water,1,2,0.5,1,0.5,1,1,1,2,1,1,1,2,1,0.5,1,1,1 5 | Electric,1,1,2,0.5,0.5,1,1,1,0,2,1,1,1,1,0.5,1,1,1 6 | Grass,1,0.5,2,1,0.5,1,1,0.5,2,0.5,1,0.5,2,1,0.5,1,0.5,1 7 | Ice,1,0.5,0.5,1,2,0.5,1,1,2,2,1,1,1,1,2,1,0.5,1 8 | Fighting,2,1,1,1,1,2,1,0.5,1,0.5,0.5,0.5,2,0,1,2,2,0.5 9 | Poison,1,1,1,1,2,1,1,0.5,0.5,1,1,1,0.5,0.5,1,1,0,2 10 | Ground,1,2,1,2,0.5,1,1,2,1,0,1,0.5,2,1,1,1,2,1 11 | Flying,1,1,1,0.5,2,1,2,1,1,1,1,2,0.5,1,1,1,0.5,1 12 | Psychic,1,1,1,1,1,1,2,2,1,1,0.5,1,1,1,1,0,0.5,1 13 | Bug,1,0.5,1,1,2,1,0.5,0.5,1,0.5,2,1,1,0.5,1,2,0.5,0.5 14 | Rock,1,2,1,1,1,2,0.5,1,0.5,2,1,2,1,1,1,1,0.5,1 15 | Ghost,0,1,1,1,1,1,1,1,1,1,2,1,1,2,1,0.5,1,1 16 | Dragon,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,0.5,0 17 | Dark,1,1,1,1,1,1,0.5,1,1,1,2,1,1,2,1,0.5,1,0.5 18 | Steel,1,0.5,0.5,0.5,1,2,1,1,1,1,1,1,2,1,1,1,0.5,2 19 | Fairy,1,0.5,1,1,1,1,2,0.5,1,1,1,1,1,1,2,2,0.5,1 20 | -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/README.md: -------------------------------------------------------------------------------- 1 | # Pokemon Data Analysis 2 | Data analysis is a process of inspecting, cleansing, transforming and modeling data with the goal of discovering useful information, informing conclusions and supporting decision-making. 3 | 4 | Lets take an example that you want to become the best Pokemon player(even better than Ash Ketchum) in the world but in the world of pokemons you are lost. You can not figure out which pokemon is the best fit for specific purposes. This is the time when you should relax and utilize data analysis to get all your required information. I would love to make you a better trainer than Ash, so lets start. 5 | 6 | You can find the Dataset here. 7 | 8 |

To run the code in Binder or Kaggle or Colab: https://jovian.ml/sayantan-world98/pokemon-data-analysis

9 | 10 | ![Poke cover](https://github.com/Sayantan-world/Pokemon-Data-Analysis/blob/main/cover.jpg?raw=true) 11 | -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/images/Talonflame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/PokemonDataAnalysis/images/Talonflame.png -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/images/blissey.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/PokemonDataAnalysis/images/blissey.jpg -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/images/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/PokemonDataAnalysis/images/cover.jpg -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/images/drag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/PokemonDataAnalysis/images/drag.jpg -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/images/team.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/PokemonDataAnalysis/images/team.png -------------------------------------------------------------------------------- /Python/PokemonDataAnalysis/images/w_chart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/PokemonDataAnalysis/images/w_chart.jpg -------------------------------------------------------------------------------- /Python/README.md: -------------------------------------------------------------------------------- 1 | # HACTOBERFEST2020 2 |

Python

3 | 4 | * Add python script here 5 | 6 | * Create a separate folder for each script 7 | -------------------------------------------------------------------------------- /Python/Seive_Theorem/README.md: -------------------------------------------------------------------------------- 1 | # Seive Theorem 2 | # Prime numbers Generator 3 | [![ForTheBadge built-by-developers](http://ForTheBadge.com/images/badges/built-by-developers.svg)](https://GitHub.com/Mithilsai/) 4 | [![ForTheBadge built-with-love](http://ForTheBadge.com/images/badges/built-with-love.svg)](https://GitHub.com/Mithilsai/) 5 | [![forthebadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) 6 | 7 | ## Example solution's output 8 | ![pic from Mithil](https://github.com/Mithilsai/HACTOBERFEST2020/blob/master/Python/Seive_Theorem/prime.PNG?raw=true) 9 | 10 | ### Run this on Command prompt or on IDE. 11 | 12 | ## Developed by 13 | [Jakka Mithil sai](https://www.linkedin.com/in/mithil1729/) 14 | -------------------------------------------------------------------------------- /Python/Seive_Theorem/generating_primes.py: -------------------------------------------------------------------------------- 1 | # Generation of the primes using seives theorem 2 | # Time complexity: O(n*log(log(n))) 3 | from math import sqrt 4 | 5 | def prime_generator(n): 6 | # we are creating a list to push those numbers 7 | # Note: we are creating a list as to have less space complexity 8 | primes = [True]*(n+1) 9 | primes[0] = False 10 | primes[1] = False 11 | # As 0 and 1 are Not Primes 12 | for p in range(2, int(sqrt(n))+1): 13 | # As the primes starts with 2 14 | if primes[p] == True: 15 | for i in range(p*p, n+1, p): 16 | #all numbers greater than sqr of 2 and divisible by 2 aren't primes 17 | primes[i] = False 18 | # Inserted of the numbers of the list are displayed 19 | for i in range(0, len(primes)): 20 | if primes[i] == True: 21 | # we are extracting every number from list and printing them indivudually 22 | print(i, end=" ") 23 | 24 | print("Enter the test cases: ") 25 | t = int(input()) 26 | while t: 27 | print("Enter the highest possibility number: ") 28 | n = int(input()) 29 | print("The prime numbers upto "+str(n)+" are: \n") 30 | prime_generator(n) 31 | t -= 1 32 | 33 | -------------------------------------------------------------------------------- /Python/Seive_Theorem/prime.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/Seive_Theorem/prime.PNG -------------------------------------------------------------------------------- /Python/Smile_detector/Smile_detector.py: -------------------------------------------------------------------------------- 1 | # Importing the libraries 2 | import cv2 3 | 4 | # Loading the cascades 5 | face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 6 | eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') 7 | smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml') 8 | 9 | def detect(gray, frame): 10 | """ 11 | A function that will do the detection of face 12 | """ 13 | faces = face_cascade.detectMultiScale(gray, 1.3, 5) 14 | for (x, y, w, h) in faces: 15 | cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2) 16 | roi_gray = gray[y:y+h, x:x+w] 17 | roi_color = frame[y:y+h, x:x+w] 18 | eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 22) 19 | for (ex, ey, ew, eh) in eyes: 20 | cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) 21 | smiles = smile_cascade.detectMultiScale(roi_gray, 1.7, 22) 22 | for (sx, sy, sw, sh) in smiles: 23 | cv2.rectangle(roi_color, (sx, sy), (sx+sw, sy+sh), (0, 0, 255), 2) 24 | return frame 25 | 26 | # Doing smile Recognition with the webcam 27 | video_capture = cv2.VideoCapture(0) 28 | while True: 29 | _, frame = video_capture.read() 30 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 31 | canvas = detect(gray, frame) 32 | cv2.imshow('Video', canvas) 33 | if cv2.waitKey(1) & 0xFF == ord('q'): 34 | break 35 | video_capture.release() 36 | cv2.destroyAllWindows() 37 | -------------------------------------------------------------------------------- /Python/Smile_detector/readme.md: -------------------------------------------------------------------------------- 1 | ## Smile_detector with openCV 2 | > A simple python script for smile detection with `openCV` . 3 | 1. Importing the libraries 4 | 2. Loading the cascades 5 | 3. Doing smile Recognition with the webcam 6 | -------------------------------------------------------------------------------- /Python/Snake Game/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 | THIS IS A SNAKE GAME 3 | BUILT IN PYTHON 4 | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 5 | -------------------------------------------------------------------------------- /Python/Snake Game/snake.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | from random import randrange 3 | from freegames import square, vector 4 | 5 | #5 FUNCTIONALITY 6 | def change(x, y): 7 | aim.x = x 8 | aim.y = y 9 | 10 | def insideField(head): 11 | return -251 < head.x < 250 and -251 < head.y < 250 12 | 13 | def move(): 14 | head = snake[-1].copy() 15 | head.move(aim) 16 | 17 | if not insideField(head): 18 | square(head.x, head.y, 9, 'red') 19 | t.write("Game Over! Score: {}".format(len(snake))) 20 | update() 21 | return 22 | 23 | snake.append(head) 24 | 25 | if head == food: 26 | food.x = randrange(-25, 25) * 10 27 | food.y = randrange(-25, 25) * 10 28 | else: 29 | snake.pop(0) 30 | 31 | clear() 32 | 33 | for body in snake: 34 | square(body.x, body.y, 9, 'black') 35 | 36 | square(food.x, food.y, 9, 'blue') 37 | update() 38 | ontimer(move, 100) 39 | 40 | #1 WINDOW SETUP 41 | window = Screen() 42 | window.bgcolor("light green") 43 | window.title("Snake Game") 44 | setup(600, 600, 400, 50) 45 | 46 | #2 MAKE FIELD AREA 47 | hideturtle() 48 | tracer(False) 49 | t = Turtle() 50 | t.hideturtle() 51 | t.penup() 52 | t.setpos(-250, 250) 53 | t.pendown() 54 | for i in range(4): 55 | t.forward(500) 56 | t.right(90) 57 | 58 | #3 SETTING STARTING POSITIONS OF ELEMENTS 59 | food = vector(0, 0) 60 | square(food.x, food.y, 9, 'blue') 61 | snake = [vector(10, 0)] 62 | square(snake[-1].x, snake[-1].y, 9, 'black') 63 | aim = vector(0, -10) 64 | 65 | #4 LISTENING FROM THE KEY BOARD 66 | listen() 67 | onkey(lambda: change(10, 0), 'Right') 68 | onkey(lambda: change(-10, 0), 'Left') 69 | onkey(lambda: change(0, 10), 'Up') 70 | onkey(lambda: change(0, -10), 'Down') 71 | 72 | move() 73 | 74 | done() 75 | -------------------------------------------------------------------------------- /Python/Spiral_Traversal_matrix/Spiral_mat_traversal.py: -------------------------------------------------------------------------------- 1 | def spiralTraverse(array): 2 | result = [] 3 | startRow, endRow = 0, len(array)-1 4 | startCol, endCol = 0, len(array[0])-1 5 | # Equal is imp if we have single line in matrix afterwards 6 | while startRow <= endRow and startCol <= endCol: 7 | for col in range(startCol, endCol+1): 8 | result.append(array[startRow][col]) 9 | 10 | for row in range(startRow+1, endRow+1): 11 | result.append(array[row][endCol]) 12 | 13 | for col in reversed(range(startCol, endCol)): 14 | result.append(array[endRow][col]) 15 | 16 | for row in reversed(range(startRow+1, endRow)): 17 | result.append(array[row][startCol]) 18 | # Now for the inward parameters we have to the following choices: 19 | startRow, endRow = startRow+1, endRow-1 20 | startCol, endCol = startCol+1, endCol-1 21 | return result 22 | 23 | 24 | matrix = [[1, 2, 3], 25 | [4, 5, 6], 26 | [7, 8, 9]] 27 | print(spiralTraverse(matrix)) 28 | # [1, 2, 3, 6, 9, 8, 7, 4, 5] 29 | -------------------------------------------------------------------------------- /Python/Sports Avalytics/README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning model and Deep Learning model for Sports Analytics 2 | 3 | The following files contains different models to show the analytics of the football match. 4 | 5 | mfile.py 6 | 7 | The following ML algorithms were implemented. 8 | 9 | 1. Linear Support Vector Machines. 10 | 2. Polynomial Support Vector Machines. 11 | 3. RBF Linear SVM. 12 | 13 | nn.py 14 | 15 | Deep learning model designed using Keras with the following model structure. 16 | 17 | Input - 20 18 | Mid layer - 16 19 | Output layer - 1 20 | -------------------------------------------------------------------------------- /Python/Sports Avalytics/nn.py: -------------------------------------------------------------------------------- 1 | import keras 2 | from keras.models import Sequential 3 | from keras.layers import Dense 4 | 5 | import pandas as pd 6 | import numpy as np 7 | 8 | dataset = pd.read_csv("sample_data.csv") 9 | X = dataset.drop(["Date","Referee"],axis=1) 10 | 11 | Y = dataset["FTR"] 12 | 13 | X_train = X[0:15] 14 | X_test = X[15:] 15 | Y_train = Y[0:15] 16 | Y_test = Y[15:] 17 | 18 | model = Sequential(); 19 | 20 | firstLayer = Dense(units = 16, activation='relu', kernel_initializer='uniform',input_dim = 20) 21 | 22 | model.add(firstLayer); 23 | 24 | secondLayer = Dense(units = 1, activation = 'relu', kernel_initializer = 'uniform') 25 | 26 | model.add(secondLayer); 27 | 28 | model.compile(optimizer = 'adam', loss = 'mse', metrics=['accuracy']) 29 | 30 | history = model.fit(X_train, Y_train, epochs = 300, batch_size = 50) 31 | 32 | import matplotlib.pyplot as plt 33 | 34 | plt.plot(history.history['accuracy']) 35 | plt.title('Model accuracy') 36 | plt.ylabel('Accuracy') 37 | plt.xlabel('Epoch') 38 | plt.legend(['Train', 'Test'], loc='upper left') 39 | plt.show() 40 | 41 | plt.plot(history.history['loss']) 42 | plt.title('Model loss') 43 | plt.ylabel('Loss') 44 | plt.xlabel('Epoch') 45 | plt.legend(['Train', 'Test'], loc='upper left') 46 | plt.show() 47 | 48 | -------------------------------------------------------------------------------- /Python/Sports Avalytics/requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | numpy 3 | matplotlib 4 | sklearn 5 | scikit-learn 6 | keras 7 | 8 | -------------------------------------------------------------------------------- /Python/Text_to_Speech/text_to_speech.py: -------------------------------------------------------------------------------- 1 | #first install gtts package on cmd --> pip install gtts 2 | from gtts import gTTS 3 | #import gTTS from package install 4 | import os #neeed to learn more ... 5 | #inbuild package 6 | 7 | #mytext= "Text to speech conversion using python" #we can gave text here too or 8 | #to read the file make file handler 9 | #default method in python which is used to open file open(,"r") and read(mode),it can be write too 10 | fh=open("text.txt","r") 11 | mytext=fh.read().replace("\n"," ") #here i too replace all the line ending with " " 12 | 13 | language="en"#variable called language t lang we us fr-->french,en-->english which is supported by gTTS 14 | 15 | output=gTTS(text=mytext,lang=language,slow=False) #slow makes False so our audio play in fast speed not in slow speed 16 | 17 | output.save("output.mp3") #u can saved ur output in mp3 by calling method call save 18 | fh.close() 19 | os.system("start output.mp3") #for playing audio file 20 | -------------------------------------------------------------------------------- /Python/Web Scrapping/Beautifulsoup/main.py: -------------------------------------------------------------------------------- 1 | # HTML Web Scrapping using bs4 2 | 3 | # STEP0: SETTING UP THE ENVIRONMENT 4 | # Imported requests and beutifulSoup(bs4) 5 | 6 | import requests 7 | from bs4 import BeautifulSoup 8 | url = "https://codewithharry.com/" 9 | 10 | # STEP1: GET THE HTML 11 | 12 | r = requests.get(url) 13 | htmlcontent = r.content 14 | print(htmlcontent) 15 | 16 | # STEP2: PARSE THE HTML 17 | 18 | soup = BeautifulSoup(htmlcontent, 'html.parser') 19 | print(soup.prettify) 20 | 21 | # STEP3: HTML TREE TRAVERSAL 22 | #Tag 23 | #Navigable String 24 | #BeautifulSoup 25 | #Comment 26 | 27 | title = soup.title 28 | print(title) 29 | 30 | paras = soup.find_all('p') 31 | print(paras) 32 | 33 | anchors = soup.find_all('a') 34 | print(anchors) 35 | 36 | first_para = soup.find('p') 37 | print(first_para) 38 | 39 | # Get classes of any element in HTML Page 40 | print(first_para['class']) 41 | 42 | # Get all the elements of a specific class(eg. lead) 43 | print(soup.find_all("p", class_="lead")) 44 | 45 | # To get text from tags/soup 46 | print(soup.find('p').get_text()) 47 | print(soup.get_text()) 48 | 49 | # To get all links of a page 50 | anchors = soup.find_all('a') 51 | all_links = set() 52 | 53 | for link in anchors: 54 | if(link.get('href') != "#"): 55 | linkText = "https://codewithharry.com" + link.get('href') 56 | all_links.add(link) 57 | print(linkText) 58 | 59 | 60 | # For comment in HTML Tree Traversal 61 | 62 | markup = "

" 63 | soup2 = BeautifulSoup(markup) 64 | print(soup2.p.string) 65 | 66 | 67 | # To find elements of a particular id 68 | 69 | navbarSupportedContent = soup.find(id='navbarSupportedContent') 70 | for element in navbarSupportedContent.children: # we can use .contents also but for large websites .children is more effecient 71 | print(element) 72 | 73 | for item in navbarSupportedContent.strings: 74 | print(item) 75 | 76 | for item in navbarSupportedContent.stripped_strings: 77 | print(item) 78 | 79 | print(navbarSupportedContent.parent) 80 | 81 | for item in navbarSupportedContent.parents: 82 | print(item.name) 83 | 84 | # Sibblings 85 | 86 | print(navbarSupportedContent.next_sibling) 87 | 88 | print(navbarSupportedContent.next_sibling.next_sibling) 89 | 90 | print(navbarSupportedContent.previous_sibling) 91 | 92 | print(navbarSupportedContent.previous_sibling.previous_sibling) 93 | 94 | # CSS Selecting 95 | 96 | # # is for id 97 | 98 | id_element = soup.select('#loginModal') 99 | print(id_element) 100 | 101 | # . is for class 102 | 103 | class_element = soup.select('.loginModal') 104 | print(class_element) -------------------------------------------------------------------------------- /Python/YoutubeDownloader/Readme.md: -------------------------------------------------------------------------------- 1 | # How to Use 2 | ### Install pytube using ```pip install pytube``` in cmd 3 | 4 | ## 1. It will Prompt for Link of Youtube Video 5 | 6 | ## 2. If the link will be valid it will show you the Title and Description of Video, else a error will thrown. 7 | 8 | ## 3. Video will start downloading with a message "Downloading...." 9 | 10 | ## 4. After successful Download a message "Download Completed!!" will appear 11 | -------------------------------------------------------------------------------- /Python/YoutubeDownloader/ytDownloader.py: -------------------------------------------------------------------------------- 1 | from pytube import YouTube 2 | 3 | #Prompt for Link of the Youtube 4 | link = input("Enter the link of YouTube video you want to download: ") 5 | yt = YouTube(link) 6 | 7 | #Showing Title, description and length of Video 8 | print("Title: ",yt.title) 9 | 10 | print("\nDescription: ",yt.description) 11 | 12 | print("\nLength of video: ",yt.length) 13 | 14 | #Getting the highest resolution possible 15 | ys = yt.streams.get_highest_resolution() 16 | 17 | #Starting download 18 | print("Downloading...") 19 | ys.download() 20 | print("Download completed!!") 21 | -------------------------------------------------------------------------------- /Python/alarm clock/alarm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/alarm clock/alarm.mp3 -------------------------------------------------------------------------------- /Python/alarm clock/alarm.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | 3 | import pygame 4 | import datetime 5 | 6 | pygame.init() 7 | pygame.mixer.init() 8 | 9 | h = int(input("Enter hour:-")) 10 | m = int(input("Enter min :-")) 11 | 12 | while 1: 13 | if h == datetime.datetime.now().hour and m == datetime.datetime.now().minute: 14 | pygame.mixer.music.load("alarm.mp3") 15 | pygame.mixer.music.play() 16 | sleep(1) 17 | break 18 | 19 | 20 | -------------------------------------------------------------------------------- /Python/datacleaning: -------------------------------------------------------------------------------- 1 | # explore the effect of the variance thresholds on the number of selected features 2 | from numpy import arange 3 | from pandas import read_csv 4 | from sklearn.feature_selection import VarianceThreshold 5 | from matplotlib import pyplot 6 | # define the location of the dataset 7 | path = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/oil-spill.csv' 8 | # load the dataset 9 | df = read_csv(path, header=None) 10 | # split data into inputs and outputs 11 | data = df.values 12 | X = data[:, :-1] 13 | y = data[:, -1] 14 | print(X.shape, y.shape) 15 | # define thresholds to check 16 | thresholds = arange(0.0, 0.55, 0.05) 17 | # apply transform with each threshold 18 | results = list() 19 | for t in thresholds: 20 | # define the transform 21 | transform = VarianceThreshold(threshold=t) 22 | # transform the input data 23 | X_sel = transform.fit_transform(X) 24 | # determine the number of input features 25 | n_features = X_sel.shape[1] 26 | print('>Threshold=%.2f, Features=%d' % (t, n_features)) 27 | # store the result 28 | results.append(n_features) 29 | # plot the threshold vs the number of selected features 30 | pyplot.plot(thresholds, results) 31 | pyplot.show() 32 | -------------------------------------------------------------------------------- /Python/digit-recognition-master/README.md: -------------------------------------------------------------------------------- 1 | # Digit Recognition 2 | Handwritten Digit Recognition using OpenCV, sklearn and Python. 3 | 4 | 5 | # Dependencies 6 | 1. `cv2` 7 | 2. `sklearn` 8 | 3. `skimage` 9 | 4. `numpy` 10 | 5. `collections` 11 | 12 | # Contents 13 | This repository contains the following files- 14 | 15 | 1. `generateClassifier.py` - Python Script to create the classifier file `digits_cls.pkl`. 16 | 2. `performRecognition.py` - Python Script to test the classifier. 17 | 3. `digits_cls.pkl` - Classifier file for digit recognition. 18 | 4. `photo_1.jpg` - Test image number 1 to test the classifier 19 | 5. `photo_2.jpg` - Test image numbre 2 to test the classifier 20 | 21 | 22 | 23 | ## TODO 24 | 25 | * Add a CNN Based approach 26 | * Reject bounding boxes lesser than some area 27 | * Look into user errors 28 | -------------------------------------------------------------------------------- /Python/digit-recognition-master/digits_cls.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/digit-recognition-master/digits_cls.pkl -------------------------------------------------------------------------------- /Python/digit-recognition-master/generateClassifier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Import the modules 4 | from sklearn.externals import joblib 5 | from sklearn import datasets 6 | from skimage.feature import hog 7 | from sklearn.svm import LinearSVC 8 | from sklearn import preprocessing 9 | import numpy as np 10 | from collections import Counter 11 | 12 | # Load the dataset 13 | dataset = datasets.fetch_mldata("MNIST Original") 14 | 15 | # Extract the features and labels 16 | features = np.array(dataset.data, 'int16') 17 | labels = np.array(dataset.target, 'int') 18 | 19 | # Extract the hog features 20 | list_hog_fd = [] 21 | for feature in features: 22 | fd = hog(feature.reshape((28, 28)), orientations=9, pixels_per_cell=(14, 14), cells_per_block=(1, 1), visualise=False) 23 | list_hog_fd.append(fd) 24 | hog_features = np.array(list_hog_fd, 'float64') 25 | 26 | # Normalize the features 27 | pp = preprocessing.StandardScaler().fit(hog_features) 28 | hog_features = pp.transform(hog_features) 29 | 30 | print "Count of digits in dataset", Counter(labels) 31 | 32 | # Create an linear SVM object 33 | clf = LinearSVC() 34 | 35 | # Perform the training 36 | clf.fit(hog_features, labels) 37 | 38 | # Save the classifier 39 | joblib.dump((clf, pp), "digits_cls.pkl", compress=3) 40 | -------------------------------------------------------------------------------- /Python/digit-recognition-master/performRecognition.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Import the modules 4 | import cv2 5 | from sklearn.externals import joblib 6 | from skimage.feature import hog 7 | import numpy as np 8 | import argparse as ap 9 | 10 | # Get the path of the training set 11 | parser = ap.ArgumentParser() 12 | parser.add_argument("-c", "--classiferPath", help="Path to Classifier File", required="True") 13 | parser.add_argument("-i", "--image", help="Path to Image", required="True") 14 | args = vars(parser.parse_args()) 15 | 16 | # Load the classifier 17 | clf, pp = joblib.load(args["classiferPath"]) 18 | 19 | # Read the input image 20 | im = cv2.imread(args["image"]) 21 | 22 | # Convert to grayscale and apply Gaussian filtering 23 | im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) 24 | im_gray = cv2.GaussianBlur(im_gray, (5, 5), 0) 25 | 26 | # Threshold the image 27 | ret, im_th = cv2.threshold(im_gray, 90, 255, cv2.THRESH_BINARY_INV) 28 | 29 | # Find contours in the image 30 | ctrs, hier = cv2.findContours(im_th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 31 | 32 | # Get rectangles contains each contour 33 | rects = [cv2.boundingRect(ctr) for ctr in ctrs] 34 | 35 | # For each rectangular region, calculate HOG features and predict 36 | # the digit using Linear SVM. 37 | for rect in rects: 38 | # Draw the rectangles 39 | cv2.rectangle(im, (rect[0], rect[1]), (rect[0] + rect[2], rect[1] + rect[3]), (0, 255, 0), 3) 40 | # Make the rectangular region around the digit 41 | leng = int(rect[3] * 1.6) 42 | pt1 = int(rect[1] + rect[3] // 2 - leng // 2) 43 | pt2 = int(rect[0] + rect[2] // 2 - leng // 2) 44 | roi = im_th[pt1:pt1+leng, pt2:pt2+leng] 45 | # Resize the image 46 | roi = cv2.resize(roi, (28, 28), interpolation=cv2.INTER_AREA) 47 | roi = cv2.dilate(roi, (3, 3)) 48 | # Calculate the HOG features 49 | roi_hog_fd = hog(roi, orientations=9, pixels_per_cell=(14, 14), cells_per_block=(1, 1), visualise=False) 50 | roi_hog_fd = pp.transform(np.array([roi_hog_fd], 'float64')) 51 | nbr = clf.predict(roi_hog_fd) 52 | cv2.putText(im, str(int(nbr[0])), (rect[0], rect[1]),cv2.FONT_HERSHEY_DUPLEX, 2, (0, 255, 255), 3) 53 | 54 | cv2.namedWindow("Resulting Image with Rectangular ROIs", cv2.WINDOW_NORMAL) 55 | cv2.imshow("Resulting Image with Rectangular ROIs", im) 56 | cv2.waitKey() 57 | -------------------------------------------------------------------------------- /Python/digit-recognition-master/photo_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/digit-recognition-master/photo_1.jpg -------------------------------------------------------------------------------- /Python/digit-recognition-master/photo_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/digit-recognition-master/photo_2.jpg -------------------------------------------------------------------------------- /Python/flight delay/Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /Python/flight delay/README.md: -------------------------------------------------------------------------------- 1 | # Application-of-Machine-Learning-Algorithms-to-Predict-Flight-Delays 2 | Using a machine learning model, we can predict the flight arrival delays. We can take various inputs as a row of feature vector like departure date, departure delay, the distance between the two airports, scheduled arrival time, origin airport, destination airport etc to the algorithm. We then use decision tree classifier to predict if the flight arrival will be delayed or not. A flight is considered to be delayed when the difference between scheduled and actual arrival times is greater than 15 minutes. The model will be trained based on the features which will give the higher accuracy. Finally, it will be integrated into a web-based application. The final system allows the user to give the details of the flights as input and the system will display the output whether the flight will be late or not. 3 | -------------------------------------------------------------------------------- /Python/flight delay/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | import pickle 3 | import numpy as np 4 | model = pickle.load(open('res.pkl', 'rb')) 5 | app = Flask(__name__) 6 | 7 | @app.route('/') 8 | def home(): 9 | return render_template('index.html') 10 | 11 | @app.route('/login', methods=['POST']) 12 | def login(): 13 | MONTH = request.form['month'] 14 | DAY = request.form['day'] 15 | SCHEDULED_DEPARTURE = request.form['scheduled_dep'] 16 | DEPARTURE_DELAY = request.form['dep_delay'] 17 | SCHEDULED_ARRIVAL = request.form['scheduled_arrival'] 18 | DIVERTED = request.form['diverted'] 19 | CANCELLED = request.form['cancelled'] 20 | AIR_SYSTEM_DELAY= 14.009280092800928 #mean 21 | SECURITY_DELAY= 0.024510245102451023 #mean 22 | AIRLINE_DELAY = 17.295672956729568 #mean 23 | LATE_AIRCRAFT_DELAY = 26.005040050400503 #mean 24 | WEATHER_DELAY = 2.2603726037260374 #mean 25 | # AIR_SYSTEM_DELAY= request.form['air_sys_delay'] 26 | # SECURITY_DELAY= request.form['security_delay'] 27 | # AIRLINE_DELAY = request.form['airline_delay'] 28 | # LATE_AIRCRAFT_DELAY = request.form['late_aircraft_delay'] 29 | # WEATHER_DELAY = request.form['weather_delay'] 30 | route= request.form['route'] 31 | 32 | total = [[int(MONTH), int(DAY),int(SCHEDULED_DEPARTURE), int(DEPARTURE_DELAY),int(SCHEDULED_ARRIVAL), int(DIVERTED), int(CANCELLED),int(AIR_SYSTEM_DELAY), int(SECURITY_DELAY), int(AIRLINE_DELAY), int(LATE_AIRCRAFT_DELAY), int(WEATHER_DELAY), int(route)]] 33 | y_pred = model.predict(total) 34 | if y_pred==1: 35 | msg='Your flight will be delayed' 36 | else: 37 | msg='Your flight will be on time' 38 | return render_template("index.html", showcase = msg) 39 | 40 | 41 | if __name__ == '__main__': 42 | app.run(debug=True) -------------------------------------------------------------------------------- /Python/flight delay/res.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/flight delay/res.pkl -------------------------------------------------------------------------------- /Python/get_step_count/dataset.txt: -------------------------------------------------------------------------------- 1 | {"minStartTimeNs": "1601922600000000000", "maxEndTimeNs": "1601955096000000000", "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", "point": [{"startTimeNanos": "1601953560000000000", "endTimeNanos": "1601953897053000000", "dataTypeName": "com.google.step_count.delta", "originDataSourceId": "raw:com.google.step_count.delta:com.xiaomi.hm.health:", "value": [{"intVal": 0, "mapVal": []}], "modifiedTimeMillis": "1601954369585"}]} -------------------------------------------------------------------------------- /Python/get_step_count/readme.md: -------------------------------------------------------------------------------- 1 | # Get Steps From Google Fit 2 | 3 | ### Requirements: 4 | 5 | 1. Create a google project and get the client_id, client_secret 6 | 2. Also set the redirect_uri 7 | 3. Add the CLIENT_ID, CLIENT_SECRET, REDIRECT_URI in the index.py 8 | 9 | ``` python 10 | # Copy your credentials from the Google Developers Console 11 | CLIENT_ID = '' 12 | CLIENT_SECRET = '' 13 | # Redirect URI for installed apps 14 | REDIRECT_URI = '' 15 | ``` 16 | 4. You are all set now 17 | 18 | ## How to get steps 19 | 20 | 1. Run the index.py with ```python index.py``` 21 | 2. Copy the url and paste it in the browser 22 | 3. Then in the redirected url take the params "code" and paste it in the terminal 23 | 4. Now, you will get your step count for today 24 | 25 | ## Happy Coding, :) 26 | -------------------------------------------------------------------------------- /Python/get_step_count/requirements.txt: -------------------------------------------------------------------------------- 1 | apiclient==1.0.4 2 | google-api-python-client==1.12.2 3 | google-auth-httplib2==0.0.4 4 | httplib2==0.19.0 5 | oauth2client==4.1.3 6 | -------------------------------------------------------------------------------- /Python/is_prime.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def is_prime(number): 4 | if number <= 1: return False 5 | if number == 2: return True 6 | if (number % 2) == 0: return False 7 | 8 | for i in range(3, int(math.sqrt(number)) +1,2): 9 | if number % 1 == 0: return False 10 | return True 11 | 12 | number = input ("Enter number :") 13 | if is_prime(number): 14 | print("It is prime") 15 | else: 16 | print("It is not prime") -------------------------------------------------------------------------------- /Python/medium_article_scraper/LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Holger Dörner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Python/medium_article_scraper/README.md: -------------------------------------------------------------------------------- 1 | # mediumScreaper 2 | A screaper for Medium.com -posts 3 | 4 | This script searches on `Medium.com` for a supplied `Topic` and returns the results as `JSON`. 5 | 6 | ## Requirements Dependancies 7 | Recommendet Python-Version 8 | - `3.5+` 9 | 10 | The only external dependancy is 11 | - `BeautifulSoap` 12 | 13 | ## Installation 14 | Install the required external dependancies with 15 | 16 | ```shell 17 | $ pip3 install -r requirements.txt 18 | ``` 19 | 20 | Also, a `chmod +x medium_scraper.py` *can* be needed to make the script executable, otherwise You have to call it with `python3` (see [Usage Examples](#usage-examples)) 21 | 22 | ## Usage examples 23 | Getting help: 24 | ```shell 25 | $ (python3) medium_scraper.py -h 26 | ``` 27 | 28 | Get posts for `python`: 29 | ```shell 30 | $ (python3) medium_scraper.py python 31 | ``` 32 | 33 | Get maximum `100` posts for `software development`: 34 | ```shell 35 | $ (python3) medium_scraper.py "software development" -c 100 36 | ``` 37 | 38 | Pretty-Print the `json` output: 39 | ```shell 40 | $ (python3) medium_scraper.py python -b 41 | ``` 42 | -------------------------------------------------------------------------------- /Python/medium_article_scraper/medium_scraper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import argparse 5 | import sys 6 | import json 7 | from urllib import parse 8 | from bs4 import BeautifulSoup 9 | 10 | 11 | def parseArgs(): 12 | parser = argparse.ArgumentParser(description='Gets posts from Medium.com for a specific topic.') 13 | parser.add_argument('topic', metavar='TOPIC', type=str, 14 | help='the topic to search for') 15 | parser.add_argument('-c', '--count', dest='count', action='store', default=15, 16 | help='maximum number of posts') 17 | parser.add_argument('-b', '--beautify', dest='beautiefy', action='store_true', 18 | help='beautiefy json output') 19 | 20 | return parser.parse_args() 21 | 22 | 23 | def run(args): 24 | def parsePost(tag): 25 | title = tag.find('h3', class_='graf') 26 | desc = tag.find('p') 27 | url = tag.find_all('a')[3] 28 | return { 29 | 'title': title.text if title else '', 30 | 'desc': desc.text if desc else '', 31 | 'url': url.get('href').split('?')[0] if url else '', 32 | } 33 | 34 | urlParams = { 35 | 'topic': parse.quote(args.topic), 36 | 'count': args.count 37 | } 38 | 39 | url = 'https://medium.com/search/posts?q={topic}&count={count}'.format_map(urlParams) 40 | 41 | posts = [] 42 | 43 | response = requests.get(url) 44 | 45 | soup = BeautifulSoup(response.text, 'html.parser') 46 | rawPosts = soup.find_all('div', class_='postArticle') 47 | 48 | if len(rawPosts) > 0: 49 | for post in rawPosts: 50 | posts.append(parsePost(post)) 51 | else: 52 | print('No posts found for "%s"...' % args.topic) 53 | sys.exit(0) 54 | 55 | print(json.dumps(posts, indent=(4 if args.beautiefy else None))) 56 | 57 | 58 | if __name__ == '__main__': 59 | run(parseArgs()) 60 | -------------------------------------------------------------------------------- /Python/medium_article_scraper/requirements.txt: -------------------------------------------------------------------------------- 1 | BeautifulSoup4 -------------------------------------------------------------------------------- /Python/nbase-to-decimal-converter.py: -------------------------------------------------------------------------------- 1 | def nbase_decimal_conv(number_input, n_base): 2 | '''Converted N base number to decimal number 3 | Keyword arguments: 4 | number_input -- input memberikan angka dari N base tertentu user giving a certain N base number 5 | n_base -- user input what base of the number 6 | return: 7 | sum_num -- the sum of each digit of the power of N base 8 | ''' 9 | sum_num = 0 10 | string_user = str(number_input) 11 | 12 | string_user = string_user[::-1] 13 | for i in range(len(string_user)): 14 | formula = int(string_user[i]) * n_base ** i 15 | sum_num += formula 16 | return sum_num 17 | -------------------------------------------------------------------------------- /Python/neural network visualizer/requirements.txt: -------------------------------------------------------------------------------- 1 | required modules for neural network analyzer: 2 | tensorflow 2.x version-(keras is used) 3 | matplot lib(for graph plot) 4 | numpy 5 | streamlit(for web app) 6 | json 7 | 8 | some knowledge of above modules , machine learning and neural networks in required for this project 9 | -------------------------------------------------------------------------------- /Python/opencvtextdetection/images/sign.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshareddy794/HACKTOBERFEST2020/01ebafdf6de908786dbd5f6b79485c2c9445cc5b/Python/opencvtextdetection/images/sign.jpg -------------------------------------------------------------------------------- /Python/password_generator/README.md: -------------------------------------------------------------------------------- 1 | #Password_generator 2 | ###Overview - Generates a password of your desired length. 3 | 4 | #### Requirements - Python3 should be installed on your system. 5 | ####Steps - 6 | Download this repo to your system. 7 | 8 | Run the passgen.py in any IDE or terminal. 9 | 10 | Enter the length of password you want to generate. 11 | 12 | Your password is generated. 13 | 14 | 15 | -------------------------------------------------------------------------------- /Python/password_generator/passgen.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | 4 | up = string.ascii_uppercase 5 | lo = string.ascii_lowercase 6 | num = string.digits 7 | sym = string.punctuation 8 | 9 | len=int(input("Enter password length\n")) 10 | 11 | s= [] 12 | s.extend(list(up)) 13 | s.extend(list(lo)) 14 | s.extend(list(num)) 15 | s.extend(list(sym)) 16 | #print(s) 17 | random.shuffle(s) 18 | #print(s) 19 | print("".join(s[0:len])) -------------------------------------------------------------------------------- /Python/sorting.py: -------------------------------------------------------------------------------- 1 | # List of Integers 2 | numbers = [1, 3, 4, 2] 3 | 4 | # Sorting list of Integers 5 | numbers.sort() 6 | 7 | print(numbers) 8 | 9 | # List of Floating point numbers 10 | decimalnumber = [2.01, 2.00, 3.67, 3.28, 1.68] 11 | 12 | # Sorting list of Floating point numbers 13 | decimalnumber.sort() 14 | 15 | print(decimalnumber) 16 | 17 | # List of strings 18 | words = ["Geeks", "For", "Geeks"] 19 | 20 | # Sorting list of strings 21 | words.sort() 22 | 23 | print(words) 24 | -------------------------------------------------------------------------------- /Python/speech_recog.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | import pyttsx3 3 | 4 | # Initialize the recognizer 5 | r = sr.Recognizer() 6 | 7 | # Function to convert text to 8 | # speech 9 | def SpeakText(command): 10 | 11 | # Initialize the engine 12 | engine = pyttsx3.init() 13 | engine.say(command) 14 | engine.runAndWait() 15 | 16 | 17 | while(1): 18 | 19 | # exceptions at the runtime 20 | try: 21 | 22 | # use the microphone as source for input. 23 | with sr.Microphone() as source2: 24 | 25 | # wait for a second to let the recognizer 26 | # adjust the energy threshold based on 27 | # the surrounding noise level 28 | r.adjust_for_ambient_noise(source2, duration=0.2) 29 | audio2 = r.listen(source2) 30 | # Using ggogle to recognize audio 31 | MyText = r.recognize_google(audio2) 32 | MyText = MyText.lower() 33 | 34 | print("Did you say "+MyText) 35 | SpeakText(MyText) 36 | 37 | except sr.RequestError as e: 38 | print("Could not request results; {0}".format(e)) 39 | 40 | except sr.UnknownValueError: 41 | print("unknown error occured") 42 | -------------------------------------------------------------------------------- /Python/torrent_search/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Holger Dörner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Python/torrent_search/README.md: -------------------------------------------------------------------------------- 1 | # torrent_search.py 2 | A torrent-meta-searcher 3 | 4 | This script searches (scrapes) on multiple Torrent sites for supplied keywords and returns the results grouped by categories as `JSON`. 5 | 6 | Currently, the following sites are queried: 7 | - thepiratebay10.org 8 | - 1337x.to 9 | - torlock.com 10 | 11 | ## Requirements and Dependencies 12 | Recommendet Python-Version 13 | - `3.5+` 14 | 15 | The only external dependency are 16 | - `BeautifulSoap` 17 | - `aiohttp` 18 | 19 | ## Installation 20 | Install the required external dependencies with 21 | 22 | ```shell 23 | $ pip3 install -r requirements.txt 24 | ``` 25 | 26 | Also, a `chmod +x torrent_search.py` *can* be needed to make the script executable, otherwise You have to call it with `python3` (see [Usage Examples](#usage-examples)) 27 | 28 | ## Usage examples 29 | Getting help: 30 | ```shell 31 | $ (python3) torrent_search.py -h 32 | ``` 33 | 34 | Perform a simple search: 35 | ```shell 36 | $ (python3) torrent_search.py doom 37 | ``` 38 | 39 | Filter results with at least 20 seeders for `big bang theory`: 40 | ```shell 41 | $ (python3) torrent_search.py "big bang theory" -s 20 42 | ``` 43 | 44 | Filter by categories: 45 | ```shell 46 | $ (python3) torrent_search.py doom -c Movies Games 47 | ``` 48 | -------------------------------------------------------------------------------- /Python/torrent_search/requirements.txt: -------------------------------------------------------------------------------- 1 | BeautifulSoup4 2 | aiohttp -------------------------------------------------------------------------------- /Python/word-of-number.py: -------------------------------------------------------------------------------- 1 | #The below program is an optimized method for converting the integers to their English representations. 2 | ''' For example: 3 | >>>Enter a number34 4 | thirty four 5 | For this conversion ,a package named n2w is used.If the package is not installed in your local machine,install it using the command : 6 | >>>pip install n2w 7 | ''' 8 | def int2word(integer): # A function is defined that will take integer value as an argument and will return the String output 9 | return n2w.convert(num) 10 | if __name__ == "__main__": 11 | import n2w # the package n2w is imported for performing the number to word calculation 12 | num=input("Enter a number:") # A number is taken as input from the user 13 | print(int2word(num)) 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HACTOBERFEST2020 2 | ![hack](https://user-images.githubusercontent.com/48166328/94787275-ba253600-03ef-11eb-8822-6b34943e9104.jpeg) 3 | 4 | 5 | ## Open source contribution is always fun and exciting :star_struck: 6 | 7 | Let's make a contribution to this repository. 8 | 9 | Let me show you how easy it is: 10 | 11 | ## 1. Fork this repository 12 | 13 | Fork this repository by clicking on the fork button on the top of this page. 14 | This will create a copy of this repository in your account. 15 | 16 | --- 17 | 18 | ## 2. Clone the repository 19 | 20 | Now clone the forked repository to your machine. Go to your GitHub account, open the forked repository, click on the clone button and then click the _copy to clipboard_ icon. 21 | Now let's bring the cloned repository to your local machine. 22 | `git clone ` 23 | For example: 24 | ` git clone https://github.com/harshareddy794/HACTOBERFEST2020.git` 25 | 26 | --- 27 | 28 | ## 3. Move inside the repository 29 | 30 | Since you want to change the files inside, first let's move to the folder correctly. Use the following command on terminal: 31 | `cd HacktoberFest2020` 32 | 33 | --- 34 | 35 | ## 4. Make a new branch 36 | 37 | Since now you're about to make your personal changes to the project, it's always a better idea to make a new branch. Run the following command: 38 | 39 | `git checkout -b ` 40 | For example: 41 | `git checkout -b new_branch` 42 | 43 | --- 44 | 45 | ## 5. Make the required changes 46 | 47 | Check out the [CONTRIBUTE.md](https://github.com/harshareddy794/HACTOBERFEST2020/blob/master/CONTRIBUTING.md) file to see what all contributions can you make. 48 | 49 | --- 50 | 51 | ## 6. Commit all your Changes 52 | 53 | It's finally that time when you commit your changes and leave a beautiful commit message behind. You can run the following commands: 54 | 55 | `git add .` 56 | `git commit -m ""` 57 | For example: 58 | `git commit -m "Added a script"` 59 | 60 | Finally, push your changes to Github: 61 | To do so run the following command: 62 | 63 | `git push origin ` 64 | For example: 65 | `git push origin branch_name` 66 | 67 | --- 68 | 69 | ## 7. Hit us a pull request 70 | 71 | If you go to your repository on GitHub, you'll see a Compare & pull request button. Click on that button. 72 | Now submit the pull request. Leave a custom message if you want. 73 | 74 | --- 75 | 76 | 77 | ## Our Contributors ✨: 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /ShortestRoute Algorithms/05.Kruskal.c: -------------------------------------------------------------------------------- 1 | // source - http://dotcprograms.blogspot.com/2018/02/c-program-for-kruskals-algorithm.html 2 | #include 3 | #define MAX 30 4 | 5 | typedef struct edge 6 | { 7 | int u,v,w; 8 | }edge; 9 | 10 | typedef struct edgelist 11 | { 12 | edge data[MAX]; 13 | int n; 14 | }edgelist; 15 | 16 | edgelist elist; 17 | 18 | int G[MAX][MAX],n; 19 | edgelist spanlist; 20 | 21 | void kruskal(); 22 | int find(int belongs[],int vertexno); 23 | void union1(int belongs[],int c1,int c2); 24 | void sort(); 25 | void print(); 26 | 27 | void main() 28 | { 29 | int i,j,total_cost; 30 | 31 | printf("\nEnter number of vertices:"); 32 | 33 | scanf("%d",&n); 34 | 35 | printf("\nEnter the adjacency matrix:\n"); 36 | 37 | for(i=0;ielist.data[j+1].w) 105 | { 106 | temp=elist.data[j]; 107 | elist.data[j]=elist.data[j+1]; 108 | elist.data[j+1]=temp; 109 | } 110 | } 111 | 112 | void print() 113 | { 114 | int i,cost=0; 115 | 116 | for(i=0;i 3 | #include 4 | 5 | int n, cost[10][10]; 6 | 7 | void prim() { 8 | int i, j, startVertex, endVertex; 9 | int k, nr[10], temp, minimumCost = 0, tree[10][3]; 10 | 11 | /* For first smallest edge */ 12 | temp = cost[0][0]; 13 | for (i = 0; i < n; i++) { 14 | for (j = 0; j < n; j++) { 15 | if (temp > cost[i][j]) { 16 | temp = cost[i][j]; 17 | startVertex = i; 18 | endVertex = j; 19 | } 20 | } 21 | } 22 | /* Now we have fist smallest edge in graph */ 23 | tree[0][0] = startVertex; 24 | tree[0][1] = endVertex; 25 | tree[0][2] = temp; 26 | minimumCost = temp; 27 | 28 | /* Now we have to find min dis of each vertex from either 29 | startVertex or endVertex by initialising nr[] array 30 | */ 31 | 32 | for (i = 0; i < n; i++) { 33 | if (cost[i][startVertex] < cost[i][endVertex]) 34 | nr[i] = startVertex; 35 | else 36 | nr[i] = endVertex; 37 | } 38 | 39 | /* To indicate visited vertex initialise nr[] for them to 100 */ 40 | nr[startVertex] = 100; 41 | nr[endVertex] = 100; 42 | 43 | /* Now find out remaining n-2 edges */ 44 | temp = 99; 45 | for (i = 1; i < n - 1; i++) { 46 | for (j = 0; j < n; j++) { 47 | if (nr[j] != 100 && cost[j][nr[j]] < temp) { 48 | temp = cost[j][nr[j]]; 49 | k = j; 50 | } 51 | } 52 | /* Now i have got next vertex */ 53 | tree[i][0] = k; 54 | tree[i][1] = nr[k]; 55 | tree[i][2] = cost[k][nr[k]]; 56 | minimumCost = minimumCost + cost[k][nr[k]]; 57 | nr[k] = 100; 58 | 59 | /* Now find if k is nearest to any vertex 60 | than its previous near value */ 61 | 62 | for (j = 0; j < n; j++) { 63 | if (nr[j] != 100 && cost[j][nr[j]] > cost[j][k]) 64 | nr[j] = k; 65 | } 66 | temp = 99; 67 | } 68 | /* Now i have the answer, just going to print it */ 69 | printf("\nThe min spanning tree is:- "); 70 | for (i = 0; i < n - 1; i++) { 71 | for (j = 0; j < 3; j++) 72 | printf("%d", tree[i][j]); 73 | printf("\n"); 74 | } 75 | 76 | printf("\nMin cost : %d", minimumCost); 77 | } 78 | 79 | void main() { 80 | int i, j; 81 | clrscr(); 82 | 83 | printf("\nEnter the no. of vertices :"); 84 | scanf("%d", &n); 85 | 86 | printf("\nEnter the costs of edges in matrix form :"); 87 | for (i = 0; i < n; i++) 88 | for (j = 0; j < n; j++) { 89 | scanf("%d", &cost[i][j]); 90 | } 91 | 92 | printf("\nThe matrix is : "); 93 | for (i = 0; i < n; i++) { 94 | for (j = 0; j < n; j++) { 95 | printf("%d\t", cost[i][j]); 96 | } 97 | printf("\n"); 98 | } 99 | prim(); 100 | getch(); 101 | } -------------------------------------------------------------------------------- /ShortestRoute Algorithms/shortest Path.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | #define vertex 7 6 | int minimumDist(int dist[], bool Dset[]) 7 | { 8 | int min=INT_MAX,index; 9 | for(int v=0;v 2 | using namespace std; 3 | int Knight(int n,int a,int b){ 4 | vector> cache(n,vector(n,INT_MAX)); 5 | queue> q; 6 | q.push(make_pair(0, 0)); 7 | cache[0][0]=0; 8 | while (!q.empty()){ 9 | pair position=q.front(); 10 | q.pop(); 11 | int currentCounter = cache[position.first][position.second]+1; 12 | vector> nextPositions={ 13 | make_pair(position.first + a, position.second + b), 14 | make_pair(position.first - a, position.second + b), 15 | make_pair(position.first - a, position.second - b), 16 | make_pair(position.first + a, position.second - b), 17 | make_pair(position.first + b, position.second + a), 18 | make_pair(position.first - b, position.second + a), 19 | make_pair(position.first - b, position.second - a), 20 | make_pair(position.first + b, position.second - a) 21 | }; 22 | for (int i=0;i tmp=nextPositions[i]; 24 | int x=tmp.first,y=tmp.second; 25 | if (0<=x && x<=n-1 && 0<=y && y<=n-1){ 26 | if (cache[x][y]>currentCounter){ 27 | cache[x][y]=currentCounter; 28 | q.push(make_pair(x,y)); 29 | } 30 | } 31 | } 32 | } 33 | if (cache[n-1][n-1]==INT_MAX){ 34 | return -1; 35 | } 36 | return cache[n-1][n-1]; 37 | } 38 | int main(){ 39 | int n; 40 | cin>>n; 41 | for(int i=1;i 2 | #include 3 | 4 | void remove_space(char str[]){ 5 | int i,l=0; 6 | // char j[100]; 7 | for(i=0;str[i]!='\0';++i) 8 | { 9 | if((str[i]>='a'&& str[i]<='z')||(str[i]=='A'&& str[i]=='Z')){ 10 | 11 | str[l++]=str[i]; 12 | 13 | } 14 | else{ 15 | ++i; 16 | } 17 | // l++; 18 | } 19 | str[l]='\0'; 20 | puts(str); 21 | } 22 | 23 | int main() 24 | { 25 | 26 | char str[100]; 27 | printf("Enter all the char : "); 28 | gets(str); 29 | remove_space(str); 30 | // puts(str); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /competative coding/rotation.c: -------------------------------------------------------------------------------- 1 | #include 2 | void rotate( int arr[],int arr_size, int arr_rot); 3 | void print_arr(int arr[], int n); 4 | int main() { 5 | //code 6 | int test_case, arr_size, arr_rot,arr[100],i; 7 | printf("hello"); 8 | scanf("%d",&test_case); 9 | scanf("%d %d",&arr_size,&arr_rot); 10 | for(int i =0;i ",arr[i-1]); 18 | // } 19 | 20 | // printf("%d",arr[i]); 21 | printf("Before rotation \n"); 22 | print_arr(arr,arr_size); 23 | 24 | 25 | for(i=0;i ",arr[i]); 52 | } 53 | } -------------------------------------------------------------------------------- /competative coding/toggleEachChar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main(){ 5 | char str[30]; 6 | printf("Enter the string "); 7 | gets(str); 8 | // scanf("%s",str); 9 | 10 | for(int i=0;str[i];i++){ 11 | if(str[i]>='a' && str[i]<='z') 12 | str[i]=str[i]-32; 13 | else if (str[i]>='A' && str[i]<='Z') 14 | { 15 | str[i]=str[i]+32; 16 | } 17 | } 18 | 19 | 20 | // printf("%s",str); 21 | puts(str); 22 | 23 | } --------------------------------------------------------------------------------