├── Assembly 8086 └── hello_world.asm ├── Bash ├── add.sh ├── calculator.sh ├── fibonacci.sh ├── forloop.sh ├── hello.sh ├── ifstatement.sh ├── nmap_find_hostname.sh ├── odd_or_even.sh ├── palindrome.sh ├── prime_number.sh ├── stringOperators.sh └── yesno.sh ├── C code_gcd of two numbers ├── C# ├── Animal_OOP.cs ├── BubbleSort.csproj ├── BubbleSort.sln ├── Cat_OOP.cs ├── Fibonacci.cs ├── Palindrome.cs ├── Pet_OOP.cs ├── Program.cs ├── Program_OOP.cs ├── RecursiveFactorial.cs └── SimpleStats.cs ├── C ├── BST_operations.c ├── Cal_Diff_ Btwn_ 2_Time_Periods.c ├── Hello-World.c ├── Leap Year.c ├── LinearSearch.c ├── Mario_stairs.c ├── MergeSort.c ├── Merge_Algorithm.c ├── Postfix_Expression_Evaluation.c ├── anagram.c ├── binary to decimal conversion.c ├── countinv.c ├── cqueue.c ├── dijkstra.c ├── doubly linked list program all operations.c ├── guessing_game.c ├── helloworld.c ├── insertion.c ├── min add.c ├── n_queen.c ├── palindrome.c ├── password_strength.c ├── quicksort.c ├── selection.c ├── single link list.c ├── stack simple progrom.c ├── stack.c ├── toh.c ├── vigenere.c └── writefile.c ├── CPP ├── 0-1_knapsack_problem_dp.cpp ├── 1 LINEAR.CPP ├── 10 WORD_A.CPP ├── 11 TRANSPOSE.cpp ├── 12 TRAVER~1.CPP ├── 13 CLASS1.CPP ├── 14 CLASS2.CPP ├── 15 CLASS3.CPP ├── 16 FUNOVE.CPP ├── 17 RECMEN.CPP ├── 18 CALLREF.CPP ├── 19 CALLVA.CPP ├── 1D ARRAY │ ├── ARR1.CPP │ ├── ARR2.CPP │ ├── ARR3.CPP │ ├── ARR4.CPP │ └── ARR5.CPP ├── 2 BINARY.CPP ├── 2 D ARRAY │ ├── 2DA1.CPP │ ├── 2DA10.CPP │ ├── 2DA11.CPP │ ├── 2DA2.CPP │ ├── 2DA3.CPP │ ├── 2DA4.CPP │ ├── 2DA5.CPP │ ├── 2DA6.CPP │ ├── 2DA7.CPP │ └── 2DA8.CPP ├── 20 SWAR.CPP ├── 21 SWAR1.CPP ├── 22 AREO.CPP ├── 23 ARREV.CPP ├── 24 ARSQ.CPP ├── 25 ARR1.CPP ├── 3 BUBBLE.CPP ├── 4 SELECTIO.CPP ├── 5 SUMMATRI.CPP ├── 6 DIFMATRI.CPP ├── 7 COUNTA~1.CPP ├── 8 COUNTL~1.CPP ├── 9 COUNTW~1.CPP ├── Balanced-Brackets.cpp ├── Candies.cpp ├── LL.CPP ├── Largest Rectangle.cpp ├── Max Array Sum.cpp ├── Palindrome.cpp ├── SeiveOfEratosthenes ├── arrayofstruct.cpp ├── binary_search.cpp ├── binarysearchtree.cpp ├── bool.cpp ├── cardSuitRank.cpp ├── checking prime number.cpp ├── checking.cpp ├── class.cpp ├── dataLoop.cpp ├── dataLoop.h ├── deleteNodeinLinkedList.cpp ├── depthFirstSearch.cpp ├── dfs_inorder.cpp ├── doubeEndedQueue.cpp ├── factorial.cpp ├── fibonacci.cpp ├── fibonacci_dp.cpp ├── first.cpp ├── focalLength.cpp ├── goingPostal.cpp ├── goingPostal.h ├── insertNodeInLinkedList.cpp ├── insertionInCircularLinkedList.cpp ├── linkedlist.cpp ├── lltraverseRecursion.cpp ├── mergesort.cpp ├── nos.cpp ├── pointer.cpp ├── pointers.cpp ├── pointerstostructures.cpp ├── printing pyramid.cpp ├── priorityqueue.cpp ├── radix-sort.cpp ├── references.cpp ├── rsadecrypt.cpp ├── searchNodeElement.cpp ├── short.cpp ├── sparsmatrix.cpp ├── spiral_matrix.cpp ├── string.cpp ├── strinput.cpp ├── structure.cpp ├── sumNums.cpp ├── ternary_search.cpp ├── text.cpp └── userinput.cpp ├── Dart └── hello_world.dart ├── Go ├── ascii-art │ ├── main.go │ └── standart.txt ├── capitalize.go ├── deck_of_cards.go ├── fibonacci_series.go ├── hello_world.go ├── read_csv.go ├── send_email.go └── sieve_of_erathostenes.go ├── HTML ├── ForIf.html ├── HTML PROTFOLIO │ ├── Saha.html │ └── saha.css ├── alert.html ├── atmfinder.html ├── bg.jpeg ├── do.html ├── for.html ├── function.html ├── hello_world.html ├── matrix.html ├── onChange.html ├── operators.html ├── partial.php ├── partialpagerefresh.html ├── sharingan.html ├── style.css └── while.html ├── JAVA ├── DiameterOfBinaryTree.java ├── DiamondPattern.java ├── DoubleLinkedListImplementation.java ├── FibonacciSeries.java ├── FindPalindrome.java ├── Floyd_algorithm.java ├── LifeGame.java ├── LinearSearch.java ├── Pi_MonteCarlo.java ├── Program to calculate power of a number using for loop ├── ReverseInteger.java ├── ReverseString.java ├── SwapNumbers.java ├── TowerOfHanoi.java ├── VowelConsonant.java ├── merge_sort │ ├── .idea │ │ ├── description.html │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── project-template.xml │ │ └── workspace.xml │ ├── merge_sort.iml │ ├── out │ │ └── production │ │ │ └── merge_sort │ │ │ └── com │ │ │ └── sunchit │ │ │ └── company │ │ │ └── Main.class │ └── src │ │ └── com │ │ └── sunchit │ │ └── company │ │ └── Main.java ├── palindrome.java └── quick_sort │ ├── .idea │ ├── description.html │ ├── encodings.xml │ ├── misc.xml │ ├── modules.xml │ ├── project-template.xml │ └── workspace.xml │ ├── out │ └── production │ │ └── quick_sort │ │ └── com │ │ └── sunchit │ │ └── company │ │ └── Main.class │ ├── quick_sort.iml │ └── src │ └── com │ └── sunchit │ └── company │ └── Main.java ├── JavaScript ├── Prime_No_finder.js ├── arrayOfCars.js ├── average.js ├── couponWithMap.js ├── finishCartWithFilterMapReduce.js ├── helloworld.js ├── reverseInt.js ├── reverseString.js ├── selectCategoryWithFilter.js ├── settimeout.js ├── string-case-conversor.js ├── sum-array.js └── totalValueWithReduce.js ├── Kotlin ├── CurrentTime.kt ├── check_palindrome_num.kt ├── fibonaaci.kt ├── find_num_in_array.kt ├── is_pangram.kt └── string_to_date.kt ├── OCaml └── len.ml ├── PHP └── helloworld.php ├── Python ├── 29.Word_Count.py ├── 8.Sum_of_Root_To_Leaf_Binary_Numbers.py ├── Abracadabra.py ├── BlacknWhite_WebCam.py ├── BubbleSort.py ├── Calculator.py ├── ControlFlow.py ├── Cops And Robber.py ├── CountingSort.py ├── Face_Detection_In_Live_Webcam.py ├── Face_Extractor_In_Live_Webcam.py ├── FindQuotedWords.py ├── Geometric_Sum.py ├── Google API │ ├── README.md │ ├── geodump.py │ ├── geoload.py │ ├── where.html │ └── where.js ├── Heap_sort.py ├── InsertionSort.py ├── Length_of_Linked_List.py ├── Link_shortner.py ├── MRO.py ├── Maitreyi88_armstrongno.py ├── Maitreyi88_fibonacci.py ├── Maitreyi88_palindrome.py ├── Maitreyi88_primeno.py ├── MergeSort.py ├── RandomNumberGenerator.py ├── Selection_sort.py ├── Speech_Recognition.py ├── SudokuSolver.py ├── TRIE.py ├── annflask.py ├── armstrong.py ├── array.py ├── balanced_paranthesis.py ├── binary_tree.py ├── break_time.py ├── browser_search.py ├── bubbleSort.py ├── calccc.py ├── calci.py ├── cash.py ├── centsChange.py ├── circle_intersect │ ├── README.md │ └── State_check.py ├── curr_conv.py ├── delete_reoccurring.py ├── dijkstra.py ├── face_recognition.py ├── factorial.py ├── fashionmnist.ipynb ├── fibonacci.py ├── flaskapp.py ├── flipString.py ├── flipkartScraper.py ├── functions.py ├── funny.py ├── generate_all_paths_graph.py ├── graph.py ├── haar_classifiers_for_Image_Processing │ ├── haarcascade_car.xml │ ├── haarcascade_eye.xml │ ├── haarcascade_frontalface_default.xml │ └── haarcascade_fullbody.xml ├── hack wifi_password.py ├── hello.py ├── hello_flask.py ├── helloworld.py ├── higher_or_lower.py ├── instagram_profile_detail.py ├── jump.py ├── lan_search.py ├── list_demo.py ├── list_examples.py ├── matrix.py ├── minimum_spanning_tree.py ├── movement_detection_opencv.py ├── mutation.py ├── nCr.py ├── notification.py ├── nth_fibonacci.py ├── number_representation.py ├── ocr.py ├── odd_or_even.py ├── orm.py ├── palindrome.py ├── ploter.py ├── polymorphism_python.py ├── prime_number.py ├── profanity_checker.py ├── punctuation.py ├── quicksort.py ├── radare.py ├── regular_expression ├── reverse_string.py ├── run-flask.py ├── send_mail.py ├── send_text.py ├── sentiment_Analysis.py ├── setex.py ├── speed_test.py ├── sum_lst_index.py ├── tic_tac.py ├── tuplex.py ├── twitter_functions.py ├── var_cons.py ├── vowel checker.py ├── web.py └── word-cloud.py ├── R ├── factorial_using_recursion.r ├── hello_world.r ├── lists.r └── uniform_distribution.r ├── README.md ├── Ruby ├── factorial.rb ├── hello_world.rb └── quicksort.rb └── Swift ├── Hello.World.swift ├── String+Anagram.swift └── fibonacci.swift /Assembly 8086/hello_world.asm: -------------------------------------------------------------------------------- 1 | ; multi-segment executable file template. 2 | 3 | data segment 4 | ; add your data here! 5 | pkey db "Hello world$" 6 | ends 7 | 8 | stack segment 9 | dw 128 dup(0) 10 | ends 11 | 12 | code segment 13 | start: 14 | ; set segment registers: 15 | mov ax, data 16 | mov ds, ax 17 | mov es, ax 18 | 19 | ; add your code here 20 | 21 | lea dx, pkey 22 | mov ah, 9 23 | int 21h ; output string at ds:dx 24 | 25 | mov ax, 4c00h ; exit to operating system. 26 | int 21h 27 | ends 28 | 29 | end start ; set entry point and stop the assembler. 30 | -------------------------------------------------------------------------------- /Bash/add.sh: -------------------------------------------------------------------------------- 1 | echo "enter two number" 2 | 3 | read number_1 4 | read number_2 5 | 6 | sum=$((number_1 + number_2)) 7 | 8 | echo "the sum is = $sum" 9 | 10 | -------------------------------------------------------------------------------- /Bash/calculator.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | 3 | # Take user Input 4 | echo "Enter Two numbers : " 5 | read a 6 | read b 7 | 8 | # Input type of operation 9 | echo "Enter Choice :" 10 | echo "1. Addition" 11 | echo "2. Subtraction" 12 | echo "3. Multiplication" 13 | echo "4. Division" 14 | read ch 15 | 16 | # Switch Case to perform 17 | # calulator operations 18 | case $ch in 19 | 1)res=`echo $a + $b | bc` 20 | ;; 21 | 2)res=`echo $a - $b | bc` 22 | ;; 23 | 3)res=`echo $a \* $b | bc` 24 | ;; 25 | 4)res=`echo "scale=2; $a / $b" | bc` 26 | ;; 27 | esac 28 | echo "Result : $res" 29 | -------------------------------------------------------------------------------- /Bash/fibonacci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function fibonacci { 4 | : ' 5 | This function will return n-th fibonacci number. 6 | input: integer 7 | output: integer 8 | 9 | Function Description: 10 | f(n) = f(n - 1) + f(n - 2) 11 | f(0) = 0, f(1) = 1 12 | 13 | Time Complexity: O(n) 14 | Space Complexity O(1) 15 | ' 16 | 17 | n=$1 18 | if [ $n -eq 1 ]; then 19 | return 0 20 | elif [ $n -eq 2 ]; then 21 | return 1 22 | else 23 | a=0; b=1; res=1; 24 | for ((i=3; i<=n; i++)); do 25 | ((res = a + b)) 26 | a=$b; b=$res; 27 | done 28 | return $res 29 | fi 30 | } 31 | 32 | # User input with message 33 | read -p "Enter any number " num 34 | 35 | # nth Fibonacci number 36 | fibonacci $num res 37 | echo "Fibonacci number is : $res" 38 | -------------------------------------------------------------------------------- /Bash/forloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in {0..3} 4 | do 5 | echo "Number: $i" 6 | done 7 | -------------------------------------------------------------------------------- /Bash/hello.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | echo Hello World # echo is used to print in consol 5 | 6 | 7 | echo "Hello World" # you can also use "" to print stuff 8 | -------------------------------------------------------------------------------- /Bash/ifstatement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -n "Input a number: " 4 | read num 5 | 6 | if [[ $num -gt 10 ]] 7 | then 8 | echo "The number is greater than 10." 9 | fi 10 | -------------------------------------------------------------------------------- /Bash/nmap_find_hostname.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #### Script finds UP hosts and its HOSTNAME 3 | #### Usage: 4 | #### sh nmap_find_hostname.sh IP/MASK 5 | #### eg.: sh nmap_find_hostname.sh 192.168.0.0/16 6 | 7 | nmap -sn $1 -oG - | awk '$4=="Status:" && $5=="Up" {print $2, $3}' 8 | -------------------------------------------------------------------------------- /Bash/odd_or_even.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Take use input 4 | echo "Enter number: " 5 | read a 6 | 7 | if (( $a % 2 )); then 8 | echo $a "is odd" 9 | else 10 | echo $a "is even" 11 | fi 12 | -------------------------------------------------------------------------------- /Bash/palindrome.sh: -------------------------------------------------------------------------------- 1 | echo "Enter a number: " 2 | read num 3 | 4 | # Storing the remainder 5 | s=0 6 | 7 | # Store number in reverse 8 | # order 9 | rev="" 10 | 11 | # Store original number 12 | # in another variable 13 | temp=$num 14 | 15 | while [ $num -gt 0 ] 16 | do 17 | # Get Remainder 18 | s=$(( $num % 10 )) 19 | 20 | # Get next digit 21 | num=$(( $num / 10 )) 22 | 23 | # Store previous number and 24 | # current digit in reverse 25 | rev=$( echo ${rev}${s} ) 26 | done 27 | 28 | if [ $temp -eq $rev ]; 29 | then 30 | echo "Number is palindrome" 31 | else 32 | echo "Number is NOT palindrome" 33 | fi 34 | 35 | -------------------------------------------------------------------------------- /Bash/prime_number.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Enter the number" 4 | read number 5 | two=2 6 | zero=0 7 | 8 | while [ $two -lt $number ] 9 | do 10 | s=`expr $number % $two` 11 | if [ $s -eq $zero ] 12 | then 13 | echo $number" is not a prime number" 14 | exit 15 | else 16 | i=`expr $two + 1` 17 | fi 18 | done 19 | 20 | echo $number " is a pime number" 21 | -------------------------------------------------------------------------------- /Bash/stringOperators.sh: -------------------------------------------------------------------------------- 1 | string_null="" 2 | string1="string1" 3 | 4 | if [ $string_null -n ] 5 | then 6 | echo "not null string" 7 | else 8 | echo "null string" 9 | fi 10 | 11 | if [ $string_null -z ] 12 | then 13 | echo "null string" 14 | else 15 | echo "not null string" 16 | fi 17 | 18 | if [ "$string_null" == "$string1" ] 19 | then 20 | echo "strings equal" 21 | else 22 | echo "strings not equal" 23 | fi 24 | 25 | if [ "$string_null" != "$string1" ] 26 | then 27 | echo "strings not equal" 28 | else 29 | echo "strings equal" 30 | fi -------------------------------------------------------------------------------- /Bash/yesno.sh: -------------------------------------------------------------------------------- 1 | 2 | # A script to implement a simple yes/no dialog in the native shell. 3 | # 4 | # bash yesno.sh "" [y|n] 5 | # 6 | # Takes two positional parameters: 7 | # - text: The question to ask, in quotes; 8 | # - default: The default option (y or n) to prefer. 9 | # 10 | # If a default option has been provided, pressing enter while entering nothing will return the default 11 | # answer. Otherwise, the dialog will be repeated until a suitable answer is provided by the user. 12 | # 13 | # Returns 0 if "yes", 1 otherwise. 14 | # 15 | # Example: 16 | # bash yesno.sh "Answer yes to this and X will appear in your terminal!" y && echo X 17 | 18 | uppercase() { 19 | echo "$1" | tr '[:lower:]' '[:upper:]' | tail -n +1 20 | } 21 | 22 | yesno() { 23 | 24 | text="$1" 25 | default="$2" 26 | 27 | default=$(echo $default | grep . || echo ' ') 28 | 29 | answers=$(echo y/n | sed -e "s/$default/`uppercase $default`/") 30 | 31 | question="$text ($answers)" 32 | 33 | while true; do 34 | read -p "$question" yn 35 | 36 | case $yn in 37 | [Yy]|yes) echo "$yn" || $default; return;; 38 | [Nn]|no) return;; 39 | *) echo $default | grep . && return || echo;; 40 | esac 41 | 42 | done 43 | } 44 | 45 | yesno "$@" | grep -oi y || exit 1 46 | -------------------------------------------------------------------------------- /C code_gcd of two numbers: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int divisor,dividend,remainder,num1,num2; 5 | printf("\n enter two numbers \n "); 6 | scanf("\n %d \n %d",&num1,&num2); 7 | if(num1>num2) 8 | { 9 | dividend=num1; 10 | divisor=num2; 11 | } 12 | else 13 | { 14 | divisor=num1; 15 | dividend=num2; 16 | } 17 | while(divisor>0) 18 | { 19 | remainder=dividend%divisor; 20 | dividend=divisor; 21 | divisor=remainder; 22 | } 23 | printf("the gcd is %d",dividend); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C#/Animal_OOP.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacktoberfest 4 | { 5 | // Abstraction 6 | public abstract class Animal 7 | { 8 | private const int AGE_MAX = 100; 9 | private const int AGE_MIN = 0; 10 | private const int AGE_DEFAULT = 0; 11 | 12 | // Encapsulation 13 | private string name; 14 | private int age; 15 | 16 | protected Animal(string name, int age) 17 | { 18 | this.name = name; 19 | this.age = age; 20 | } 21 | 22 | 23 | public string Name 24 | { 25 | get { return name; } 26 | set { name = value; } 27 | } 28 | 29 | public int Age 30 | { 31 | get { return age; } 32 | set 33 | { 34 | if (value >= AGE_MIN && value <= AGE_MAX) 35 | { 36 | age = value; 37 | } 38 | else 39 | { 40 | age = AGE_DEFAULT; 41 | } 42 | } 43 | } 44 | 45 | public abstract string MakeASound(); 46 | 47 | public override string ToString() 48 | { 49 | return string.Format("Name: {0}\nAge: {1}\nSound: {2}", name, age, MakeASound()); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /C#/BubbleSort.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /C#/BubbleSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29306.81 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BubbleSort", "BubbleSort.csproj", "{9964E7A4-A6EB-4A6B-B2F3-89AE9CC8DF8F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9964E7A4-A6EB-4A6B-B2F3-89AE9CC8DF8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {9964E7A4-A6EB-4A6B-B2F3-89AE9CC8DF8F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {9964E7A4-A6EB-4A6B-B2F3-89AE9CC8DF8F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {9964E7A4-A6EB-4A6B-B2F3-89AE9CC8DF8F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {35F200AC-2FEC-4EF9-89A6-3F33213C4DF8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /C#/Cat_OOP.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacktoberfest 4 | { 5 | // Inheritance 6 | class Cat : Pet 7 | { 8 | public Cat(string name, int age, string owner) : base(name, age, owner) 9 | { 10 | } 11 | 12 | public void DrinkMilk() 13 | { 14 | Console.WriteLine("Drinking milk..."); 15 | } 16 | 17 | public override string MakeASound() 18 | { 19 | return "meow"; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return string.Format("Cat\n{0}", base.ToString()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /C#/Fibonacci.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Security.Principal; 4 | 5 | class Fibonacci 6 | { 7 | /// 8 | /// Compute nth value in Fibonacci sequence 9 | /// 10 | public static uint ComputeNth(uint i) 11 | { 12 | return (i < 2) ? i : ComputeNth(i, 2, 0, 1); 13 | } 14 | 15 | private static uint ComputeNth(uint i, int current, uint prev1, uint prev2) 16 | { 17 | var sum = prev1 + prev2; 18 | return (current >= i) ? sum : ComputeNth(i, current + 1, prev2, sum); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /C#/Palindrome.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | class TextMethods 5 | { 6 | /// 7 | /// Ask user for a word then see if it is a palindrome 8 | /// 9 | public static void Palindrome() 10 | { 11 | bool result = false; 12 | 13 | Console.WriteLine("Enter a word: "); 14 | var value = Console.ReadLine(); 15 | 16 | if (!String.IsNullOrEmpty(value)) 17 | { 18 | var temp = value.ToLower().Trim(); 19 | var rev = temp.Reverse().ToArray(); 20 | 21 | for (var n = 0; n < rev.Length; n++) 22 | { 23 | if (rev[n] != temp[n]) break; 24 | result = (n == rev.Length - 1); 25 | } 26 | } 27 | 28 | Console.WriteLine($"{value} is {(!result ? "NOT " : "")}a palindrome"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /C#/Pet_OOP.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacktoberfest 4 | { 5 | // Inheritance 6 | public abstract class Pet : Animal 7 | { 8 | private string owner; 9 | 10 | protected Pet(string name, int age, string owner) : base(name, age) 11 | { 12 | this.owner = owner; 13 | } 14 | 15 | public string Owner 16 | { 17 | get { return owner; } 18 | set { owner = value; } 19 | } 20 | 21 | public override string ToString() 22 | { 23 | return string.Format("{0}\nOwner: {1}", base.ToString(), owner); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /C#/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BubbleSort 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Bubble sort algorithm"); 10 | 11 | int[] array = { 20, 50, 10, 70, 100, 60, 30, 40, 90, 80 }; 12 | 13 | Console.WriteLine("Array before sort:"); 14 | for (int i = 0; i < array.Length; i++) 15 | { 16 | Console.Write(array[i] + " "); 17 | } 18 | 19 | for (int i = 0; i < array.Length; i++) 20 | { 21 | for (int j = 0; j < array.Length - 1; j++) 22 | { 23 | if (array[j] > array[j + 1]) 24 | { 25 | int temp = array[j + 1]; 26 | array[j + 1] = array[j]; 27 | array[j] = temp; 28 | } 29 | } 30 | } 31 | 32 | Console.WriteLine("\nArray after sort:"); 33 | for (int i = 0; i < array.Length; i++) 34 | { 35 | Console.Write(array[i] + " "); 36 | } 37 | 38 | Console.Write("\nEnter any key to continue: "); 39 | Console.ReadKey(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /C#/Program_OOP.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacktoberfest 4 | { 5 | public class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | // Polymorphism 10 | Animal a = new Cat("Tom", 20, "David"); 11 | Console.WriteLine(a); 12 | 13 | // In order to use the DrinkMilk method, a casting is needed. 14 | ((Cat)a).DrinkMilk(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /C#/RecursiveFactorial.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RecursiveFactorial 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Enter limit: "); 10 | Console.WriteLine(recursiveFactorial(Int32.Parse(Console.ReadLine()))); 11 | } 12 | 13 | static int recursiveFactorial(int input) 14 | { 15 | return (input == 1 || input == 0) ? 1 : input * recursiveFactorial(input - 1); 16 | } 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /C#/SimpleStats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | class SimpleStats 4 | { 5 | /// 6 | /// Ask user to enter numbers then compute the average 7 | /// of those numbers 8 | /// 9 | public static void ComputeAverage() 10 | { 11 | double total = 0, counter = 0; 12 | 13 | // display instructions 14 | Console.WriteLine("I will compute the average of numbers."); 15 | Console.WriteLine("Enter as many numbers as you want,"); 16 | Console.WriteLine("Or press enter to see the result.\n\n"); 17 | Console.WriteLine("Start entering numbers: "); 18 | 19 | // get input from user 20 | while (true) 21 | { 22 | double temp; 23 | var value = Console.ReadLine(); 24 | if (String.IsNullOrEmpty(value)) break; 25 | if (double.TryParse(value, out temp)) 26 | { 27 | total += temp; 28 | counter++; 29 | } 30 | } 31 | 32 | // display result 33 | if (counter > 0) 34 | { 35 | var avg = total / counter; 36 | Console.WriteLine($"You entered {counter} valid numbers."); 37 | Console.WriteLine($"Average {avg:N2}."); 38 | } 39 | else 40 | { 41 | Console.WriteLine("You did not enter any valid numbers."); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /C/Hello-World.c: -------------------------------------------------------------------------------- 1 | //This is a basic program of language C 2 | 3 | #include 4 | int main() 5 | { 6 | printf("Hello World!"); 7 | printf("\nHi"); 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /C/Leap Year.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) { 4 | 5 | int A; 6 | 7 | printf("Enter the desired year: \n"); 8 | scanf("%d", &A); 9 | 10 | if(A%4 == 0 || A%4 != 0 && A%400 == 0){ 11 | printf("This year is leap. \n"); 12 | } 13 | else{ 14 | printf("This year isn't leap. \n"); 15 | } 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C/LinearSearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int a[20],i,n,pos=-1,key; 6 | printf("Enter the number of elements in the given linear list:\n"); 7 | scanf("%d",&n); 8 | printf("Enter the elements in the list:\n"); 9 | for(i=0;i 2 | int main() 3 | { 4 | int n; 5 | printf("Enter the number of stairs required\n"); 6 | scanf("%d",&n); 7 | for(int i = 0; i < n; i++) 8 | { 9 | for(int j = 0; j <= i; j++) 10 | { 11 | printf("#"); 12 | } 13 | printf("\n"); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/MergeSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void merge(int arr[], int l, int m, int r) 5 | { 6 | int i, j, k; 7 | int n1 = m - l + 1; 8 | int n2 = r - m; 9 | 10 | 11 | int L[n1], R[n2]; 12 | 13 | 14 | for (i = 0; i < n1; i++) 15 | L[i] = arr[l + i]; 16 | for (j = 0; j < n2; j++) 17 | R[j] = arr[m + 1+ j]; 18 | 19 | 20 | i = 0; 21 | j = 0; 22 | k = l; 23 | while (i < n1 && j < n2) 24 | { 25 | if (L[i] <= R[j]) 26 | { 27 | arr[k] = L[i]; 28 | i++; 29 | } 30 | else 31 | { 32 | arr[k] = R[j]; 33 | j++; 34 | } 35 | k++; 36 | } 37 | 38 | 39 | while (i < n1) 40 | { 41 | arr[k] = L[i]; 42 | i++; 43 | k++; 44 | } 45 | 46 | 47 | while (j < n2) 48 | { 49 | arr[k] = R[j]; 50 | j++; 51 | k++; 52 | } 53 | } 54 | 55 | 56 | void mergeSort(int arr[], int l, int r) 57 | { 58 | if (l < r) 59 | { 60 | 61 | int m = l+(r-l)/2; 62 | 63 | 64 | mergeSort(arr, l, m); 65 | mergeSort(arr, m+1, r); 66 | 67 | merge(arr, l, m, r); 68 | } 69 | } 70 | 71 | int main() 72 | { 73 | int n,i,j; 74 | scanf("%d", &n); 75 | 76 | int a[n]; 77 | 78 | for(i=0;i 2 | int binarySearch(int[],int,int,int); 3 | int main(){ 4 | int n1,n2,i,j=0,k=0,item,count=0; 5 | printf("enter number of elements in 1st array\n"); 6 | scanf("%d",&n1); 7 | printf("enter number of elements in 2nd array\n"); 8 | scanf("%d",&n2); 9 | int a[n1],b[n2]; 10 | printf("enter values of 1st array (sorted)\n"); 11 | for (i=0;i= l) { 69 | int mid = l + (r - l) / 2; 70 | if (arr[mid] == x) 71 | return 1; 72 | if (arr[mid] > x) 73 | return binarySearch(arr, l, mid - 1, x); 74 | return binarySearch(arr, mid + 1, r, x); 75 | } 76 | return -1; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /C/Postfix_Expression_Evaluation.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | 4 | int stack[100],top=-1; 5 | 6 | void push(int data){ 7 | top++; 8 | stack[top]=data; 9 | } 10 | 11 | int pop(){ 12 | int temp = stack[top]; 13 | top--; 14 | return temp; 15 | } 16 | 17 | int main(){ 18 | char exp[100],tStr[20]; 19 | int tKey=0; 20 | printf("Enter a postfix expression.\n"); 21 | gets(exp); 22 | int i; 23 | for(i=0;exp[i]!='\0';i++){ 24 | if(exp[i] = ' '){ 25 | int k=0; 26 | int j; 27 | for(j=tKey;j 7 | #include 8 | #include 9 | 10 | void main() { 11 | char word[100], word1[100]; 12 | int l1, l2, i, s1 = 0, s2 = 0; 13 | printf("*************Program to Check for Anangrams*************\n"); 14 | printf("Enter the first word: \n"); 15 | gets(word); 16 | printf("Enter the second word: \n"); 17 | gets(word1); 18 | l1 = strlen(word); 19 | l2 = strlen(word1); 20 | for (i = 0; i < l1; i++) { 21 | s1 = s1 + (int) word[i]; 22 | } 23 | for (i = 0; i < l2; i++) { 24 | s2 = s2 + (int) word1[i]; 25 | } 26 | if (s1 == s2) { 27 | printf("The words are Anagrams! \n"); 28 | } else { 29 | printf("The Words are not Anagrams! \n"); 30 | } 31 | getch(); 32 | } 33 | -------------------------------------------------------------------------------- /C/binary to decimal conversion.c: -------------------------------------------------------------------------------- 1 | #include 2 | int bintodec(int n); 3 | 4 | bintodec(int n) 5 | { 6 | 7 | if(n==0) 8 | { 9 | return 0; 10 | } 11 | else{ 12 | return n%10+bintodec(n/10*2); 13 | } 14 | } 15 | int main() 16 | { 17 | int bin, res; 18 | printf("Enter the binary number = "); 19 | scanf("%d",&bin); 20 | res = bintodec(bin); 21 | printf("The equivalent decimal = %d",res); 22 | } 23 | -------------------------------------------------------------------------------- /C/countinv.c: -------------------------------------------------------------------------------- 1 | #include 2 | int getInvCount(int arr[], int n) 3 | { 4 | int inv_count = 0; 5 | for (int i = 0; i < n - 1; i++) 6 | for (int j = i + 1; j < n; j++) 7 | if (arr[i] > arr[j]) 8 | inv_count++; 9 | 10 | return inv_count; 11 | } 12 | 13 | /* Driver program to test above functions */ 14 | int main() 15 | { 16 | int arr[] = { 1, 20, 6, 4, 5 }; 17 | int n = sizeof(arr) / sizeof(arr[0]); 18 | printf(" Number of inversions are %d \n", getInvCount(arr, n)); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello world!"); 6 | } 7 | -------------------------------------------------------------------------------- /C/insertion.c: -------------------------------------------------------------------------------- 1 | #include 2 | void insertionSort(int arr[], int n) 3 | { 4 | int i, key, j; 5 | for (i = 1; i < n; i++) { 6 | key = arr[i]; 7 | j = i - 1; 8 | 9 | while (j >= 0 && arr[j] > key) { 10 | arr[j + 1] = arr[j]; 11 | j = j - 1; 12 | } 13 | arr[j + 1] = key; 14 | } 15 | } 16 | void printArray(int arr[], int n) 17 | { 18 | int i; 19 | for (i = 0; i < n; i++) 20 | printf("%d ", arr[i]); 21 | printf("\n"); 22 | } 23 | int main() 24 | { 25 | int arr[] = { 12, 11, 13, 5, 6 }; 26 | int n = sizeof(arr) / sizeof(arr[0]); 27 | 28 | insertionSort(arr, n); 29 | printArray(arr, n); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C/min add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int no,n[]={},i,j; 6 | scanf("%d",&n); 7 | printf("hello"); 8 | for(i=0;i n[j]) 19 | { 20 | 21 | a = n[i]; 22 | n[i] = n[j]; 23 | n[j] = a; 24 | 25 | } 26 | 27 | } 28 | 29 | } 30 | 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C/n_queen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int board[20],count; 5 | 6 | int main() 7 | { 8 | int n,i,j; 9 | void queen(int row,int n); 10 | 11 | printf(" - N Queens Problem Using Backtracking -"); 12 | printf("\n\nEnter number of Queens:"); 13 | scanf("%d",&n); 14 | queen(1,n); 15 | return 0; 16 | } 17 | 18 | //function for printing the solution 19 | void print(int n) 20 | { 21 | int i,j; 22 | printf("\n\nSolution %d:\n\n",++count); 23 | 24 | for(i=1;i<=n;++i) 25 | printf("\t%d",i); 26 | 27 | for(i=1;i<=n;++i) 28 | { 29 | printf("\n\n%d",i); 30 | for(j=1;j<=n;++j) //for nxn board 31 | { 32 | if(board[i]==j) 33 | printf("\tQ"); //queen at i,j position 34 | else 35 | printf("\t-"); //empty slot 36 | } 37 | } 38 | } 39 | 40 | /*funtion to check conflicts 41 | If no conflict for desired postion returns 1 otherwise returns 0*/ 42 | int place(int row,int column) 43 | { 44 | int i; 45 | for(i=1;i<=row-1;++i) 46 | { 47 | //checking column and digonal conflicts 48 | if(board[i]==column) 49 | return 0; 50 | else 51 | if(abs(board[i]-column)==abs(i-row)) 52 | return 0; 53 | } 54 | 55 | return 1; //no conflicts 56 | } 57 | 58 | //function to check for proper positioning of queen 59 | void queen(int row,int n) 60 | { 61 | int column; 62 | for(column=1;column<=n;++column) 63 | { 64 | if(place(row,column)) 65 | { 66 | board[row]=column; //no conflicts so place queen 67 | if(row==n) //dead end 68 | print(n); //printing the board configuration 69 | else //try queen with next position 70 | queen(row+1,n); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /C/palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int n, m, digit, rev; 7 | printf("Enter the number "); 8 | scanf("%d",&n); 9 | m = n; 10 | rev = 0; 11 | while(n!=0) 12 | { 13 | digit = n % 10; 14 | rev = rev*10 + digit; 15 | n = n/10; 16 | 17 | } 18 | if(m==rev) 19 | { 20 | 21 | printf("The given number is a palindrome i.e %d = %d",m,rev); 22 | } 23 | else 24 | { 25 | printf("The given number is not a palindrome i.e %d != %d",m,rev); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /C/password_strength.c: -------------------------------------------------------------------------------- 1 | /*The following program is an implementation of Password Strenth Measurer in C Programming Language. This basic Strenth Checker, checks 2 | the length of the Password Strenth, the presence of Uppercase Character, Lowercase Character, Digits and finally the Special Characters 3 | and if all the criteria are met, then the password strenth is strong otherwise medium or weak. */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | void check() 10 | { 11 | char pass[100],a=0,b=0,c=0,d=0,e=0,sum=0,i; 12 | char ch; 13 | clrscr(); 14 | printf("Enter the password to check its strength: \n"); 15 | scanf("%s",pass); 16 | if(strlen(pass)>=8){ 17 | a=1; 18 | } 19 | for(i=0;i=65 && pass[i]<=90){ 21 | b=1; 22 | } 23 | if(pass[i]>=97 && pass[i]<=122){ 24 | c=1; 25 | } 26 | if(pass[i]>=48 && pass[i]<=57){ 27 | d=1; 28 | } 29 | if(pass[i]=='!'||pass[i]=='@'||pass[i]=='#'||pass[i]=='$'||pass[i]=='%'||pass[i]=='^'||pass[i]=='&'||pass[i]=='*'||pass[i]=='*'||pass[i]=='('||pass[i]==')'||pass[i]=='+'||pass[i]=='-') 30 | { 31 | e=1; 32 | } 33 | } 34 | sum=a+b+c+d+e; 35 | if(sum==5){ 36 | printf("Strong Password \n"); 37 | } 38 | else if(sum>=3 && sum<=4){ 39 | printf("Medium Password \n"); 40 | } 41 | else{ 42 | printf("Weak Password \n"); 43 | } 44 | printf("Do you want to re-check your password [Y/N]? \n"); 45 | scanf(" %c",&ch); 46 | if(ch=='Y' || ch=='y'){ 47 | system("cls"); 48 | check(); 49 | } 50 | else{ 51 | exit(0); 52 | } 53 | } 54 | void main() 55 | { 56 | check(); 57 | getch(); 58 | } 59 | -------------------------------------------------------------------------------- /C/quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void q_sort(long long int *numbers,long long int left,long long int right) { 5 | long long int pivot, l_hold, r_hold; 6 | l_hold = left; 7 | r_hold = right; 8 | pivot = numbers[left]; 9 | while (left < right) { 10 | while ((numbers[right] >= pivot) && (left < right)) 11 | right--; 12 | if (left != right) { 13 | numbers[left] = numbers[right]; 14 | left++; 15 | } 16 | while ((numbers[left] <= pivot) && (left < right)) 17 | left++; 18 | if (left != right) { 19 | numbers[right] = numbers[left]; 20 | right--; 21 | } 22 | } 23 | numbers[left] = pivot; 24 | pivot = left; 25 | left = l_hold; 26 | right = r_hold; 27 | if (left < pivot) 28 | q_sort(numbers, left, pivot-1); 29 | if (right > pivot) 30 | q_sort(numbers, pivot+1, right); 31 | } 32 | 33 | void quickSort(long long int *numbers, long long int array_size) { 34 | q_sort(numbers, 0, array_size - 1); 35 | } 36 | 37 | // Input: Array 38 | // number of lines of array M and array contents written per line 39 | 40 | int main () { 41 | long long int M,i; 42 | scanf ("%lld\n", &M); 43 | long long int A[M]; 44 | for (i=0;i 2 | #include 3 | int main() 4 | { 5 | int i,j,pos,n,a[20],temp=0; 6 | printf("Enter the size of array:"); 7 | scanf("%d",&n); 8 | printf("Enter the element of array:"); 9 | for(i=0;ia[j]) 17 | pos=j; 18 | } 19 | if(pos != i) 20 | { 21 | temp=a[i]; 22 | a[i]=a[pos]; 23 | a[pos]=temp; 24 | } 25 | } 26 | printf("Sorted array:"); 27 | for(i=0;i 3 | 4 | int toh(int n, char s, char a, char d); 5 | 6 | int main() 7 | { 8 | int n, num; 9 | char s ='S', a = 'A', d ='D'; 10 | call: 11 | { 12 | printf("Enter the number of disks:\n"); 13 | scanf("%d", &n); 14 | 15 | num=toh(n,s,a,d); 16 | 17 | } 18 | 19 | if(num == -1) 20 | { 21 | printf("Number of disks is inavlid.\n"); 22 | goto call; 23 | } 24 | else 25 | printf("\nSuccessful\n"); 26 | 27 | 28 | return 0; 29 | } 30 | 31 | 32 | 33 | 34 | int toh(int n, char s, char a, char d) 35 | { 36 | if(n<=0) //no of disks is invalid. 37 | { 38 | //printf("Number of disks is invalid."); 39 | return -1; 40 | } 41 | 42 | if(n==1) //base case 43 | { 44 | printf("Taking Disk %d from %c to %c.\n", n,s,d); 45 | return 1; //succesfull 46 | 47 | } 48 | 49 | if(n>1) 50 | toh(n-1, s, d,a); //left rcursion. 51 | 52 | printf("Taking %d Disk from %c to %c.\n",n,s,d); 53 | 54 | if(n>1) 55 | toh(n-1, a,s,d); //right recursion. 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /C/vigenere.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/infiniteoverflow/contribute_ur_code/79e7ba32b965d7ef5a3fe081814be9800fb92102/C/vigenere.c -------------------------------------------------------------------------------- /C/writefile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void main(){ 9 | //char msg[20] = "hello \n"; 10 | char buffer[1]; //used for reading file 11 | 12 | int fd = open("git.txt", O_CREAT | O_WRONLY, 0777); 13 | int w = write(fd, "chris", 5); 14 | close(fd); 15 | 16 | fd = open("name.txt", O_RDONLY); 17 | int r; 18 | while (r>0){ 19 | r = read(fd, buffer, 1); 20 | printf("%s", buffer); 21 | } 22 | close(fd); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /CPP/0-1_knapsack_problem_dp.cpp: -------------------------------------------------------------------------------- 1 | // A Dynamic Programming based solution for 0-1 Knapsack problem 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | // A utility function that returns maximum of two llegers 7 | ll max(ll a, ll b) { return (a > b)? a : b; } 8 | 9 | // Returns the maximum value that can be put in a knapsack of capacity W 10 | ll knapSack(ll W, ll wt[], ll val[], ll n) 11 | { 12 | ll i, w; 13 | ll K[n+1][W+1]; 14 | 15 | // Build table K[][] in bottom up manner 16 | for (i = 0; i <= n; i++) 17 | { 18 | for (w = 0; w <= W; w++) 19 | { 20 | if (i==0 || w==0) 21 | K[i][w] = 0; 22 | else if (wt[i-1] <= w) 23 | K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); 24 | else 25 | K[i][w] = K[i-1][w]; 26 | } 27 | } 28 | 29 | return K[n][W]; 30 | } 31 | 32 | int main() 33 | { 34 | ll n; 35 | cout << "Enter Size" << endl; 36 | cin >> n; 37 | ll val[n]; 38 | ll wt[n]; 39 | cout << "Enter Values of n items" << endl; 40 | for(ll i=0;i> val[i]; 42 | } 43 | cout << "Enter wights of n items" << endl; 44 | for(ll i=0;i> wt[i]; 46 | } 47 | ll W; 48 | cout << "Enter capacity of knapsack" << endl; 49 | cin >> W; 50 | cout << "The maximum value that can be put in knapsack is: "; 51 | cout << knapSack(W, wt, val, n) << endl; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /CPP/1 LINEAR.CPP: -------------------------------------------------------------------------------- 1 | //Program for Linear Search in Arrays. 2 | #include 3 | #include 4 | lsearch(int [],int,int); 5 | void main() 6 | { 7 | clrscr(); 8 | int ar[20],ele,n,index; 9 | cout<<"\nENTER NUMBER OF ARRAY ELEMENTS : "; 10 | cin>>n; 11 | cout<<"\nENTER ARRAY ELEMENTS : \n"; 12 | for(int i=0;i>ar[i]; 14 | cout<<"\nENTER ELEMENT TO BE SEARCHED : "; 15 | cin>>ele; 16 | 0 index=lsearch(ar,n,ele); 17 | if(index==-1) 18 | cout<<"\nSORRY. \nELEMENT COULD NOT BE FOUND"; 19 | else 20 | cout<<"\nELEMENT IS FOUND AT POSITION : "< 3 | #include 4 | #include 5 | void main() 6 | { 7 | clrscr(); 8 | int count=0; 9 | char word[20]; 10 | ifstream fin("story.txt",ios::in); 11 | while(!fin.eof()) 12 | { 13 | fin>>word; 14 | if(word[0]=='A'||word[0]=='a') 15 | count++; 16 | } 17 | cout<<"\nNumber of words starting with letter A in a file story.txt are: "< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int i,j,r,c,A[10][10],T[10][10]; 8 | 9 | cout<<"Enter the number of rows and columns of matrix : \n"; 10 | cin>>r>>c; 11 | cout<<"Enter the elements of matrix : \n"; 12 | for( i = 0 ; i < r ; i++ ) 13 | { 14 | for( j = 0 ; j < c ; j++ ) 15 | { 16 | cin>>A[i][j]; 17 | } 18 | } 19 | cout<<"\nMatrix is : \n"; 20 | for( i = 0 ; i < r ; i++ ) 21 | { 22 | for( j = 0 ; j < c ; j++ ) 23 | { 24 | cout<<" "< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[10],n; 8 | clrscr(); 9 | cout<<"\nEnter the number of elements : \n"; 10 | cin>>n; 11 | cout<<"\nEnter elements : \n"; 12 | for(int i=0; i>ar[i]; 14 | cout<<"\nEntered array is : \n"; 15 | for(i=0; i 3 | #include 4 | #include 5 | #include 6 | class PHOTO 7 | { 8 | int pno; 9 | char category[20],exhibit[20]; 10 | void fixexhibit() 11 | { 12 | if(strcmp(category,"Antique")==0) 13 | strcpy(exhibit,"Zaveri"); 14 | else if(strcmp(category,"Modern")==0) 15 | strcpy(exhibit,"Johnsen"); 16 | else if(strcmp(category,"Classic")==0) 17 | strcpy(exhibit,"Terenida"); 18 | } 19 | public: 20 | void Register() 21 | { 22 | cout<<"\nEnter value of Photo Number : "; 23 | cin>>pno; 24 | cout<<"\nEnter value of Photo Category : "; 25 | gets(category); 26 | fixexhibit(); 27 | } 28 | void viewall() 29 | { 30 | cout<<"\nPhoto Number : "< 3 | #include 4 | #include 5 | class APPLICANT 6 | { 7 | long ano; 8 | char name[20],grade; 9 | float agg; 10 | void grademe() 11 | { 12 | if(agg>=80) 13 | grade='A'; 14 | else if(agg>=65) 15 | grade='B'; 16 | else if(agg>=50) 17 | grade='C'; 18 | else if(agg<50) 19 | grade='D'; 20 | } 21 | public: 22 | void enter() 23 | { 24 | cout<<"\nEnter value of Admission Number : "; 25 | cin>>ano; 26 | cout<<"\nEnter Name : "; 27 | gets(name); 28 | cout<<"\nEnter Aggregate Marks : "; 29 | cin>>agg; 30 | grademe(); 31 | } 32 | void result() 33 | { 34 | cout<<"\nAdmission Number : "< 3 | #include 4 | #include 5 | class STOCK 6 | { 7 | int icode,qty; 8 | char name[20]; 9 | float price,discount; 10 | void finddisc() 11 | { 12 | if(qty<=50) 13 | discount=0; 14 | else if(qty<=100) 15 | discount=5; 16 | else if(qty>100) 17 | discount=10; 18 | } 19 | public: 20 | void buy() 21 | { 22 | cout<<"\nEnter Item Code : "; 23 | cin>>icode; 24 | cout<<"\nEnterItem Name : "; 25 | gets(name); 26 | cout<<"\nEnter Price of each item : "; 27 | cin>>price; 28 | cout<<"\nEnter Quantity in Stock : "; 29 | cin>>qty; 30 | finddisc(); 31 | } 32 | void showall() 33 | { 34 | cout<<"\nItem Code : "< 3 | #include 4 | float area(float l,float b) 5 | { 6 | return (l*b); 7 | } 8 | float area(float r) 9 | { 10 | return (22*r*r)/7; 11 | } 12 | void main() 13 | { 14 | clrscr(); 15 | cout<<"\nAREA OF A RECTANGLE : "< 4 | #include 5 | #include 6 | #include 7 | #include 8 | void main() 9 | { 10 | clrscr(); 11 | int n; 12 | float l,b,pm,ar,diag; 13 | do 14 | { 15 | cout<<"\nRECTANGLE MENU : "; 16 | cout<<"\n1. AREA "; 17 | cout<<"\n2. PERIMETER "; 18 | cout<<"\n3. DIAGONAL "; 19 | cout<<"\n4. EXIT "; 20 | cout<<"\n\n\nENTER YOUR CHOICE : "; 21 | cin>>n; 22 | if(n==1||n==2||n==3) 23 | { 24 | cout<<"\nENTER LENGTH AND BREADTH OF RECTANGLE : \n"; 25 | cin>>l>>b; 26 | } 27 | switch(n) 28 | { 29 | case 1 : ar=l*b; 30 | cout<<"\nAREA OF RECTANGLE : "<=1 && n<=3); 43 | getche(); 44 | } 45 | -------------------------------------------------------------------------------- /CPP/18 CALLREF.CPP: -------------------------------------------------------------------------------- 1 | //PROGRAM FOR CALL BY VALUE 2 | #include 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | void change(int &); 8 | int a=10; 9 | cout<<"\nVALUE OF A IS : "< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | void change(int); 8 | int a=10; 9 | cout<<"\nVALUE OF A IS : "< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={45,35,85,80,33,27,90}; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<7;i++) 10 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={45,35,85,80,33,27,90},temp; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<7;i++) 10 | cout<ar[j+1]) 16 | { 17 | temp=ar[j]; 18 | ar[j]=ar[j+1]; 19 | ar[j+1]=temp; 20 | } 21 | } 22 | cout<<"\nSORTED ARRAY IS : "; 23 | for(j=0;j<7;j++) 24 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={45,35,85,80,33,27,90},num; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<7;i++) 10 | cout<>num; 13 | for(i=0;i<7;i++) 14 | if(ar[i]==num) 15 | cout<<"\n\nELEMENT FOUND AT POSITION : "<<++i< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={45,35,85,80,33,27,90},temp; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<7;i++) 10 | cout< 10 | #include 11 | void main() 12 | { 13 | clrscr(); 14 | int ar[]={45,34,85,80,33,27,90},num; 15 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 16 | for(int i=0;i<7;i++) 17 | cout< 3 | #include 4 | bsearch(int [],int,int); 5 | void main() 6 | { 7 | clrscr(); 8 | int ar[20],ele,n,index; 9 | cout<<"\nENTER NUMBER OF ARRAY ELEMENTS : "; 10 | cin>>n; 11 | cout<<"\nENTER ARRAY ELEMENTS : \n"; 12 | for(int i=0;i>ar[i]; 14 | cout<<"\nENTER ELEMENT TO BE SEARCHED : "; 15 | cin>>ele; 16 | index=bsearch(ar,n,ele); 17 | if(index==-1) 18 | cout<<"\nSORRY. \nELEMENT COULD NOT BE FOUND"; 19 | else 20 | cout<<"\nELEMENT IS FOUND AT POSITION : "<ar[mid]) 32 | beg=mid+1; 33 | else 34 | last=mid-1; 35 | } 36 | return -1; 37 | } 38 | -------------------------------------------------------------------------------- /CPP/2 D ARRAY/2DA1.CPP: -------------------------------------------------------------------------------- 1 | //PROGRAM TO REPRESENT 2D ARRAY. 2 | #include 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}},sum=0; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | { 12 | if(ar[i][j]%2==0) 13 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | { 12 | if(i==0) 13 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | { 12 | if(j==0) 13 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | { 12 | if(i==3/2) 13 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}}; 8 | cout<<"\n\nDIAGONAL 1 : "; 9 | for(int i=0;i<3;i++) 10 | { 11 | for(int j=0;j<3;j++) 12 | { 13 | if(i==j) 14 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}},temp; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[3][3]={{3,4,5},{5,6,7},{6,7,8}},sum1=0,sum2=0,sum3=0; 8 | for(int i=0;i<3;i++) 9 | { 10 | for(int j=0;j<3;j++) 11 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={22,25,70,32,12},temp=ar[0]; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<5;i++) 10 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={90,56,45,20,34,54},temp; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<6;i++) 10 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[6]; 8 | cout<<"\nENTER ANY 6 NUMBERS : \n"; 9 | for(int i=0;i<6;i++) 10 | cin>>ar[i]; 11 | cout<<"\n\nEVEN NUMBERS ARE : "; 12 | for(i=0;i<6;i++) 13 | { 14 | if(ar[i]%2==0) 15 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[6]={3,5,7,8,11,12}; 8 | cout<<"\n\nTHE ELEMENTS IN ARRAY ARE : "; 9 | for(int i=0;i<6;i++) 10 | cout<=0;i--) 13 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={2,3,4,5,6}; 8 | cout<<"\n\nTHE ELEMENTS IN ARRAY ARE : "; 9 | for(int i=0;i<5;i++) 10 | cout< 3 | #include 4 | void main() 5 | { 6 | clrscr(); 7 | int ar[]={45,35,85,80,33,27,90}; 8 | cout<<"\nELEMENTS IN AN ARRAY ARE : "; 9 | for(int i=0;i<7;i++) 10 | cout< 3 | #include 4 | void bubble(int [],int); 5 | void main() 6 | { 7 | clrscr(); 8 | int ar[20],n; 9 | cout<<"\nNUMBER OF ELEMENTS TO BE ENTERED : "; 10 | cin>>n; 11 | cout<<"\nENTER ELEMENTS : \n"; 12 | for(int i=0;i>ar[i]; 14 | bubble(ar,n); 15 | cout<<"\nTHE SORTED ARRY IS : \n"; 16 | for(i=0;iar[j+1]) 29 | { 30 | temp=ar[j]; 31 | ar[j]=ar[j+1]; 32 | ar[j+1]=temp; 33 | } 34 | } 35 | cout<<"ARRAY AFTER ITERATION "<<++pass<<" : "; 36 | for(int k=0;k 3 | #include 4 | void select(int [],int); 5 | void main() 6 | { 7 | clrscr(); 8 | int ar[20],n; 9 | cout<<"\nNUMBER OF ELEMENTS TO BE ENTERED : "; 10 | cin>>n; 11 | cout<<"\nENTER ELEMENTS : \n"; 12 | for(int i=0;i>ar[i]; 14 | select(ar,n); 15 | cout<<"\nTHE SORTED ARRY IS : \n"; 16 | for(i=0;i 3 | #include 4 | #include 5 | void main() 6 | { 7 | clrscr(); 8 | int a[10][10],b[10][10],c[10][10]; 9 | int i,j,m,n,p,q; 10 | cout<<"\nENTER NUMBER OF ROWS AND COLUMNS FOR MATRIX A : \n"; 11 | cin>>m>>n; 12 | cout<<"\nENTER NUMBER OF ROWS AND COLUMNS FOR MATRIX B : \n"; 13 | cin>>p>>q; 14 | if((m==p)&&(n==q)) 15 | cout<<"MATRICES CAN BE ADDED"; 16 | else 17 | { 18 | cout<<"\nMATRICES CANNOT BE ADDED"; 19 | exit(0); 20 | } 21 | cout<<"\nINPUT ELEMENTS OF MATRIX A : \n"; 22 | for(i=0;i>a[i][j]; 26 | } 27 | cout<<"\nINPUT ELEMENTS OF MATRIX B : \n"; 28 | for(i=0;i>b[i][j]; 32 | } 33 | for(i=0;i 3 | #include 4 | #include 5 | void main() 6 | { 7 | clrscr(); 8 | int a[10][10],b[10][10],c[10][10]; 9 | int i,j,m,n,p,q; 10 | cout<<"\nENTER NUMBER OF ROWS AND COLUMNS FOR MATRIX A : \n"; 11 | cin>>m>>n; 12 | cout<<"\nENTER NUMBER OF ROWS AND COLUMNS FOR MATRIX B : \n"; 13 | cin>>p>>q; 14 | if((m==p)&&(n==q)) 15 | cout<<"MATRICES CAN BE SUBTRACTED"; 16 | else 17 | { 18 | cout<<"\nMATRICES CANNOT BE SUBTRACTED"; 19 | exit(0); 20 | } 21 | cout<<"\nINPUT ELEMENTS OF MATRIX A : \n"; 22 | for(i=0;i>a[i][j]; 26 | } 27 | cout<<"\nINPUT ELEMENTS OF MATRIX B : \n"; 28 | for(i=0;i>b[i][j]; 32 | } 33 | for(i=0;i 3 | #include 4 | #include 5 | void main() 6 | { 7 | clrscr(); 8 | int count=0; 9 | char ch; 10 | ifstream fin("story.txt",ios::in); 11 | while(!fin.eof()) 12 | { 13 | fin>>ch; 14 | if(isalpha(ch)) 15 | count++; 16 | } 17 | cout<<"\nNumber of alphabets in a file story.txt are: "< 3 | #include 4 | #include 5 | void main() 6 | { 7 | clrscr(); 8 | int count=0; 9 | char line[200]; 10 | ifstream fin("story.txt",ios::in); 11 | while(!fin.eof()) 12 | { 13 | fin.getline(line,200); 14 | count++; 15 | } 16 | cout<<"\nNumber of lines in a file story.txt are: "< 3 | #include 4 | #include 5 | void main() 6 | { 7 | clrscr(); 8 | int count=0; 9 | char word[20]; 10 | ifstream fin("story.txt",ios::in); 11 | while(!fin.eof()) 12 | { 13 | fin>>word; 14 | if(word!='\0') 15 | count++; 16 | } 17 | cout<<"\nNumber of words in a file story.txt are: "< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | string isBalanced(string s) { 8 | stack st; 9 | 10 | for (auto c: s) { 11 | switch (c) { 12 | case '{': 13 | case '(': 14 | case '[': 15 | st.push(c); 16 | break; 17 | case '}': 18 | if (st.empty() || (st.top() != '{')) { 19 | return "NO"; 20 | } 21 | st.pop(); 22 | break; 23 | case ')': 24 | if (st.empty() || (st.top() != '(')) { 25 | return "NO"; 26 | } 27 | st.pop(); 28 | break; 29 | case ']': 30 | if (st.empty() || (st.top() != '[')) { 31 | return "NO"; 32 | } 33 | st.pop(); 34 | break; 35 | } 36 | } 37 | 38 | return st.empty() ? "YES" : "NO"; 39 | } 40 | 41 | 42 | int main(){ 43 | int t; 44 | cin >> t; 45 | for(int a0 = 0; a0 < t; a0++){ 46 | string s; 47 | cin >> s; 48 | cout << isBalanced(s) << endl; 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /CPP/Candies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // Complete the candies function below. 6 | long candies(int n, vector arr) { 7 | int i; 8 | int candy[n]; 9 | fill(candy,candy+n,1); 10 | for(i=0;i0;i--) 16 | { 17 | if(arr[i-1]>arr[i] && candy[i-1]<=candy[i]) 18 | candy[i-1]+=1; 19 | } 20 | int sum=0; 21 | for(i=0;i> n; 32 | cin.ignore(numeric_limits::max(), '\n'); 33 | 34 | vector arr(n); 35 | 36 | for (int i = 0; i < n; i++) { 37 | int arr_item; 38 | cin >> arr_item; 39 | cin.ignore(numeric_limits::max(), '\n'); 40 | 41 | arr[i] = arr_item; 42 | } 43 | 44 | long result = candies(n, arr); 45 | 46 | fout << result << "\n"; 47 | 48 | fout.close(); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /CPP/LL.CPP: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct node{ 8 | int data; 9 | node *next; 10 | }; 11 | 12 | class list{ 13 | private: 14 | node *start,*end; 15 | public: 16 | list(){ 17 | head = NULL; 18 | tail = NULL; 19 | } 20 | 21 | } 22 | 23 | void createnode(int value){ 24 | node *temp=new node; 25 | temp->data = value; 26 | temp->next = NULL; 27 | if(head == NULL){ 28 | head = temp; 29 | tail =temp; 30 | temp = NULL; 31 | } 32 | else{ 33 | tail->next = temp; 34 | tail = temp; 35 | } 36 | } 37 | 38 | void display(){ 39 | node *temp = new node; 40 | temp = head; 41 | while(temp!=NULL){ 42 | cout<data<<"\t"; 43 | temp = temp->next; 44 | } 45 | } 46 | 47 | void insert_start(int value){ 48 | node *temp = new node; 49 | temp->data = value; 50 | temp->next = head; 51 | head = temp; 52 | } 53 | 54 | 55 | void insert_position(int pos, int value) 56 | { 57 | node *pre=new node; 58 | node *cur=new node; 59 | node *temp=new node; 60 | cur=head; 61 | for(int i=1;inext; 65 | } 66 | temp->data=value; 67 | pre->next=temp; 68 | temp->next=cur; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /CPP/Largest Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | long long n,arr[100001],i,j,max,temp=-1,k,count=1,val; 12 | cin>>n; 13 | for(i=0;i>arr[i]; 15 | } 16 | for(i=0;i=0 || k=0 && arr[j]>=val && cl1==1){ 21 | count++; 22 | }else cl1=0; 23 | if(k=val && cl==1){ 24 | count++; 25 | }else cl=0; 26 | if(cl==0 && cl1==0) 27 | break; 28 | } 29 | max=val*count; 30 | if(max>temp){ 31 | temp=max; 32 | } 33 | count=1; 34 | 35 | } 36 | cout< 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, num, digit, rev = 0; 9 | 10 | cout << "Enter a positive number: "; 11 | cin >> num; 12 | 13 | n = num; 14 | 15 | do 16 | { 17 | digit = num % 10; 18 | rev = (rev * 10) + digit; 19 | num = num / 10; 20 | } while (num != 0); 21 | 22 | cout << " The reverse of the number is: " << rev << endl; 23 | 24 | if (n == rev) 25 | cout << " The number is a palindrome."; 26 | else 27 | cout << " The number is not a palindrome."; 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /CPP/SeiveOfEratosthenes: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void SieveOfEratosthenes(int n) 5 | { 6 | bool prime[n+1]; 7 | memset(prime, true, sizeof(prime)); 8 | 9 | for (int p=2; p*p<=n; p++) 10 | { 11 | 12 | if (prime[p] == true) 13 | { 14 | 15 | for (int i=p*p; i<=n; i += p) 16 | prime[i] = false; 17 | } 18 | } 19 | 20 | 21 | for (int p=2; p<=n; p++) 22 | if (prime[p]) 23 | cout << p << " "; 24 | } 25 | 26 | 27 | int main() 28 | { 29 | int n; 30 | cin>>n; 31 | cout << "Following are the prime numbers smaller " 32 | << " than or equal to " << n << endl; 33 | SieveOfEratosthenes(n); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /CPP/arrayofstruct.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | struct stud 7 | { 8 | int rollNo; 9 | string name; 10 | int phoneNo; 11 | }; 12 | 13 | int main() 14 | { 15 | struct stud id[5]; 16 | int i; 17 | 18 | for (i = 0; i < 5; i++) 19 | { 20 | cout << "Student " << i + 1 << endl; 21 | cout << "Naam Likho:" << endl; 22 | cin >> id[i].name; 23 | cout << "rollNo Likho:" << endl; 24 | cin >> id[i].rollNo; 25 | cout << "mobileNo likho:" << endl; 26 | cin >> id[i].phoneNo; 27 | } 28 | 29 | for (i = 0; i < 5; i++) 30 | { 31 | cout << "Student " << i + 1 << endl; 32 | cout << "Tumhara Naam he:" << id[i].name << endl; 33 | cout << "Tumhara rollNo he:" << id[i].rollNo << endl; 34 | cout << "Tumhara Mobil No he:" << id[i].phoneNo << endl; 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /CPP/binary_search.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to implement recursive Binary Search 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | // A recursive binary search function. It returns 7 | // location of x in given array arr[l..r] is present, 8 | // otherwise -1 9 | ll binarySearch(ll arr[], ll l, ll r, ll x) 10 | { 11 | if (r >= l) { 12 | ll mid = l + (r - l) / 2; 13 | 14 | // If the element is present at the middle 15 | // itself 16 | if (arr[mid] == x) 17 | return mid; 18 | 19 | // If element is smaller than mid, then 20 | // it can only be present in left subarray 21 | if (arr[mid] > x) 22 | return binarySearch(arr, l, mid - 1, x); 23 | 24 | // Else the element can only be present 25 | // in right subarray 26 | return binarySearch(arr, mid + 1, r, x); 27 | } 28 | 29 | // We reach here when element is not 30 | // present in array 31 | return -1; 32 | } 33 | 34 | int main(void) 35 | { 36 | ll n; 37 | cout << "Enter the size of the array" << endl; 38 | cin >> n; 39 | ll arr[n]; 40 | cout << "Enter the array elements" << endl; 41 | for(ll i=0;i> arr[i]; 43 | } 44 | ll x; 45 | cout << "Enter the element to be searched" << endl; 46 | cin >> x; 47 | ll result = binarySearch(arr, 0, n - 1, x); 48 | (result == -1) ? cout << "Element is not present in array" 49 | : cout << "Element is present at index " << result; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /CPP/bool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | bool is =true; 5 | bool iz = false; 6 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n, i; 7 | cout << "Enter a positive integer n : "; 8 | cin >> n; 9 | for(i = 2; i * i <= n ; i++) 10 | { 11 | if(n % i == 0) 12 | { 13 | cout<<" n is not a Prime number" << endl; 14 | exit(0); 15 | } 16 | } 17 | cout << " n is a Prime number" << endl; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /CPP/checking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | 9 | { 10 | 11 | int n, i; 12 | 13 | cout << "Enter a positive integer n : "; 14 | 15 | cin >> n; 16 | 17 | for(i = 2; i * i <= n ; i++) 18 | 19 | { 20 | 21 | if(n % i == 0) 22 | 23 | { 24 | 25 | cout << "n is a Prime Number"; 26 | 27 | exit(0); 28 | 29 | } 30 | 31 | } 32 | 33 | cout << "n is not a Prime number"; 34 | return 0; 35 | 36 | } -------------------------------------------------------------------------------- /CPP/class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class tenant{ 7 | public: 8 | string name; 9 | string month; 10 | int age; 11 | }; 12 | 13 | 14 | int main() { 15 | tenant ayan; 16 | ayan.name = "ayan"; 17 | ayan.month = "july"; 18 | ayan.age = 18; 19 | 20 | tenant harsh; 21 | harsh.name = "harsh"; 22 | harsh.month = "july"; 23 | harsh.age = 18; 24 | 25 | tenant shagun; 26 | shagun.name = "shagun"; 27 | shagun.month = "august"; 28 | shagun.age = 18; 29 | 30 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #include "h13.h" 9 | 10 | string dataSets(const string& fileName) 11 | { 12 | ifstream infile(fileName); 13 | if (infile.fail()) 14 | { 15 | return "data/notfound.txt cannot be opened.\n"; 16 | } 17 | int repeat = 0; 18 | double x = 1.0; 19 | int set = 1; 20 | string result; 21 | infile >> repeat; 22 | 23 | while (!infile.fail()) 24 | { 25 | double sum = 0; 26 | int count = 0; 27 | 28 | while (repeat != 0) 29 | { 30 | infile >> x; 31 | count += repeat; 32 | sum += (repeat * x); 33 | infile >> repeat; 34 | } 35 | ostringstream out; 36 | double avg = (sum * 1.0) / (count * 1.0); 37 | out << fixed << setprecision(4) << avg; 38 | 39 | if (count > 0) 40 | { 41 | if (set > 1) 42 | { 43 | result += "\n"; 44 | } 45 | } 46 | result += "data set " + to_string(set) + ": total values = " + to_string(count) 47 | + "\n" + "average value = " + out.str() + "\n"; 48 | set++; 49 | infile >> repeat; 50 | } 51 | return result; 52 | } 53 | 54 | ///////////////// Student Testing ///////////////////////// 55 | int run() 56 | { 57 | cout << "Student tests" << endl; 58 | return 0; 59 | } -------------------------------------------------------------------------------- /CPP/dataLoop.h: -------------------------------------------------------------------------------- 1 | #ifndef H13_H_ 2 | #define H13_H_ 3 | 4 | #include 5 | 6 | /** 7 | * Opens and processes the data sets in fileName. 8 | * Returns as a string the count and the average. 9 | * @param fileName name of the file. 10 | * @return the stats as described in the handout. 11 | */ 12 | std::string dataSets(const std::string& fileName); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /CPP/depthFirstSearch.cpp: -------------------------------------------------------------------------------- 1 | /* Depth First Search using C++ 11 */ 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | #define MAX 112345678; 8 | bool visited[MAX]; 9 | vector neighbors[MAX]; 10 | 11 | void dfs (int s){ 12 | if(visited[s]) return; 13 | visited[s] = true; 14 | for(auto u : neighbors[s]){ 15 | dfs(u); 16 | } 17 | } 18 | 19 | int main(void){ 20 | int n = 0, a = 0, b = 0; 21 | cin>>n; 22 | for(int i = 0; i < n; i++){ 23 | cin>>a>>b; 24 | neighbors[a].push_back(b); 25 | neighbors[b].push_back(a); 26 | } 27 | dfs(1); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /CPP/dfs_inorder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct Node 6 | { 7 | int data; 8 | struct Node *llink; 9 | struct Node *rlink; 10 | Node(int data) 11 | { 12 | this->data = data; 13 | llink = NULL; 14 | rlink = NULL; 15 | } 16 | }; 17 | 18 | void inorder(struct Node *root) 19 | { 20 | stack s; 21 | Node *curr = root; 22 | 23 | while(curr != NULL || s.empty()== false) 24 | { 25 | while(curr != NULL) 26 | { 27 | s.push(curr); 28 | curr = curr->llink; 29 | } 30 | 31 | curr = s.top(); 32 | s.pop(); 33 | cout<data<rlink; 36 | } 37 | } 38 | 39 | int main() 40 | { 41 | struct Node *root = new Node(1); 42 | root->llink = new Node(2); 43 | root->rlink = new Node(3); 44 | root->llink->llink = new Node(4); 45 | root->llink->rlink = new Node(5); 46 | inorder(root); 47 | return 0; 48 | } -------------------------------------------------------------------------------- /CPP/doubeEndedQueue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | #define SIZE 5; 5 | 6 | class dequeue{ 7 | int arr[10]; 8 | int front,rear; 9 | public: 10 | dequeue(); 11 | void addAtBeg(int); 12 | void addAtEnd(int); 13 | void delFrFront(); 14 | void delFrRear(); 15 | void display(); 16 | }; 17 | 18 | dequeue::dequeue(){ 19 | front = -1; 20 | rear = -1; 21 | } 22 | 23 | void dequeue::addAtEnd(int item){ 24 | if(rear >= SIZE-1){ 25 | cout<<"\n Insertion Not Possible,OVERFLOW"; 26 | }else{ 27 | if(front == -1){ 28 | front++; 29 | rear++; 30 | }else{ 31 | rear +=1; 32 | } 33 | a[rear] = item; 34 | cout<<"\nInserted item is:"< 2 | 3 | using namespace std; 4 | 5 | void factorial(int num) 6 | { 7 | long int factrl=1; 8 | for(int i=1;i<=num;i++) 9 | { 10 | factrl=factrl*i; 11 | } 12 | cout << factrl; 13 | } 14 | 15 | int main() 16 | { 17 | int num; 18 | cin >> num; 19 | factorial(num); 20 | return 0; 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CPP/fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int a=0,b=1,c,n; 6 | cin>>n; 7 | if (n>=2) 8 | { 9 | cout< 2 | 3 | int main(){ 4 | printf(" YOLO"); 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /CPP/focalLength.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | /** 9 | * Calculates the focal length of a lens. 10 | * @param d thickness of the lens 11 | * @param r1 radii r1 12 | * @param r2 radii r2 13 | * @param n the refractive index 14 | * @return the focal length 15 | */ 16 | double focalLength(double d, double r1, double r2, double n) 17 | { 18 | double f; 19 | 20 | f = 1 / ((n - 1) * ((1 / r1) - (1 / r2) + (((n - 1) * d) / (n * r1 * r2)))); 21 | 22 | return f; 23 | } 24 | 25 | 26 | 27 | /////////////// Optional Student Code ///////////////// 28 | int run() 29 | { 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /CPP/goingPostal.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | #include "h09.h" 6 | 7 | string codeForDigit(int digit) 8 | { 9 | string result; 10 | switch(digit) 11 | { 12 | case 1: result = ":::||"; 13 | break; 14 | 15 | case 2: result = "::|:|"; 16 | break; 17 | 18 | case 3: result = "::||:"; 19 | break; 20 | 21 | case 4: result = ":|::|"; 22 | break; 23 | 24 | case 5: result = ":|:|:"; 25 | break; 26 | 27 | case 6: result = ":||::"; 28 | break; 29 | 30 | case 7: result = "|:::|"; 31 | break; 32 | 33 | case 8: result = "|::|:"; 34 | break; 35 | 36 | case 9: result = "|:|::"; 37 | break; 38 | 39 | case 0: result = "||:::"; 40 | break; 41 | } 42 | return result; 43 | } 44 | 45 | int checkDigit(int zip) 46 | { 47 | int sum = 0; 48 | 49 | while (zip != 0) 50 | { 51 | sum += zip % 10; 52 | zip /= 10; 53 | } 54 | if (sum % 10 == 0) 55 | { 56 | return 0; 57 | } 58 | sum = 10 - (sum % 10) % 10; 59 | return sum; 60 | } 61 | 62 | string barCode(int zip) 63 | { 64 | int i = checkDigit(zip); 65 | string result = codeForDigit(i); 66 | i = 0; 67 | while (zip != 0) 68 | { 69 | i = zip % 10; 70 | result = codeForDigit(i) + result; 71 | zip /= 10; 72 | } 73 | return + "|" + result + "|"; 74 | } 75 | 76 | /////////// Student Testing /////////////////////// 77 | int run() 78 | { 79 | return 0; 80 | } -------------------------------------------------------------------------------- /CPP/goingPostal.h: -------------------------------------------------------------------------------- 1 | #ifndef H09_H_ 2 | #define H09_H_ 3 | 4 | /** 5 | * takes one digit and returns the appropriate code for that digit 6 | * @param digit the int 7 | * @returns string result 8 | */ 9 | string codeForDigit(int digit); 10 | /* 11 | calculates the check digit 12 | @param int zip 13 | @return return sum 14 | */ 15 | int checkDigit(int zip); 16 | 17 | /** 18 | * calculates and encodes the check digit 19 | * surrounds the entire code with the frame bars 20 | * using ':' for the half-bars and '|' for the full bars 21 | * @param zip the int 22 | * @return string result 23 | */ 24 | string barCode(int zip); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /CPP/insertionInCircularLinkedList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Node{ 5 | int data; 6 | Node*next=NULL; 7 | }; 8 | class list{ 9 | Node* last=NULL; 10 | public: 11 | void insert(int data){ 12 | Node* node= new Node; 13 | node->data=data; 14 | if(last==NULL){ 15 | last=node; 16 | last->next=last; 17 | }else{ 18 | node->next=last->next; 19 | last->next=node; 20 | last=node; 21 | } 22 | } 23 | //inserton at the last of the list 24 | void insertAtlast(int data){ 25 | Node* node= new Node; 26 | node->data=data; 27 | node->next=last->next; 28 | last->next=node; 29 | last=node; 30 | } 31 | //insertion at the front of the list 32 | void insertAtFront(int data){ 33 | Node* node= new Node; 34 | node->data=data; 35 | node->next=last->next; 36 | last->next=node; 37 | } 38 | void show(){ 39 | Node* n=last->next; 40 | if(last==NULL){ 41 | cout<<"list is empty"<data<<" "; 46 | n=n->next; 47 | } while(n!=last->next); 48 | cout< 2 | 3 | using namespace std; 4 | 5 | struct node 6 | { 7 | int data; 8 | struct node *next; 9 | }; 10 | 11 | class ll 12 | { 13 | private: 14 | node *head, *tail; 15 | 16 | public: 17 | ll() 18 | { 19 | head = NULL; 20 | tail = NULL; 21 | } 22 | 23 | void addNode(int no) 24 | { 25 | node *tmp = new node; 26 | tmp->data = no; 27 | tmp->next = NULL; 28 | if (head == NULL) 29 | { 30 | head = tmp; 31 | tail = tmp; 32 | } 33 | else 34 | { 35 | tail->next = tmp; 36 | tail = tail->next; 37 | } 38 | } 39 | void display() 40 | { 41 | node *tmp; 42 | tmp = head; 43 | cout << "Elements in Node are:" << endl; 44 | while (tmp != NULL) 45 | { 46 | cout << tmp->data << endl; 47 | tmp = tmp->next; 48 | } 49 | } 50 | void countNode() 51 | { 52 | node *tmp; 53 | tmp = head; 54 | int count = 0; 55 | while (tmp != NULL) 56 | { 57 | cout << tmp->data << endl; 58 | tmp = tmp->next; 59 | count++; 60 | } 61 | cout << "Total Elements in Node are:" << count << endl; 62 | } 63 | }; 64 | 65 | int main() 66 | { 67 | ll a; 68 | a.addNode(2); 69 | a.addNode(3); 70 | a.display(); 71 | a.countNode(); 72 | return 0; 73 | } -------------------------------------------------------------------------------- /CPP/lltraverseRecursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct node 6 | { 7 | int data; 8 | struct node *next; 9 | }; 10 | 11 | class ll 12 | { 13 | private: 14 | node *head, *tail; 15 | 16 | public: 17 | ll() 18 | { 19 | head = NULL; 20 | tail = NULL; 21 | } 22 | 23 | void addNode(int no) 24 | { 25 | node *tmp = new node; 26 | tmp->data = no; 27 | tmp->next = NULL; 28 | if (head == NULL) 29 | { 30 | head = tmp; 31 | tail = tmp; 32 | } 33 | else 34 | { 35 | tail->next = tmp; 36 | tail = tail->next; 37 | } 38 | } 39 | 40 | node *gethead() 41 | { 42 | return head; 43 | } 44 | void display(node *head) 45 | { 46 | if (head = NULL) 47 | { 48 | cout << "NULL" << endl; 49 | } 50 | else 51 | { 52 | cout << head->data << endl; 53 | display(head->next); 54 | } 55 | } 56 | }; 57 | 58 | int main() 59 | { 60 | ll a; 61 | a.addNode(2); 62 | a.addNode(3); 63 | a.display(); 64 | return 0; 65 | } -------------------------------------------------------------------------------- /CPP/mergesort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void merge(int arr[], int l, int m, int r) 5 | { 6 | int i, j, k; 7 | int n1 = m - l + 1; 8 | int n2 = r - m; 9 | 10 | 11 | int L[n1], R[n2]; 12 | 13 | 14 | for (i = 0; i < n1; i++) 15 | L[i] = arr[l + i]; 16 | for (j = 0; j < n2; j++) 17 | R[j] = arr[m + 1+ j]; 18 | 19 | 20 | i = 0; 21 | j = 0; 22 | k = l; 23 | while (i < n1 && j < n2) 24 | { 25 | if (L[i] <= R[j]) 26 | { 27 | arr[k] = L[i]; 28 | i++; 29 | } 30 | else 31 | { 32 | arr[k] = R[j]; 33 | j++; 34 | } 35 | k++; 36 | } 37 | 38 | 39 | while (i < n1) 40 | { 41 | arr[k] = L[i]; 42 | i++; 43 | k++; 44 | } 45 | 46 | 47 | while (j < n2) 48 | { 49 | arr[k] = R[j]; 50 | j++; 51 | k++; 52 | } 53 | } 54 | 55 | 56 | void mergeSort(int arr[], int l, int r) 57 | { 58 | if (l < r) 59 | { 60 | 61 | int m = l+(r-l)/2; 62 | 63 | 64 | mergeSort(arr, l, m); 65 | mergeSort(arr, m+1, r); 66 | 67 | merge(arr, l, m, r); 68 | } 69 | } 70 | 71 | int main() 72 | { 73 | int n,i,j; 74 | scanf("%d", &n); 75 | 76 | int a[n]; 77 | 78 | for(i=0;i 2 | using namespace std; 3 | int main() { 4 | float f1 = 35e3; 5 | cout<< f1; 6 | return 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /CPP/pointer.cpp: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/c-tutorial-pointer/submissions/code/125899276 2 | 3 | #include 4 | 5 | void update(int *a,int *b) { 6 | int aa = *a; 7 | *a = *a+*b; 8 | *b = aa-*b; 9 | if(*b < 0)*b *= -1; 10 | } 11 | 12 | int main() { 13 | int a, b; 14 | int *pa = &a, *pb = &b; 15 | 16 | scanf("%d %d", &a, &b); 17 | update(pa, pb); 18 | printf("%d\n%d", a, b); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CPP/pointers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string name = "Shagun"; 6 | string* ptr = &name; 7 | 8 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | struct stud 7 | { 8 | int rollNo; 9 | string name; 10 | }; 11 | 12 | int main() 13 | { 14 | struct stud point = {181, "shagun"}; 15 | struct stud *ptr; 16 | ptr = &point; 17 | 18 | cout << point.rollNo << " " << point.name << endl; 19 | cout << ptr->rollNo << " " << ptr->name << endl; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /CPP/printing pyramid.cpp: -------------------------------------------------------------------------------- 1 | // C++ code to demonstrate star pattern 2 | #include 3 | using namespace std; 4 | 5 | // Function to demonstrate printing pattern 6 | void triangle(int n) 7 | { 8 | // number of spaces 9 | int k = 2*n - 2; 10 | 11 | // outer loop to handle number of rows 12 | // n in this case 13 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | priority_queue pq; 8 | 9 | pq.push(4); 10 | pq.push(5); 11 | pq.push(6); 12 | //pq.pop(5); 13 | 14 | cout << "Top:" << pq.top() << endl; 15 | cout << pq.size() << endl; 16 | cout << "PQueue:" << endl; 17 | while (!pq.empty()) 18 | { 19 | cout << pq.top() << " "; 20 | pq.pop(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CPP/radix-sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | void display(int *array, int size) { 6 | for(int i = 0; i pocket[10]; //radix of decimal number is 10 13 | for(i = 0; i< max; i++) { 14 | m = pow(10, i+1); 15 | p = pow(10, i); 16 | for(j = 0; j> n; 36 | cout << "Enter the maximum digit of elements: "; 37 | cin >> max; 38 | int arr[n]; //create an array with given number of elements 39 | cout << "Enter elements:" << endl; 40 | for(int i = 0; i> arr[i]; 42 | } 43 | cout << "Data before Sorting: "; 44 | display(arr, n); 45 | radixSort(arr, n, max); 46 | cout << "Data after Sorting: "; 47 | display(arr, n); 48 | } 49 | -------------------------------------------------------------------------------- /CPP/references.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string name = "Shagun"; 8 | string &naam = name; 9 | cout< 2 | 3 | using namespace std; 4 | 5 | struct node 6 | { 7 | int data; 8 | struct node *next; 9 | }; 10 | 11 | class ll 12 | { 13 | private: 14 | node *head, *tail; 15 | 16 | public: 17 | ll() 18 | { 19 | head = NULL; 20 | tail = NULL; 21 | } 22 | 23 | void addNode(int no) 24 | { 25 | node *temp = new node; 26 | temp->data = no; 27 | temp->next = NULL; 28 | if (head == NULL) 29 | { 30 | head = temp; 31 | tail = temp; 32 | } 33 | else 34 | { 35 | tail->next = temp; 36 | tail = tail->next; 37 | } 38 | } 39 | 40 | void display() 41 | { 42 | node *temp; 43 | temp = head; 44 | cout << "Elements are:" << endl; 45 | while (temp != NULL) 46 | { 47 | cout << temp->data; 48 | temp = temp->next; 49 | } 50 | } 51 | }; 52 | 53 | int main() 54 | { 55 | ll a; 56 | int num; 57 | cout << "enter Number:"; 58 | cin >> num; 59 | a.addNode(num); 60 | a.display(); 61 | return 0; 62 | } -------------------------------------------------------------------------------- /CPP/short.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int time = 20; 7 | string result = (time < 20)?"good day":"good evening"; 8 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int a[10][10] = {{0, 0, 9}, {5, 0, 8}, {7, 0, 0}}; 6 | int i, j, count = 0; 7 | int row = 3, col = 3; 8 | for (i = 0; i < row; ++i) 9 | { 10 | for (j = 0; j < col; ++j) 11 | { 12 | if (a[i][j] == 0) 13 | count++; 14 | } 15 | } 16 | cout << "The matrix is:" << endl; 17 | for (i = 0; i < row; ++i) 18 | { 19 | for (j = 0; j < col; ++j) 20 | { 21 | cout << a[i][j] << " "; 22 | } 23 | cout << endl; 24 | } 25 | cout << "The number of zeros in the matrix are " << count << endl; 26 | if (count > ((row * col) / 2)) 27 | cout << "This is a sparse matrix" << endl; 28 | else 29 | cout << "This is not a sparse matrix" << endl; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /CPP/spiral_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define R 3 4 | #define C 6 5 | 6 | void spiralPrint(int m, int n, int a[R][C]) 7 | { 8 | int i, k = 0, l = 0; 9 | 10 | /* k - starting row index 11 | m - ending row index 12 | l - starting column index 13 | n - ending column index 14 | i - iterator 15 | */ 16 | 17 | while (k < m && l < n) { 18 | /* Print the first row from 19 | the remaining rows */ 20 | for (i = l; i < n; ++i) { 21 | cout << a[k][i] << " "; 22 | } 23 | k++; 24 | 25 | /* Print the last column 26 | from the remaining columns */ 27 | for (i = k; i < m; ++i) { 28 | cout << a[i][n - 1] << " "; 29 | } 30 | n--; 31 | 32 | /* Print the last row from 33 | the remaining rows */ 34 | if (k < m) { 35 | for (i = n - 1; i >= l; --i) { 36 | cout << a[m - 1][i] << " "; 37 | } 38 | m--; 39 | } 40 | 41 | /* Print the first column from 42 | the remaining columns */ 43 | if (l < n) { 44 | for (i = m - 1; i >= k; --i) { 45 | cout << a[i][l] << " "; 46 | } 47 | l++; 48 | } 49 | } 50 | } 51 | 52 | /* Driver program to test above functions */ 53 | int main() 54 | { 55 | int a[R][C] = { { 1, 2, 3, 4, 5, 6 }, 56 | { 7, 8, 9, 10, 11, 12 }, 57 | { 13, 14, 15, 16, 17, 18 } }; 58 | 59 | spiralPrint(R, C, a); 60 | return 0; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /CPP/string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | string fname = "ID10t"; 7 | string lname = "Alderson"; 8 | string fullname = fname + lname; 9 | 10 | cout< 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string fname,fullname; 6 | cout<<"fname:"< 2 | 3 | using namespace std; 4 | 5 | struct Shagun 6 | { 7 | char name[20]; 8 | int age; 9 | float grade; 10 | }; 11 | 12 | int main() 13 | { 14 | Shagun st; 15 | cout << "Enter apka naam:" << endl; 16 | cin.get(st.name, 50); 17 | cout << "Appki umar kya he:" << endl; 18 | cin >> st.age; 19 | cout << "Apke kitne marks aaye he is bar:" << endl; 20 | cin >> st.grade; 21 | 22 | cout << "Jankari:" << endl; 23 | cout << "Naam:" << st.name << endl; 24 | cout << "Umar:" << st.age << endl; 25 | cout << "ank:" << st.grade << endl; 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /CPP/sumNums.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int sumNums(const string& s) 6 | { 7 | int sum = 0; 8 | int num = 0; 9 | for (size_t i = 0, len = s.size(); i <= len - 1; i++) 10 | { 11 | char digit = s.at(i); 12 | if (isdigit(digit)) 13 | { 14 | digit -= '0'; 15 | num *= 10; 16 | num += digit; 17 | } 18 | else 19 | { 20 | sum += num; 21 | num = 0; 22 | } 23 | } 24 | sum += num; 25 | return sum; 26 | } 27 | -------------------------------------------------------------------------------- /CPP/text.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void text(const char* message) { 5 | std::cout << message << std::endl; 6 | } -------------------------------------------------------------------------------- /CPP/userinput.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int x,y; 6 | int sum; 7 | cout<<"ALadin madafaka:"; 8 | cin>>x; 9 | cout<<"once more madafaka:"; 10 | cin>>y; 11 | sum = x+y; 12 | std::cout<<"SUM iz:"< 2 | 3 | 4 | 5 | 6 | ForIf 7 | 8 | 9 | 10 | 11 | 35 | 36 | -------------------------------------------------------------------------------- /HTML/alert.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Alert Javascript 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /HTML/bg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/infiniteoverflow/contribute_ur_code/79e7ba32b965d7ef5a3fe081814be9800fb92102/HTML/bg.jpeg -------------------------------------------------------------------------------- /HTML/do.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | While 7 | 8 | 9 | 10 | 18 | 19 | -------------------------------------------------------------------------------- /HTML/for.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Looping For 7 | 8 | 9 | 10 | 23 | 24 | -------------------------------------------------------------------------------- /HTML/function.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | function 7 | 8 | 9 | 10 | 28 | 29 | -------------------------------------------------------------------------------- /HTML/hello_world.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTML page 6 | 7 | 11 | here give the link of the you image in href attribute. 12 | 13 | --! > 14 | 15 | 16 | 17 |
18 |

19 |

Hello World!

20 |

21 | 22 | 23 | -------------------------------------------------------------------------------- /HTML/matrix.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | -------------------------------------------------------------------------------- /HTML/onChange.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Menampilkan Hari 7 | 8 | 9 | 10 |
17 | 18 | 23 | 24 |

25 |

26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /HTML/operators.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Table Javascript 6 | 7 | 8 | 15 | 16 | -------------------------------------------------------------------------------- /HTML/partial.php: -------------------------------------------------------------------------------- 1 | text1 = "
AJAX = Asynchronous JavaScript And XML.
 7 | 
 8 | AJAX is not a programming language.
 9 | 
10 | AJAX just uses a combination of:
11 | 
12 |     A browser built-in XMLHttpRequest object (to request data from a web server)
13 |     JavaScript and HTML DOM (to display or use the data)
14 | 
15 | AJAX is a misleading name. AJAX applications might use XML to transport data, but it is equally common to transport data as plain text or JSON text.
16 | 
"; 17 | 18 | $res->text2 = "

Change my text using AJAX

"; 19 | 20 | $res->button1 = ""; 21 | 22 | $res->button2 = ""; 23 | 24 | $my_JSON = json_encode($res); 25 | 26 | echo $my_JSON; 27 | ?> -------------------------------------------------------------------------------- /HTML/partialpagerefresh.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Partial Page Refresh 10 | 36 | 37 | 38 |
39 |

Change my text using AJAX

40 | 41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /HTML/style.css: -------------------------------------------------------------------------------- 1 | @import "https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"; 2 | body{ 3 | margin: 0; 4 | padding: 0; 5 | font-family: cursive; 6 | background: url(bg.jpeg) no-repeat; 7 | background-size: cover; 8 | } -------------------------------------------------------------------------------- /HTML/while.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | While 7 | 8 | 9 | 10 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /JAVA/DiameterOfBinaryTree.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | 4 | class TreeNode { 5 | int val; 6 | TreeNode left; 7 | TreeNode right; 8 | 9 | public TreeNode(int val){ 10 | this.val = val; 11 | } 12 | } 13 | 14 | 15 | public class DiameterOfBinaryTree{ 16 | int ans = 0; 17 | 18 | public int diameterOfBinaryTree(TreeNode root){ 19 | if(root == null) return 0; 20 | TreeNode left = diameterOfBinaryTree(root.left); 21 | TreeNode right = diameterOfBinaryTree(root.right); 22 | ans = Math.max(left+right, ans); 23 | return 1 + Math.max(left, right); 24 | } 25 | 26 | public static void main(String[] args){ 27 | diameterOfBinaryTree(root); 28 | System.out.println(ans); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /JAVA/DiamondPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class DiamondPattern{ 5 | public static void main(String[] args){ 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int i,j,k=1; 9 | for(i=1;i<=n;i++){ 10 | for(j=1;j<=k+1;j++){ 11 | System.out.print(" "); 12 | } 13 | k--; 14 | for(j=1;j<=2*i-1;j++){ 15 | System.out.print("*"); 16 | } 17 | System.out.println(""); 18 | } 19 | k=1; 20 | for(i=1;i<=n-1;i++){ 21 | for(j=1;j<=k;j++){ 22 | System.out.print(" "); 23 | } 24 | k++; 25 | for(j=1;j<=2*(n-i)-1;j++){ 26 | System.out.print("*"); 27 | } 28 | System.out.println(""); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /JAVA/FibonacciSeries.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class FibonacciSeries { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the limit:"); 9 | int number = sc.nextInt(); 10 | 11 | int a = 0; 12 | int b = 0; 13 | int c = 1; 14 | 15 | for(int i = 0; i <= number; i++) { 16 | a = b; 17 | b = c; 18 | c = a + b; 19 | System.out.println(a + ""); 20 | } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /JAVA/FindPalindrome.java: -------------------------------------------------------------------------------- 1 | class FindPalindrome { 2 | public static void main(String[] args) { 3 | //tests 4 | //true 5 | String test = "racecar"; 6 | System.out.println(isPalindrome(test, 0, test.length()-1)); 7 | 8 | //false 9 | test = "billy"; 10 | System.out.println(isPalindrome(test, 0, test.length()-1)); 11 | 12 | 13 | } 14 | 15 | //check if string is Palindrome 16 | static boolean isPalindrome(String s, int left, int right) { 17 | while(left < right) { 18 | if(s.charAt(left) != s.charAt(right)) { 19 | return false; 20 | } 21 | 22 | left++; 23 | right--; 24 | } 25 | 26 | return true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /JAVA/Floyd_algorithm.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class floyd 3 | { 4 | public static void Floyds(int a[][],int n) 5 | { 6 | int i,j,k; 7 | int d[][]=new int[10][10]; 8 | for(i=1;i<=n;i++) 9 | { 10 | for(j=1;j<=n;j++) 11 | { 12 | d[i][j]=a[i][j]; 13 | 14 | } 15 | } 16 | for(k=1;k<=n;k++) 17 | { 18 | for(i=1;i<=n;i++) 19 | { 20 | for(j=1;j<=n;j++) 21 | { 22 | d[i][j]=min(d[i][j],d[i][k]+d[k][j]); 23 | } 24 | } 25 | } 26 | System.out.println("\nThe distance matrix is\n"); 27 | for(i=1;i<=n;i++) 28 | { 29 | for(j=1;j<=n;j++) 30 | { 31 | System.out.print(+d[i][j]+"\t"); 32 | } 33 | System.out.println("\n"); 34 | } 35 | } 36 | public static int min(int a,int b) 37 | { 38 | if(a=0; i--) { 10 | reverse.append(letters[i]); 11 | } 12 | 13 | System.out.println(reverse); 14 | 15 | if(str.equals(reverse.toString())) { 16 | System.out.println("Input is palindrome."); 17 | } 18 | else { 19 | System.out.println("Input is not palindrome."); 20 | } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /JAVA/SwapNumbers.java: -------------------------------------------------------------------------------- 1 | public class SwapNumbers { 2 | 3 | public static void main(String[] args) { 4 | 5 | int x = 75; 6 | int y = 50; 7 | 8 | System.out.println("Before Swapping\nx = " + x + "\ny = " + y); 9 | 10 | x = x + y; 11 | y = x - y; 12 | x = x - y; 13 | 14 | System.out.println("After Swapping\nx = " + x + "\ny = " + y); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /JAVA/TowerOfHanoi.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TowerOfHanoi { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | System.out.print("Enter number of disks: "); 9 | int noOfDisks = scanner.nextInt(); 10 | 11 | towerOfHanoi(noOfDisks, 'A', 'C', 'B'); 12 | } 13 | 14 | private static void towerOfHanoi(int n, char from_rod, char to_rod, char auxillary_rod) { 15 | if (n == 1) { 16 | System.out.println("Move disk 1 from rod " + from_rod + " to rod " + to_rod); 17 | return; 18 | } 19 | towerOfHanoi(n - 1, from_rod, auxillary_rod, to_rod); 20 | System.out.println("Move disk " + n + " from rod " + from_rod + " to rod " + to_rod); 21 | towerOfHanoi(n - 1, auxillary_rod, to_rod, from_rod); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /JAVA/VowelConsonant.java: -------------------------------------------------------------------------------- 1 | public class VowelConsonant { 2 | 3 | public static void main(String[] args) { 4 | 5 | char ch = 'i'; 6 | 7 | if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ) 8 | System.out.println(ch + " is vowel"); 9 | else 10 | System.out.println(ch + " is consonant"); 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /JAVA/merge_sort/.idea/description.html: -------------------------------------------------------------------------------- 1 | Simple Java application that includes a class with main() method -------------------------------------------------------------------------------- /JAVA/merge_sort/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /JAVA/merge_sort/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /JAVA/merge_sort/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JAVA/merge_sort/.idea/project-template.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /JAVA/merge_sort/merge_sort.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /JAVA/merge_sort/out/production/merge_sort/com/sunchit/company/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/infiniteoverflow/contribute_ur_code/79e7ba32b965d7ef5a3fe081814be9800fb92102/JAVA/merge_sort/out/production/merge_sort/com/sunchit/company/Main.class -------------------------------------------------------------------------------- /JAVA/palindrome.java: -------------------------------------------------------------------------------- 1 | //Program to display only Palindrome Words in a sentence 2 | 3 | import java.util.*; 4 | class Paln 5 | { 6 | static void teja() 7 | { 8 | Scanner in = new Scanner(System.in); 9 | System.out.println(“Enter the Sentence : “); 10 | while(in.hasNext()) 11 | { 12 | String st = in.next(); 13 | int l = st.length(); 14 | String rev=””; 15 | for(int i=0;iSimple Java application that includes a class with main() method -------------------------------------------------------------------------------- /JAVA/quick_sort/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /JAVA/quick_sort/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /JAVA/quick_sort/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JAVA/quick_sort/.idea/project-template.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /JAVA/quick_sort/out/production/quick_sort/com/sunchit/company/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/infiniteoverflow/contribute_ur_code/79e7ba32b965d7ef5a3fe081814be9800fb92102/JAVA/quick_sort/out/production/quick_sort/com/sunchit/company/Main.class -------------------------------------------------------------------------------- /JAVA/quick_sort/quick_sort.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /JavaScript/Prime_No_finder.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /JavaScript/arrayOfCars.js: -------------------------------------------------------------------------------- 1 | // Array that shows an inventory of cars 2 | // display's car id, car_type, car_make, car_model, and year 3 | 4 | const Cars = [ 5 | {id: 1, car_type: Sedan, car_make: Nissan, car_model: Versa, year: 2012}, 6 | {id: 2, car_type: SUV, car_make: Honda, car_model: Pilot, year: 2017}, 7 | {id: 3, car_type: Sedan, car_make: Honda, car_model: Accord, year: 2012}, 8 | {id: 4, car_type: SUV, car_make: Acura, car_model: MDX, year: 2017}, 9 | {id: 5, car_type: Coupe, car_make: Chevrolet, car_model: Camaro, year: 2012}, 10 | {id: 6, car_type: Sedan, car_make: Nissan, car_model: Maxima, year: 2020}, 11 | {id: 7, car_type: Coupe, car_make: Chevrolet, car_model: Corvette, year: 2020}, 12 | ] 13 | 14 | // **** How to retrieve values from an array **** 15 | 16 | // Getting all the different car models 17 | 18 | const getCarModel = (cars) => { 19 | 20 | let carModel = [] 21 | 22 | for(let i = 0; i < cars.length; i++) { 23 | carModel.push(cars[i].car_model) 24 | } 25 | 26 | return carModel; 27 | 28 | } 29 | 30 | 31 | // Getting all the different car make 32 | 33 | const getCarMake = (inventory) => { 34 | 35 | let carMake = [] 36 | 37 | for(let i = 0; inventory.length; i++) { 38 | carMake.push(inventory[i].car_make) 39 | } 40 | 41 | return carMake; 42 | } 43 | -------------------------------------------------------------------------------- /JavaScript/average.js: -------------------------------------------------------------------------------- 1 | const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length; -------------------------------------------------------------------------------- /JavaScript/helloworld.js: -------------------------------------------------------------------------------- 1 | ///Simple Hello World Program For Begineers 2 | ///print in Console --> 3 | console.log("Hello World"); 4 | ///Print Hello World in Document / Screen ---> 5 | document.write("Hello World"); 6 | -------------------------------------------------------------------------------- /JavaScript/reverseInt.js: -------------------------------------------------------------------------------- 1 | //Q. Given an integer, return an integer that is the reverse 2 | // ordering of numbers. 3 | // --- Examples 4 | // reverseInt(-42) === -24 5 | // reverseInt(-90) === -9 6 | 7 | function reverseInt(n) { 8 | const reversed = n 9 | .toString() 10 | .split('') 11 | .reverse() 12 | .join(''); 13 | 14 | return parseInt(reversed) * Math.sign(n); 15 | } 16 | 17 | module.exports = reverseInt; 18 | -------------------------------------------------------------------------------- /JavaScript/reverseString.js: -------------------------------------------------------------------------------- 1 | //Q. Given a string, return a new string with the reversed 2 | // order of characters 3 | // --- Examples 4 | // reverse('hello') === 'olleh' 5 | 6 | function reverse(str) { 7 | return str 8 | .split('') 9 | .reverse() 10 | .join(''); 11 | } 12 | 13 | module.exports = reverse; 14 | -------------------------------------------------------------------------------- /JavaScript/selectCategoryWithFilter.js: -------------------------------------------------------------------------------- 1 | // This is an exercise to show how Array.prototype.filter() works 2 | // We'll have a list of products and filter them by category 3 | 4 | // List of products 5 | const products = [ 6 | { "name": "Smartphone", "category": "Technology" }, 7 | { "name": "Laptop", "category": "Technology" }, 8 | { "name": "Mug", "category": "Kitchen" }, 9 | { "name": "The Hitchhiker's Guide to the Galaxy", "category": "Book" }, 10 | { "name": "Smart TV", "category": "Technology" }, 11 | { "name": "Coffee", "category": "Food" }, 12 | { "name": "Chocolate", "category": "Food" } 13 | ] 14 | 15 | // The Array.prototype.fitler() will return a NEW ARRAY with all elements that pass the test 16 | let selectedProducts = products.filter(function(element) { 17 | // If this condition is true add this element in the new array 18 | return element.category === "Technology" 19 | }) 20 | 21 | console.log(selectedProducts) -------------------------------------------------------------------------------- /JavaScript/settimeout.js: -------------------------------------------------------------------------------- 1 | const settimeout = (ms) => { 2 | setTimeout(function(){ 3 | alert("Hello"); 4 | }, ms); 5 | } 6 | -------------------------------------------------------------------------------- /JavaScript/string-case-conversor.js: -------------------------------------------------------------------------------- 1 | function snake_case(str) { 2 | return str 3 | .trim() 4 | .replace(/\s/gi, "_") 5 | .replace( 6 | /[a-z][A-Z]/g, 7 | str => 8 | str.charAt(0).toLocaleLowerCase() + 9 | "_" + 10 | str.charAt(1).toLocaleLowerCase() 11 | ) 12 | .toLocaleLowerCase() 13 | } 14 | 15 | function camelCase(str) { 16 | return str 17 | .toLocaleLowerCase() 18 | .trim() 19 | .replace(/\s*\b\S/gi, str => str.toLocaleUpperCase().trim()) 20 | .replace(/_\S/gi, str => str.charAt(1).toLocaleUpperCase()) 21 | } 22 | 23 | function PascalCase(str) { 24 | return str 25 | .toLocaleLowerCase() 26 | .trim() 27 | .replace(/^\S/gi, str => str.toLocaleUpperCase().trim()) 28 | .replace(/\s*\b\S/gi, str => str.toLocaleUpperCase().trim()) 29 | .replace(/_\S/, str => str.charAt(1).toLocaleUpperCase()) 30 | } 31 | -------------------------------------------------------------------------------- /JavaScript/sum-array.js: -------------------------------------------------------------------------------- 1 | const total = [1, 2, 3].reduce((a,b) => a + b, 0); -------------------------------------------------------------------------------- /JavaScript/totalValueWithReduce.js: -------------------------------------------------------------------------------- 1 | // This is an exercise to show how Array.prototype.reduce() works 2 | // We'll add all the products price to get the total price using reduce and map 3 | 4 | // List of products 5 | const products = [ 6 | { "name": "Smartphone", "category": "Technology", "price": 499.99 }, 7 | { "name": "Laptop", "category": "Technology", "price": 699.99 }, 8 | { "name": "Mug", "category": "Kitchen", "price": 4.99 }, 9 | { "name": "The Hitchhiker's Guide to the Galaxy", "category": "Book", "price": 19.99 }, 10 | { "name": "Smart TV", "category": "Technology", "price": 799.99 }, 11 | { "name": "Coffee", "category": "Food", "price": 5.99 }, 12 | { "name": "Chocolate", "category": "Food", "price": 2.99 } 13 | ] 14 | 15 | // Return the price of an element 16 | let getPrices = function(element) { 17 | return element.price 18 | } 19 | 20 | // The method map returns just the field "price" and reduce are accumulating the value of each element to get the total price 21 | let totalPrice = products.map(getPrices).reduce(function (accumulator, currentValue) { 22 | return accumulator + currentValue 23 | }) 24 | 25 | console.log(totalPrice) -------------------------------------------------------------------------------- /Kotlin/CurrentTime.kt: -------------------------------------------------------------------------------- 1 | import java.time.LocalDateTime 2 | fun main() { 3 | val current = LocalDateTime.now() 4 | println("Current Date and Time is: $current") 5 | } 6 | -------------------------------------------------------------------------------- /Kotlin/check_palindrome_num.kt: -------------------------------------------------------------------------------- 1 | //Program to Check Palindrome 2 | 3 | fun main(args: Array) { 4 | var num = 121 5 | var reversedInteger = 0 6 | var remainder: Int 7 | val originalInteger: Int 8 | originalInteger = num 9 | // reversed integer is stored in variable 10 | while (num != 0) { 11 | remainder = num % 10 12 | reversedInteger = reversedInteger * 10 + remainder 13 | num /= 10 14 | } 15 | // palindrome if orignalInteger and reversedInteger are equal 16 | if (originalInteger == reversedInteger) 17 | println("$originalInteger is a palindrome.") 18 | else 19 | println("$originalInteger is not a palindrome.") 20 | } -------------------------------------------------------------------------------- /Kotlin/fibonaaci.kt: -------------------------------------------------------------------------------- 1 | fun main(args: Array) { 2 | val n = 10 3 | var t1 = 0 4 | var t2 = 1 5 | 6 | print("First $n terms: ") 7 | for (i in 1..n) { 8 | print("$t1 + ") 9 | val sum = t1 + t2 10 | t1 = t2 11 | t2 = sum 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kotlin/find_num_in_array.kt: -------------------------------------------------------------------------------- 1 | 2 | //Check if Int Array contains a given value 3 | 4 | fun main(args: Array) { 5 | val num = intArrayOf(1, 2, 3, 4, 5) 6 | val toFind = 3 7 | var found = false 8 | for (n in num) { 9 | if (n == toFind) { 10 | found = true 11 | break 12 | } 13 | } 14 | if (found) 15 | println("$toFind is found.") 16 | else 17 | println("$toFind is not found.") 18 | } -------------------------------------------------------------------------------- /Kotlin/is_pangram.kt: -------------------------------------------------------------------------------- 1 | fun main(phrase: String) { 2 | val aux: CharArray = phrase.toLowerCase().toCharArray() // convert the given phrase to a lowercase char array 3 | val presence: BooleanArray = BooleanArray(26) // keep track of the presence of every distinct letter 4 | 5 | for(c: Char in aux) { 6 | if((c.toInt() >= 97) and (c.toInt() <= 122)) // ascii value check (a-z) 7 | presence[122-c.toInt()] = true 8 | } 9 | 10 | for(element in presence) { 11 | if(!element) 12 | return false 13 | } 14 | 15 | return true 16 | } 17 | -------------------------------------------------------------------------------- /Kotlin/string_to_date.kt: -------------------------------------------------------------------------------- 1 | import java.time.LocalDate 2 | import java.time.format.DateTimeFormatter 3 | fun main(args: Array) { 4 | // Format y-M-d or yyyy-MM-d 5 | val string = "2017-07-25" 6 | val date = LocalDate.parse(string, DateTimeFormatter.ISO_DATE) 7 | println(date) 8 | } -------------------------------------------------------------------------------- /OCaml/len.ml: -------------------------------------------------------------------------------- 1 | (* Find length of a list. Usage: len [a;b;c];; *) 2 | let len list = 3 | let rec aux n = function 4 | | [] -> n 5 | | _::t -> aux (n+1) t 6 | in aux 0 list;; 7 | -------------------------------------------------------------------------------- /PHP/helloworld.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Python/29.Word_Count.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. 3 | 4 | Note: 5 | 6 | The same word in the dictionary may be reused multiple times in the segmentation. 7 | You may assume the dictionary does not contain duplicate words. 8 | Example 1: 9 | 10 | Input: s = "leetcode", wordDict = ["leet", "code"] 11 | Output: true 12 | Explanation: Return true because "leetcode" can be segmented as "leet code". 13 | Example 2: 14 | 15 | Input: s = "applepenapple", wordDict = ["apple", "pen"] 16 | Output: true 17 | Explanation: Return true because "applepenapple" can be segmented as "apple pen apple". 18 | Note that you are allowed to reuse a dictionary word. 19 | Example 3: 20 | 21 | Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] 22 | Output: false 23 | 24 | 25 | ''' 26 | 27 | class Solution: 28 | def wordBreak(self, s, words): 29 | ok = [True] 30 | max_len = max(map(len,words+[''])) 31 | words = set(words) 32 | for i in range(1, len(s)+1): 33 | ok += any(ok[j] and s[j:i] in words for j in range(max(0, i-max_len),i)), 34 | return ok[-1] -------------------------------------------------------------------------------- /Python/8.Sum_of_Root_To_Leaf_Binary_Numbers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13. 3 | 4 | For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. 5 | 6 | Return the sum of these numbers. 7 | 8 | 9 | 10 | Example 1: 11 | 12 | 13 | 14 | Input: [1,0,1,0,1,0,1] 15 | Output: 22 16 | Explanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22 17 | 18 | 19 | Note: 20 | 21 | The number of nodes in the tree is between 1 and 1000. 22 | node.val is 0 or 1. 23 | The answer will not exceed 2^31 - 1. 24 | Hide Hint #1 25 | Find each path, then transform that path to an integer in base 10. 26 | 27 | ''' 28 | 29 | # Definition for a binary tree node. 30 | # class TreeNode: 31 | # def __init__(self, val=0, left=None, right=None): 32 | # self.val = val 33 | # self.left = left 34 | # self.right = right 35 | class Solution: 36 | def sumRootToLeaf(self, root): 37 | def dfs(node): 38 | if not node.left and not node.right: self.sum += node.val 39 | for child in filter(None, [node.left, node.right]): 40 | child.val += node.val * 2 41 | dfs(child) 42 | 43 | self.sum = 0 44 | dfs(root) 45 | return self.sum -------------------------------------------------------------------------------- /Python/Abracadabra.py: -------------------------------------------------------------------------------- 1 | while True: 2 | try: 3 | palavra = input() 4 | palavra = ''.join(list(map(lambda x: x+' ', list(palavra)))) 5 | for i in range(len(palavra) // 2): 6 | print(palavra[:-1]) 7 | palavra = ' ' + palavra[:-2] 8 | 9 | print() 10 | except EOFError: 11 | break 12 | -------------------------------------------------------------------------------- /Python/BlacknWhite_WebCam.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | cap = cv2.VideoCapture(0) 5 | 6 | while(True): 7 | # Capture frame-by-frame 8 | ret, frame = cap.read() 9 | 10 | # Our operatios on the frame come here 11 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 12 | 13 | # Display the resulting frame 14 | cv2.imshow('frame', gray) 15 | if(cv2.waitKey(1) & 0xFF == ord('q')): 16 | break 17 | 18 | # When everything done, release the capture 19 | cap.release() 20 | cv2.destroyAllWindows() 21 | -------------------------------------------------------------------------------- /Python/BubbleSort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Bubble Sort 2 | 3 | def bubbleSort(arr): 4 | n = len(arr) 5 | 6 | # Traverse through all array elements 7 | for i in range(n): 8 | 9 | # Last i elements are already in place 10 | for j in range(0, n-i-1): 11 | 12 | # traverse the array from 0 to n-i-1 13 | # Swap if the element found is greater 14 | # than the next element 15 | if arr[j] > arr[j+1] : 16 | arr[j], arr[j+1] = arr[j+1], arr[j] 17 | 18 | # Driver code to test above 19 | arr = [64, 34, 25, 12, 22, 11, 90] 20 | 21 | bubbleSort(arr) 22 | 23 | print ("Sorted array is:") 24 | for i in range(len(arr)): 25 | print ("%d" %arr[i]) 26 | 27 | -------------------------------------------------------------------------------- /Python/Cops And Robber.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | t=int(input()) 4 | for i in range(t): 5 | count=0 6 | n,k=map(int,input().split()) 7 | for j in range(n): 8 | li=list(map(str,input().split())) 9 | l=len(li) 10 | for ind in range(l): 11 | if(li[ind]=="P"): 12 | if((ind-k)>=0 and ind+k<=l-1): 13 | for s in range(ind-k,ind+k+1): 14 | if(li[s]=="T"): 15 | count+=1 16 | li[s]="X" 17 | break 18 | elif((ind-k)<0 and ind+k<=l-1): 19 | for s in range(ind+1,ind+k+1): 20 | if(li[s]=="T"): 21 | count+=1 22 | li[s]="X" 23 | break 24 | elif((ind-k)>=0 and ind+k>l-1): 25 | for s in range(ind-k,ind): 26 | if(li[s]=="T"): 27 | count+=1 28 | li[s]="X" 29 | break 30 | print(count) 31 | -------------------------------------------------------------------------------- /Python/CountingSort.py: -------------------------------------------------------------------------------- 1 | def counting_sort(nums, k): 2 | count_occurrences = [0] * k 3 | output = [0] * len(nums) 4 | 5 | # count occurrences for each element in the array 6 | for i in range(len(nums)): 7 | count_occurrences[nums[i]] += 1 8 | 9 | # get the running sums 10 | # (The value of occurrenece at i and the value before it) 11 | for i in range(1, k): 12 | count_occurrences[i] += count_occurrences[i-1] 13 | 14 | # place each element where it supposed to be 15 | for i in range(len(nums)): 16 | output[count_occurrences[nums[i]] - 1] = nums[i] 17 | count_occurrences[nums[i]] -= 1 18 | 19 | return output 20 | 21 | 22 | if __name__ == "__main__": 23 | # two test arrays 24 | nums = [2, 5, 3, 0, 2, 3, 0, 3] 25 | nums2 = [4, 2, 2, 8, 3, 3, 1] 26 | 27 | # k must be the range of the input numbers 28 | output = counting_sort(nums2, 9) 29 | # output = counting_sort(nums, 6) 30 | 31 | print(output) 32 | -------------------------------------------------------------------------------- /Python/Face_Detection_In_Live_Webcam.py: -------------------------------------------------------------------------------- 1 | # This script will detect faces via your webcam. 2 | # Tested with OpenCV3 3 | 4 | import cv2 5 | 6 | cap = cv2.VideoCapture(0) 7 | 8 | # Create the haar cascade 9 | faceCascade = cv2.CascadeClassifier("haar_classifiers_for_Image_Processing/haarcascade_frontalface_default.xml") 10 | 11 | while(True): 12 | # Capture frame-by-frame 13 | ret, frame = cap.read() 14 | 15 | # Our operations on the frame come here 16 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 17 | 18 | # Detect faces in the image 19 | faces = faceCascade.detectMultiScale( 20 | gray, 21 | scaleFactor=1.1, 22 | minNeighbors=5, 23 | minSize=(30, 30) 24 | #flags = cv2.CV_HAAR_SCALE_IMAGE 25 | ) 26 | 27 | print("Found {0} faces!".format(len(faces))) 28 | 29 | # Draw a rectangle around the faces 30 | for (x, y, w, h) in faces: 31 | cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) 32 | 33 | 34 | # Display the resulting frame 35 | cv2.imshow('frame', frame) 36 | if cv2.waitKey(1) & 0xFF == ord('q'): 37 | break 38 | 39 | # When everything done, release the capture 40 | cap.release() 41 | cv2.destroyAllWindows() 42 | -------------------------------------------------------------------------------- /Python/Face_Extractor_In_Live_Webcam.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | face_classifier = cv2.CascadeClassifier('haar_classifiers_for_Image_Processing/haarcascade_frontalface_default.xml') 5 | eye_classifier = cv2.CascadeClassifier('haar_classifiers_for_Image_Processing/haarcascade_eye.xml') 6 | 7 | def face_detector(img, size=0.5): 8 | # Convert image to grayscale 9 | gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 10 | faces = face_classifier.detectMultiScale(gray, 1.3, 5) 11 | if faces is (): 12 | return img 13 | for (x,y,w,h) in faces: 14 | x = x - 50 15 | w = w + 50 16 | y = y - 50 17 | h = h + 50 18 | cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) 19 | roi_gray = gray[y:y+h, x:x+w] 20 | roi_color = img[y:y+h, x:x+w] 21 | eyes = eye_classifier.detectMultiScale(roi_gray) 22 | for (ex,ey,ew,eh) in eyes: 23 | cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,0,255),2) 24 | roi_color = cv2.flip(roi_color,1) 25 | return roi_color 26 | 27 | cap = cv2.VideoCapture(0) 28 | 29 | while True: 30 | 31 | ret, frame = cap.read() 32 | cv2.imshow('Our Face Extractor', face_detector(frame)) 33 | if cv2.waitKey(1) == 13: #13 is the Enter Key 34 | break 35 | 36 | cap.release() 37 | cv2.destroyAllWindows() 38 | -------------------------------------------------------------------------------- /Python/FindQuotedWords.py: -------------------------------------------------------------------------------- 1 | sentance = input('Enter a sentence: ') 2 | for word in sentance.split(): 3 | if word.startswith('"') and word.endswith('"'): 4 | print(word) 5 | -------------------------------------------------------------------------------- /Python/Geometric_Sum.py: -------------------------------------------------------------------------------- 1 | 2 | #Program to find geometeric sum , with input k 3 | #The given form is geometric series and we will find sum of this series 4 | #1 + 1/2 + 1/4 + 1/8 + ... + 1/(2^k) 5 | 6 | 7 | 8 | def find(k): 9 | if(k==0): 10 | return 1 11 | a=1/2**k 12 | return (a+find(k-1)) 13 | k=int(input()) 14 | print("{:.5f}".format(find(k))) -------------------------------------------------------------------------------- /Python/Google API/README.md: -------------------------------------------------------------------------------- 1 | USING GOOGLE API FOR STUDY PURPOSE ONLY TO GET GIVEN LOCATION 2 | RUN GEOLOAD.PY FIRST THEN GEODUMP.PY THEN OPEN WHERE.HTML 3 | -------------------------------------------------------------------------------- /Python/Google API/geodump.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import json 3 | import codecs 4 | 5 | conn = sqlite3.connect('geodata.sqlite') 6 | cur = conn.cursor() 7 | 8 | cur.execute('SELECT * FROM Locations') 9 | fhand = codecs.open('where.js', 'w', "utf-8") 10 | fhand.write("myData = [\n") 11 | count = 0 12 | for row in cur : 13 | data = str(row[1].decode()) 14 | try: js = json.loads(str(data)) 15 | except: continue 16 | 17 | if not('status' in js and js['status'] == 'OK') : continue 18 | 19 | lat = js["results"][0]["geometry"]["location"]["lat"] 20 | lng = js["results"][0]["geometry"]["location"]["lng"] 21 | if lat == 0 or lng == 0 : continue 22 | where = js['results'][0]['formatted_address'] 23 | where = where.replace("'", "") 24 | try : 25 | print(where, lat, lng) 26 | 27 | count = count + 1 28 | if count > 1 : fhand.write(",\n") 29 | output = "["+str(lat)+","+str(lng)+", '"+where+"']" 30 | fhand.write(output) 31 | except: 32 | continue 33 | 34 | fhand.write("\n];\n") 35 | cur.close() 36 | fhand.close() 37 | print(count, "records written to where.js") 38 | print("Open where.html to view the data in a browser") 39 | 40 | -------------------------------------------------------------------------------- /Python/Heap_sort.py: -------------------------------------------------------------------------------- 1 | # To heapify subtree rooted at index i. 2 | # n is size of heap 3 | def heapify(arr, n, i): 4 | largest = i # Initialize largest as root 5 | l = 2 * i + 1 # left = 2*i + 1 6 | r = 2 * i + 2 # right = 2*i + 2 7 | 8 | # See if left child of root exists and is 9 | # greater than root 10 | if l < n and arr[i] < arr[l]: 11 | largest = l 12 | 13 | # See if right child of root exists and is 14 | # greater than root 15 | if r < n and arr[largest] < arr[r]: 16 | largest = r 17 | 18 | # Change root, if needed 19 | if largest != i: 20 | arr[i],arr[largest] = arr[largest],arr[i] # swap 21 | 22 | # Heapify the root. 23 | heapify(arr, n, largest) 24 | 25 | # The main function to sort an array of given size 26 | def heapSort(arr): 27 | n = len(arr) 28 | 29 | # Build a maxheap. 30 | for i in range(n, -1, -1): 31 | heapify(arr, n, i) 32 | 33 | # One by one extract elements 34 | for i in range(n-1, 0, -1): 35 | arr[i], arr[0] = arr[0], arr[i] # swap 36 | heapify(arr, i, 0) 37 | 38 | # Driver code to test above 39 | arr = [ 12, 11, 13, 5, 6, 7] 40 | heapSort(arr) 41 | n = len(arr) 42 | print ("Sorted array is") 43 | for i in range(n): 44 | print ("%d" %arr[i]) 45 | -------------------------------------------------------------------------------- /Python/InsertionSort.py: -------------------------------------------------------------------------------- 1 | def insertion_sort(nums): 2 | for j in range(1, len(nums)): 3 | key = nums[j] 4 | i = j-1 5 | while i > -1 and nums[i] > key: 6 | nums[i+1] = nums[i] 7 | i -= 1 8 | nums[i+1] = key 9 | 10 | if __name__ == "__main__": 11 | nums = [5, 2, 4, 6, 1, 3] 12 | insertion_sort(nums) 13 | print(nums) 14 | -------------------------------------------------------------------------------- /Python/Length_of_Linked_List.py: -------------------------------------------------------------------------------- 1 | #Python Program to find the length of the given linked list 2 | 3 | 4 | 5 | class Node: 6 | #Initializing the linked list 7 | def __init__(self, data): 8 | self.data = data 9 | self.next = None 10 | 11 | 12 | #calculating length of Linked List 13 | def length(head): 14 | count=0 15 | 16 | while head is not None: 17 | head=head.next 18 | count=count+1 19 | 20 | return count 21 | 22 | # Creating a Linked list 23 | def ll(arr): 24 | if len(arr)==0: 25 | return None 26 | head = Node(arr[0]) 27 | last = head 28 | for data in arr[1:]: 29 | last.next = Node(data) 30 | last = last.next 31 | return head 32 | 33 | # Main 34 | # Reading the link list elements including -1 (-1 to terminate) 35 | arr=list(int(i) for i in input().strip().split(' ')) 36 | # Creating a Linked list after removing -1 from list 37 | l = ll(arr[:-1]) 38 | len=length(l) 39 | print(len) 40 | -------------------------------------------------------------------------------- /Python/Link_shortner.py: -------------------------------------------------------------------------------- 1 | ##import bitly_api 2 | ## 3 | ##API_USER = 'USERNAME' 4 | ##API_KEY = 'API_KEY' 5 | ##bitly = bitly_api.Connection(API_USER, API_KEY) 6 | ## 7 | ##response = bitly.shorten("www.mysite.com") 8 | ## 9 | ##print(response) 10 | ## 11 | ############################################################### 12 | ## 13 | import bitly_api 14 | 15 | BITLY_ACCESS_TOKEN ="ACCESS_TOKEN_HERE" 16 | 17 | b = bitly_api.Connection(access_token = BITLY_ACCESS_TOKEN) 18 | 19 | response = b.shorten('URL') 20 | print(response) 21 | ## 22 | ################################################################ 23 | ## 24 | ##from pyshorteners import Shortener 25 | ## 26 | ##url = 'http://www.godaddy.com' 27 | ##shortener = Shortener('Tinyurl') 28 | ##shortener = Shortener('Isgd') 29 | ##s = (shortener.short(url)) 30 | ##print ("My long url is {}".format(s)) 31 | ## 32 | ##### expanding 33 | ##url = 'http://tinyurl.com/ycus76' 34 | ##print ("My long url is {}".format(shortener.expand(url))) 35 | ##url = 'http://is.gd/SsaC' 36 | ##print ("My long url is {}".format(shortener.expand(s))) 37 | -------------------------------------------------------------------------------- /Python/MRO.py: -------------------------------------------------------------------------------- 1 | 2 | # Python program to show the order 3 | # in which methods are resolved 4 | 5 | class A: 6 | def rk(self): 7 | print(" In class A") 8 | class B: 9 | def rk(self): 10 | print(" In class B") 11 | 12 | # classes ordering 13 | class C(A, B): 14 | def __init__(self): 15 | print("Constructor C") 16 | 17 | r = C() 18 | 19 | # it prints the lookup order 20 | print(C.__mro__) 21 | print(C.mro()) 22 | -------------------------------------------------------------------------------- /Python/Maitreyi88_armstrongno.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[5]: 5 | 6 | 7 | a=int(input("Enter a number: ")) 8 | sum = 0 9 | temp = a 10 | while temp > 0: 11 | digit = temp % 10 12 | sum += digit ** 3 13 | temp //= 10 14 | if a == sum: 15 | print(a,"is an Armstrong number") 16 | else: 17 | print(a,"is not an Armstrong number") 18 | 19 | -------------------------------------------------------------------------------- /Python/Maitreyi88_fibonacci.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[30]: 5 | 6 | 7 | a= int(input("Input integer: ")) 8 | def fibo(a): 9 | a1, a2 = 0, 1 10 | a3 = 0 11 | if a == 1: 12 | print("Fibonacci sequence upto",a,":",a1) 13 | else: 14 | print("Fibonacci sequence:") 15 | while a3 <= a: 16 | print(a1,end=" ") 17 | a3 = a1 + a2 18 | a1 = a2 19 | a2 = a3 20 | fibo(a) 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Python/Maitreyi88_palindrome.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[10]: 5 | 6 | 7 | a=input("Enter a string :") 8 | if a==a[::-1]: 9 | print("Input string",a ," is a palindrome") 10 | else: 11 | print("It is not a palindrome") 12 | 13 | -------------------------------------------------------------------------------- /Python/Maitreyi88_primeno.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[17]: 5 | 6 | 7 | a=int(input("Enter a number:")) 8 | if a> 1: 9 | for i in range(2,a): 10 | if (a % i) == 0: 11 | print(a,"is not a prime number") 12 | break 13 | else: 14 | print(a,"is a prime number") 15 | else: 16 | print(a,"is not a prime number") 17 | 18 | -------------------------------------------------------------------------------- /Python/MergeSort.py: -------------------------------------------------------------------------------- 1 | def merge_sort(nums, start, end): 2 | if start < end: 3 | mid = (start + (end-1)) // 2 4 | merge_sort(nums, start, mid) 5 | merge_sort(nums, mid + 1, end) 6 | merge(nums, start, mid, end) 7 | 8 | 9 | def merge(nums, start, mid, end): 10 | n1 = mid - start + 1 11 | n2 = end - mid 12 | 13 | left = [0] * (n1) 14 | right = [0] * (n2) 15 | 16 | for i in range(n1): 17 | left[i] = nums[start + i] 18 | for j in range(n2): 19 | right[j] = nums[mid + 1 + j] 20 | 21 | i, j = 0, 0 22 | k = start 23 | 24 | while i < n1 and j < n2: 25 | if left[i] <= right[j]: 26 | nums[k] = left[i] 27 | i += 1 28 | else: 29 | nums[k] = right[j] 30 | j += 1 31 | k += 1 32 | 33 | while i < n1: 34 | nums[k] = left[i] 35 | i += 1 36 | k += 1 37 | 38 | while j < n2: 39 | nums[k] = right[j] 40 | j += 1 41 | k += 1 42 | 43 | 44 | if __name__ == "__main__": 45 | nums = [5, 2, 4, 6, 1, 3] 46 | merge_sort(nums, 0, len(nums) - 1) 47 | print(nums) 48 | -------------------------------------------------------------------------------- /Python/RandomNumberGenerator.py: -------------------------------------------------------------------------------- 1 | import random #importing random library 2 | print random.randint(0, 100) #this will print a random number between 0, 100 3 | -------------------------------------------------------------------------------- /Python/Selection_sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Selection 2 | # Sort 3 | import sys 4 | A = [64, 25, 12, 22, 11] 5 | 6 | # Traverse through all array elements 7 | for i in range(len(A)): 8 | 9 | # Find the minimum element in remaining 10 | # unsorted array 11 | min_idx = i 12 | for j in range(i+1, len(A)): 13 | if A[min_idx] > A[j]: 14 | min_idx = j 15 | 16 | # Swap the found minimum element with 17 | # the first element 18 | A[i], A[min_idx] = A[min_idx], A[i] 19 | 20 | # Driver code to test above 21 | print ("Sorted array") 22 | for i in range(len(A)): 23 | print("%d" %A[i]) -------------------------------------------------------------------------------- /Python/Speech_Recognition.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | 3 | # Creating a Recognizer instance 4 | r = sr.Recognizer() 5 | 6 | ''' Each Recognizer instance has seven methods for recognizing 7 | speech from an audio source using various APIs. These are: 8 | 9 | recognize_bing(): Microsoft Bing Speech 10 | recognize_google(): Google Web Speech API 11 | recognize_google_cloud(): Google Cloud Speech - requires installation of the google-cloud-speech package 12 | recognize_houndify(): Houndify by SoundHound 13 | recognize_ibm(): IBM Speech to Text 14 | recognize_sphinx(): CMU Sphinx - requires installing PocketSphinx 15 | recognize_wit(): Wit.ai 16 | 17 | Of the seven, only recognize_sphinx() works offline with the 18 | CMU Sphinx engine. Others require an internet connection 19 | ''' 20 | 21 | aud = input("Enter the location of the audio File: ") 22 | 23 | jack = sr.AudioFile(aud) 24 | 25 | # The context manager opens the file and reads its contents, 26 | # storing the data in an AudioFile instance called source. 27 | with jack as source: 28 | r.adjust_for_ambient_noise(source,duration=0.5) 29 | audio1 = r.record(source) 30 | #the record() method records the data from the entire file 31 | #into an AudioData instance. 32 | 33 | print(r.recognize_google(audio1,show_all=True)) 34 | -------------------------------------------------------------------------------- /Python/TRIE.py: -------------------------------------------------------------------------------- 1 | from typing import Tuple 2 | 3 | 4 | class TrieNode(object): 5 | 6 | 7 | def __init__(self, char: str): 8 | self.char = char 9 | self.children = [] 10 | self.word_finished = False 11 | self.counter = 1 12 | 13 | 14 | def add(root, word: str): 15 | 16 | node = root 17 | for char in word: 18 | found_in_child = False 19 | for child in node.children: 20 | if child.char == char: 21 | 22 | child.counter += 1 23 | node = child 24 | found_in_child = True 25 | break 26 | if not found_in_child: 27 | new_node = TrieNode(char) 28 | node.children.append(new_node) 29 | # And then point node to the new child 30 | node = new_node 31 | node.word_finished = True 32 | 33 | 34 | def find_prefix(root, prefix: str) -> Tuple[bool, int]: 35 | 36 | node = root 37 | 38 | if not root.children: 39 | return False, 0 40 | for char in prefix: 41 | char_not_found = True 42 | for child in node.children: 43 | if child.char == char: 44 | char_not_found = False 45 | node = child 46 | break 47 | if char_not_found: 48 | return False, 0 49 | 50 | return True, node.counter 51 | 52 | if __name__ == "__main__": 53 | root = TrieNode('*') 54 | add(root, "hackathon") 55 | add(root, 'hack') 56 | 57 | print(find_prefix(root, 'hac')) 58 | print(find_prefix(root, 'hack')) 59 | print(find_prefix(root, 'hackathon')) 60 | print(find_prefix(root, 'ha')) 61 | print(find_prefix(root, 'hammer')) 62 | -------------------------------------------------------------------------------- /Python/armstrong.py: -------------------------------------------------------------------------------- 1 | s=int(input("enter a number")) 2 | n=s 3 | sum1=0 4 | while (s!=0): 5 | r=s%10 6 | sum1+=r**3 7 | s=int(s/10) 8 | if sum1==n: 9 | print("armstrong number") 10 | else: 11 | print("not an armstrong number") 12 | -------------------------------------------------------------------------------- /Python/array.py: -------------------------------------------------------------------------------- 1 | import array as arr 2 | numbers_list = [2, 5, 62, 5, 42, 52, 48, 5] 3 | numbers_array = arr.array('i', numbers_list) 4 | print(numbers_array[2:5]) # 3rd to 5th 5 | print(numbers_array[:-5]) # beginning to 4th 6 | print(numbers_array[5:]) # 6th to end 7 | print(numbers_array[:]) # beginning to end 8 | -------------------------------------------------------------------------------- /Python/balanced_paranthesis.py: -------------------------------------------------------------------------------- 1 | def areParanthesisBalanced(expr) : 2 | 3 | s = []; 4 | 5 | # Going through the Expression 6 | for i in range(len(expr)) : 7 | 8 | if (expr[i] == '(' or 9 | expr[i] == '[' or expr[i] == '{') : 10 | 11 | # Push the element in the stack 12 | s.append(expr[i]); 13 | continue; 14 | 15 | # IF current character is not opening 16 | # bracket, then it must be closing. 17 | # So stack cannot be empty at this point. 18 | if (len(s) == 0) : 19 | return False; 20 | 21 | if (expr[i] == ')'): 22 | 23 | # Store the top element in a 24 | x = s.pop(); 25 | 26 | if (x == '{' or x == '[') : 27 | return False; 28 | 29 | elif (expr[i] == '}'): 30 | 31 | # Store the top element in b 32 | x = s.pop(); 33 | 34 | if (x == '(' or x == '[') : 35 | return False; 36 | 37 | elif (x == ']'): 38 | 39 | # Store the top element in c 40 | x = s.pop(); 41 | 42 | if (x =='(' or x == '{') : 43 | return False; 44 | 45 | # Check Empty Stack 46 | if len(s) : 47 | return True 48 | else : 49 | return False 50 | 51 | # Driver Code to send the input expression 52 | if __name__ == "__main__" : 53 | 54 | expr = "{()}[]"; 55 | 56 | if (areParanthesisBalanced(expr)) : 57 | print("Balanced"); 58 | else : 59 | print("Not Balanced"); -------------------------------------------------------------------------------- /Python/break_time.py: -------------------------------------------------------------------------------- 1 | import webbrowser,time 2 | 3 | 4 | for i in range(0,3): 5 | time.sleep(10) 6 | webbrowser.open("https://stackoverflow.com/questions/17351016/set-up-python-simplehttpserver-on-windows") -------------------------------------------------------------------------------- /Python/bubbleSort.py: -------------------------------------------------------------------------------- 1 | def bubbleSort(a): 2 | for b in range(len(a)-1,0,-1): 3 | for i in range(b): 4 | if a[i]>a[i+1]: 5 | temp = a[i] 6 | a[i] = a[i+1] 7 | a[i+1] = temp 8 | 9 | nlist = [14,46,43,27,57,41,45,21,70] 10 | bubbleSort(nlist) 11 | print(nlist) 12 | -------------------------------------------------------------------------------- /Python/calci.py: -------------------------------------------------------------------------------- 1 | def add(x, y): 2 | return x + y 3 | def subtract(x, y): 4 | return x - y 5 | def multiply(x, y): 6 | return x * y 7 | def divide(x, y): 8 | return x / y 9 | print("Select operation.") 10 | print("1.Add") 11 | print("2.Subtract") 12 | print("3.Multiply") 13 | print("4.Divide") 14 | 15 | choice = input("Enter choice(1/2/3/4):") 16 | num1 = int(input("Enter first number: ")) 17 | num2 = int(input("Enter second number: ")) 18 | if choice == '1': 19 | print(num1,"+",num2,"=", add(num1,num2)) 20 | elif choice == '2': 21 | print(num1,"-",num2,"=", subtract(num1,num2)) 22 | elif choice == '3': 23 | print(num1,"*",num2,"=", multiply(num1,num2)) 24 | elif choice == '4': 25 | print(num1,"/",num2,"=", divide(num1,num2)) 26 | else: 27 | print("Invalid input") 28 | -------------------------------------------------------------------------------- /Python/cash.py: -------------------------------------------------------------------------------- 1 | from cs50 import get_float 2 | c=int(get_float("Change owed:")*100) 3 | 4 | r25=c//25 5 | c=c%25 6 | r10=c//10 7 | c=c%10 8 | r5=c//5 9 | c=c%5 10 | r1=c//1 11 | nc=r1+r5+r10+r25 12 | print(int(nc)) -------------------------------------------------------------------------------- /Python/centsChange.py: -------------------------------------------------------------------------------- 1 | #Python 3 2 | 3 | def change(cent): 4 | quarter = dime = nickel = penny = coins = 0; 5 | 6 | while cent>0: 7 | if cent >= 25: 8 | quarter += 1 9 | cent -= 25 10 | elif cent >= 10 : 11 | dime += 1 12 | cent -= 10 13 | elif cent >= 5 : 14 | nickel += 1 15 | cent -= 5 16 | elif cent >= 1: 17 | penny += 1 18 | cent -= 1 19 | coins +=1 20 | 21 | print() 22 | print("Change : ") 23 | print(str(quarter) + " Quarter") 24 | print(str(dime) + " Dime") 25 | print(str(nickel) + " Nickel") 26 | print(str(penny) + " Penny") 27 | print() 28 | print(str(coins)+" Coins") 29 | 30 | if __name__ == "__main__": 31 | change(int(input("How many cents? :"))) -------------------------------------------------------------------------------- /Python/circle_intersect/README.md: -------------------------------------------------------------------------------- 1 | # Python script to check the state of the circles 2 | 3 | ### Features: 4 | Checks if the circles are concentric, are tangents to each other or intersect each other at more than one point. 5 | 6 | ### User input: 7 | #### Takes input for: 8 | 1)x, y coordinates of centres of circle A, B. 9 | 2)Length of the radii of circles A, B. 10 | 11 | ### Algorithm / Thinking process: 12 | ##### 1)Two circles would intersect or be tangents to each other only if 13 | The distance between their centers is between the sum and the difference of their radii. 14 | i.e. interSect = abs(r_1 - r_2) <= math.sqrt((x_1 - x_2)^2 + (y_1 - y_2)^2) <= abs(r_1 + r_2) 15 | 16 | ##### 2)Now there are four cases: 17 | if interSect == 'True': 18 | if C1C2 == r_1 + r_2: 19 | print("Circle A and circle B are tangents to each other.") 20 | else: 21 | print("Circles A, B intersect each other") 22 | 23 | else: 24 | if C1C2 == 0: 25 | print("Circles A, B are concentric.") 26 | else: 27 | print("The circles don't intersect.") 28 | 29 | 30 | ##### I used matplotlib to just draw an image of what happens in the computers brain 31 | -------------------------------------------------------------------------------- /Python/curr_conv.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | class Currency_converter: 4 | rates = {} 5 | 6 | def __init__(self,url): 7 | 8 | data=requests.get(url).json() 9 | self.rates = data["rates"] 10 | 11 | def convert(self , from_currency , to_currency , amount): 12 | initial_amount = amount 13 | 14 | if from_currency != 'EUR' : 15 | amount = amount / self.rates[from_currency] 16 | 17 | amount = round(amount * self.rates[to_currency] , 2) 18 | print('{} {} = {} {}'.format(initial_amount , from_currency , amount , to_currency)) 19 | 20 | 21 | if __name__ == "__main__": 22 | 23 | YOUR_ACCESS_KEY='GET YOUR ACCESS KEY FROM fixer.io' 24 | 25 | 26 | url=str.__add__('http://data.fixer.io/api/latest?access_key=' , YOUR_ACCESS_KEY) 27 | 28 | c=Currency_converter(url) 29 | from = 'USD' 30 | to = 'INR' 31 | amount = 1 32 | 33 | c.convert(from , to , amount) 34 | -------------------------------------------------------------------------------- /Python/delete_reoccurring.py: -------------------------------------------------------------------------------- 1 | """ 2 | QUESTION: Given a string as your input, delete any reoccurring 3 | character, and return the new string. 4 | 5 | This is a Google warmup interview question that was asked duirng phone screening 6 | at my university. 7 | """ 8 | 9 | # time complexity O(n) 10 | def delete_reoccurring_characters(string): 11 | seen_characters = set() 12 | output_string = '' 13 | for char in string: 14 | if char not in seen_characters: 15 | seen_characters.add(char) 16 | output_string += char 17 | return output_string 18 | 19 | -------------------------------------------------------------------------------- /Python/dijkstra.py: -------------------------------------------------------------------------------- 1 | #Dijkstra's single source shortest path algorithm 2 | 3 | class Graph(): 4 | 5 | def __init__(self, vertices): 6 | self.vertices = vertices 7 | self.graph = [[0 for column in range(vertices)] for row in range(vertices)] 8 | 9 | def min_distance(self, dist, min_dist_set): 10 | min_dist = float("inf") 11 | for v in range(self.vertices): 12 | if dist[v] < min_dist and min_dist_set[v] == False: 13 | min_dist = dist[v] 14 | min_index = v 15 | return min_index 16 | 17 | def dijkstra(self, src): 18 | 19 | dist = [float("inf")] * self.vertices 20 | dist[src] = 0 21 | min_dist_set = [False] * self.vertices 22 | 23 | for count in range(self.vertices): 24 | 25 | #minimum distance vertex that is not processed 26 | u = self.min_distance(dist, min_dist_set) 27 | 28 | #put minimum distance vertex in shortest tree 29 | min_dist_set[u] = True 30 | 31 | #Update dist value of the adjacent vertices 32 | for v in range(self.vertices): 33 | if self.graph[u][v] > 0 and min_dist_set[v] == False and dist[v] > dist[u] + self.graph[u][v]: 34 | dist[v] = dist[u] + self.graph[u][v] 35 | 36 | return dist 37 | -------------------------------------------------------------------------------- /Python/face_recognition.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | 5 | face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 6 | vid = cv2.VideoCapture('your_file_name') 7 | 8 | #In the [your_file_name] mention the Video File that you want to process and detect the Face in 9 | 10 | while True: 11 | ret, frame = vid.read() 12 | frame = cv2.resize(frame,(int(frame.shape[1]/2),int(frame.shape[0]/2))) 13 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 14 | faces = face_cascade.detectMultiScale(gray, 1.3, 5) 15 | for (x,y,w,h) in faces: 16 | cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2) 17 | cv2.imshow('Video', frame) 18 | 19 | if cv2.waitKey(1) == 27: 20 | break 21 | 22 | vid.release() 23 | cv2.destroyAllWindows() 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Python/factorial.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if n < 1: 3 | return 0 4 | product = 1 5 | while(n > 0): 6 | product *= n 7 | n -= 1 8 | return product 9 | 10 | 11 | print(factorial(5)) 12 | -------------------------------------------------------------------------------- /Python/fibonacci.py: -------------------------------------------------------------------------------- 1 | # Find the Nth Fibonacci Number 2 | 3 | class Solution: 4 | def fib(self, N: int) -> int: 5 | if N <= 1: 6 | return N 7 | previous, current = 0, 1 8 | for _ in range(N - 1): 9 | new_current = previous + current 10 | previous, current = current, new_current 11 | return current 12 | -------------------------------------------------------------------------------- /Python/flaskapp.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | app.config['SECRET KEY'] = 'this is supposed to be a secret key' 5 | 6 | @app.route("/") 7 | def home(): 8 | return "

Hello World using Flask

" 9 | 10 | if __name__ == "__main__": 11 | app.run(debug = True) -------------------------------------------------------------------------------- /Python/flipString.py: -------------------------------------------------------------------------------- 1 | def flip(str): 2 | print("Output : "+str[::-1]) 3 | 4 | if __name__ == "__main__": 5 | flip(input("Input : ")) -------------------------------------------------------------------------------- /Python/flipkartScraper.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup as soup 2 | from urllib.request import urlopen as uReq 3 | 4 | serach = input("enter the product you want to search") 5 | my_url="https://www.flipkart.com/search?q=" + serach + "&otracker=search&otracker1=search&marketplace=FLIPKART&as-show=on&as=off" 6 | print(my_url) 7 | uClient = uReq(my_url) 8 | page_html = uClient.read() 9 | uClient.close() 10 | page_soup = soup(page_html, "html.parser") 11 | containers = page_soup.findAll("div", {"class": "bhgxx2 col-12-12"}) 12 | print(len(containers)) 13 | 14 | 15 | for i in range(3,len(containers)-5): 16 | container=containers[i] 17 | name=container.findAll("div", {"class":"_3wU53n"}) 18 | print("Product " +" : "+ name[0].text) 19 | price = container.findAll("div", {"class": "_1vC4OE _2rQ-NK"}) 20 | print("Price : "+price[0].text) 21 | ratings = container.findAll("div", {"class": "hGSR34"}) 22 | print("Ratings : " + ratings[0].text) 23 | -------------------------------------------------------------------------------- /Python/functions.py: -------------------------------------------------------------------------------- 1 | #inputs from user 2 | xh=input("Enter hours:") 3 | xr=input("Enter rate:") 4 | xp=float(xh)*float(xr) 5 | print("Pay:",xp) 6 | if xp>40: 7 | print("overflow") 8 | else: 9 | print("regular") 10 | #using functions 11 | def one(): 12 | print("Hello") 13 | print("world") 14 | print(":)") 15 | one() 16 | #using built-in functions 17 | big=max("helloworld") 18 | print(big) 19 | small=min("helloworld") 20 | print(small) -------------------------------------------------------------------------------- /Python/funny.py: -------------------------------------------------------------------------------- 1 | n,p = list(map(int,input().split())) 2 | if (n>=0 and p>=0): 3 | ls = list(str(n)) 4 | sum = 0 5 | c = p 6 | for num in range(0,len(ls)): 7 | sum = sum + (int(ls[num]))**c 8 | c+=1 9 | k = sum/n 10 | if(sum%n == 0 and k*n == sum): 11 | print(int(k)) 12 | else: 13 | print(-1) 14 | -------------------------------------------------------------------------------- /Python/generate_all_paths_graph.py: -------------------------------------------------------------------------------- 1 | ''' 2 | find all the possible paths in a directed cyclic graph from 3 | a start point to a end point. 4 | ''' 5 | 6 | 7 | 8 | 9 | def find_all_paths(graph, start, end, path=[]): 10 | path = path + [start] 11 | if start == end: 12 | return [path] 13 | if start not in graph.keys(): 14 | return [] 15 | paths = [] 16 | for node in graph[start]: 17 | if node not in path: #to prevent cyclic rotations 18 | newpaths = find_all_paths(graph, node, end, path) 19 | #print(newpaths) 20 | for newpath in newpaths: 21 | paths.append(newpath) 22 | return paths 23 | 24 | 25 | graph={1:[2,4], 26 | 2:[3], 27 | 4:[5], 28 | 3:[5] 29 | } 30 | 31 | for i in graph.keys(): 32 | print(i,'to 5',find_all_paths(graph,i,5)) 33 | -------------------------------------------------------------------------------- /Python/hack wifi_password.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors="backslashreplace").split('\n') 3 | profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i] 4 | for i in profiles: 5 | try: 6 | results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8', errors="backslashreplace").split('\n') 7 | results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b] 8 | try: 9 | print ("{:<30}| {:<}".format(i, results[0])) 10 | except IndexError: 11 | print ("{:<30}| {:<}".format(i, "")) 12 | except subprocess.CalledProcessError: 13 | print ("{:<30}| {:<}".format(i, "ENCODING ERROR")) 14 | input("") 15 | -------------------------------------------------------------------------------- /Python/hello.py: -------------------------------------------------------------------------------- 1 | #This is a python code to display strings 2 | print("Hello World!\nI am Aswin gopinathan USN:-1MV17CS018") 3 | print("Nice meeting you") 4 | -------------------------------------------------------------------------------- /Python/hello_flask.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | @app.route("/") 5 | def hello(): 6 | return "Hello World!" 7 | 8 | if __name__ == "__main__": 9 | app.run() 10 | -------------------------------------------------------------------------------- /Python/helloworld.py: -------------------------------------------------------------------------------- 1 | print("Hello world, I am Aditya Rajneesh Singh.") -------------------------------------------------------------------------------- /Python/instagram_profile_detail.py: -------------------------------------------------------------------------------- 1 | 2 | from bs4 import BeautifulSoup 3 | import requests 4 | URL = "https://www.instagram.com/{}/" 5 | def parse_data(s): 6 | data = {} 7 | s = s.split("-")[0] 8 | s = s.split(" ") 9 | data['Followers'] = s[0] 10 | data['Following'] = s[2] 11 | data['Posts'] = s[4] 12 | return data 13 | 14 | 15 | def scrape_data(username): 16 | r = requests.get(URL.format(username)) 17 | s = BeautifulSoup(r.text, "html.parser") 18 | meta = s.find("meta", property="og:description") 19 | return parse_data(meta.attrs['content']) 20 | 21 | 22 | 23 | if __name__ == "__main__": 24 | username = input("Enter Instagram User Name:\t") 25 | data = scrape_data(username) 26 | print(data) 27 | -------------------------------------------------------------------------------- /Python/jump.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def JumpSearch (lys, val): 4 | length = len(lys) 5 | jump = int(math.sqrt(length)) 6 | left, right = 0, 0 7 | while left < length and lys[left] <= val: 8 | right = min(length - 1, left + jump) 9 | if lys[left] <= val and lys[right] >= val: 10 | break 11 | left += jump; 12 | if left >= length or lys[left] > val: 13 | return -1 14 | right = min(length - 1, right) 15 | i = left 16 | while i <= right and lys[i] <= val: 17 | if lys[i] == val: 18 | return i 19 | i += 1 20 | return -1 21 | 22 | -------------------------------------------------------------------------------- /Python/lan_search.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | class LANScanner(): 4 | def __init__(self): 5 | self.hostname = socket.gethostname() 6 | self.networkIP = socket.gethostbyname(self.hostname) 7 | self.networkPrefix = self.networkIP.split(".") 8 | del(self.networkPrefix[-1]) 9 | self.networkPrefix = ".".join(self.networkPrefix) 10 | 11 | def checkIP(self,currentIP): 12 | s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 13 | s.settimeout(0.01) 14 | if not s.connect_ex((currentIP,135)): 15 | s.close() 16 | return(1) 17 | else: 18 | s.close() 19 | 20 | def startScan(self): 21 | print("Your IP : %s" %(self.networkIP)) 22 | print("scanning lan network...") 23 | for ip in range(1,255): 24 | currentIP = self.networkPrefix + "." + str(ip) 25 | if(self.checkIP(currentIP)): 26 | print("%s \t - %s"%(currentIP, socket.getfqdn(currentIP))) 27 | print("scan finished!") 28 | 29 | if __name__=="__main__": 30 | sLan = LANScanner() 31 | sLan.startScan() 32 | -------------------------------------------------------------------------------- /Python/list_demo.py: -------------------------------------------------------------------------------- 1 | i = 0 2 | numbers = [] 3 | 4 | while i < 6: 5 | print(f'At the top i is {i}') 6 | numbers.append(i) 7 | 8 | i += 1 9 | print(f'Number now is {numbers}') 10 | print(f'At the bottm i is {i}') 11 | 12 | print('The Numbers') 13 | for number in numbers: 14 | print(number) 15 | -------------------------------------------------------------------------------- /Python/movement_detection_opencv.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | cap = cv2.VideoCapture(0) 4 | ret, frame1 = cap.read() 5 | ret, frame2 = cap.read() 6 | while cap.isOpened(): 7 | diff = cv2.absdiff(frame1, frame2) 8 | gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY) 9 | blur = cv2.GaussianBlur(gray, (5, 5), 0) 10 | A, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY) 11 | dialted = cv2.dilate(thresh, None) 12 | contours, A = cv2.findContours(dialted, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 13 | for contour in contours: 14 | (x, y, w, h) = cv2.boundingRect(contour) 15 | if cv2.contourArea(contour) < 950: 16 | continue 17 | else: 18 | cv2.rectangle(frame1, (x, y), (x + w, y + h), (0, 0, 255), 2) 19 | cv2.putText(frame1, 'Warning: {}'.format(' Movement Detected '), (15, 25), cv2.FONT_HERSHEY_DUPLEX, 1, (10, 255,255),1) 20 | 21 | cv2.imshow('Saurabh Saha', frame1) 22 | frame1 = frame2 23 | ret, frame2 = cap.read() 24 | if cv2.waitKey(40) == 97: 25 | break 26 | cap.release() 27 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Python/mutation.py: -------------------------------------------------------------------------------- 1 | def mutate_string(string, position, character): 2 | string_list = list(string) 3 | string_list[position] = character 4 | string_list_new = ''.join(string_list) 5 | return string_list_new 6 | 7 | 8 | if __name__ == '__main__': 9 | s = input() 10 | i, c = input().split() 11 | s_new = mutate_string(s, int(i), c) 12 | print(s_new) -------------------------------------------------------------------------------- /Python/nCr.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | fermits little theorem 4 | nCr % p = (fac[n]* modinverse(fac[r]) % p * modinverse(fac[n-r]) % p) % p 5 | 6 | modinverse(x) % p = x^p-2 7 | 8 | ''' 9 | 10 | 11 | def ncr(n, r, p): 12 | numerator = denominator = 1 13 | for i in range(r): 14 | numerator = (numerator * (n - i)) % p 15 | denominator = (denominator * (i + 1)) % p 16 | return (numerator * pow(denominator , p - 2 , p)) % p 17 | 18 | 19 | n, r, p = 10**5, 20000, 1000000007 20 | 21 | print(ncr(n, r, p)) 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Python/notification.py: -------------------------------------------------------------------------------- 1 | import time 2 | from plyer import notification 3 | 4 | while True: 5 | notification.notify(title = 'PLEASE DRINK WATER!! :)', 6 | message = 'Regularly Drinking Water is good for Health!', 7 | app_icon = 'drink.ico', 8 | timeout = 10) 9 | time.sleep(60 * 60) # Reminds every 1 hour 10 | -------------------------------------------------------------------------------- /Python/nth_fibonacci.py: -------------------------------------------------------------------------------- 1 | #Python Program to calculate the nth Fibonacci Number 2 | 3 | from math import sqrt 4 | def fibonacci(n): 5 | return int(1/sqrt(5)*(((1+sqrt(5))/2)**n - ((1-sqrt(5))/2)**n)) 6 | 7 | your_number=int(input("Enter the value so that we can calculate its corresponding Fibonacci Number:")) 8 | print(fibonacci(your_number)) 9 | -------------------------------------------------------------------------------- /Python/number_representation.py: -------------------------------------------------------------------------------- 1 | # NUMBER REPRESENTATION AND CONVERSION PYTHON PROGRAM 2 | # (c) 2019 Tafadzwa Muteke. All rights reserved. 3 | # https://github.com/tmuteke 4 | 5 | def encode(digits): 6 | encode_map = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 7 | if max(digits) >= len(encode_map): 8 | raise ValueError 9 | return ''.join([encode_map[x] for x in digits]) 10 | 11 | 12 | def from_base_ten(number, base): 13 | if 2 >= base >= 36: 14 | raise ValueError('Base too big') 15 | digits = [] 16 | while number > 0: 17 | number, remainder = divmod(number, base) 18 | digits.append(remainder) 19 | return digits[::-1] 20 | 21 | 22 | def to_base_ten(str_number, base): 23 | return int(str_number, base) 24 | 25 | 26 | def init(): 27 | print('Represent numbers from one base to another; base 2 through base 36') 28 | number = input('Enter your number: ') 29 | base = int(input('Enter its base: ')) 30 | repr_in_base = int(input('Represent in base: ')) 31 | 32 | in_base_ten = to_base_ten(number, base) 33 | number_repr = encode(from_base_ten(in_base_ten, repr_in_base)) 34 | print('{}[{}] = {}[{}]'.format(number, base, number_repr, repr_in_base)) 35 | 36 | 37 | init() -------------------------------------------------------------------------------- /Python/odd_or_even.py: -------------------------------------------------------------------------------- 1 | # Python program to check if the input number is odd or even. 2 | number = int(input("Enter a number: ")) 3 | if (number % 2) == 0: 4 | print("{0} is Even".format(number)) 5 | else: 6 | print("{0} is Odd".format(number)) 7 | -------------------------------------------------------------------------------- /Python/orm.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | from sqlalchemy import Column, ForeignKey, Integer, String 4 | from sqlalchemy.ext.declarative import declarative_base 5 | from sqlalchemy.orm import relationship 6 | from sqlalchemy import create_engine 7 | 8 | Base = declarative_base() 9 | 10 | print ("hiii") 11 | class Restaurant(Base): 12 | __tablename__ = 'restaurant' 13 | 14 | id = Column(Integer, primary_key=True) 15 | name = Column(String(250), nullable=False) 16 | 17 | 18 | class MenuItem(Base): 19 | __tablename__ = 'menu_item' 20 | 21 | name = Column(String(80), nullable=False) 22 | id = Column(Integer, primary_key=True) 23 | description = Column(String(250)) 24 | price = Column(String(8)) 25 | course = Column(String(250)) 26 | restaurant_id = Column(Integer, ForeignKey('restaurant.id')) 27 | restaurant = relationship(Restaurant) 28 | 29 | 30 | engine = create_engine('sqlite:///restaurantmenu.db') 31 | 32 | 33 | Base.metadata.create_all(engine) 34 | -------------------------------------------------------------------------------- /Python/palindrome.py: -------------------------------------------------------------------------------- 1 | # Python program to check if a string is a palindrome or not 2 | 3 | s = input("Enter your string: ") 4 | 5 | def isPalindrome(s): 6 | s.lower() 7 | rev = s[::-1] 8 | 9 | if (s == rev): 10 | return True 11 | return False 12 | 13 | print(isPalindrome(s)) 14 | 15 | if __name__ == "__main__": 16 | isPalindrome(s) -------------------------------------------------------------------------------- /Python/ploter.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from matplotlib import pyplot as plt 3 | 4 | window=tk.Tk() 5 | 6 | 7 | def EXIT(): 8 | window.destroy() 9 | 10 | 11 | def plot(): 12 | x=[0 for i in range(5)] 13 | y=[0 for i in range(5)] 14 | 15 | for i in range(5): 16 | 17 | x[i]=int(xentries[i].get()) 18 | y[i]=int(yentries[i].get()) 19 | 20 | plt.plot(x,y) 21 | plt.show() 22 | 23 | 24 | label1=tk.Label(window,text='XY PLOTER',bg='black',fg='white',font='HELVITICA 20 bold') 25 | label1.grid(row=0,column=2) 26 | 27 | xlabels=[tk.Label for i in range(5)] 28 | ylabels=[tk.Label for i in range(5)] 29 | 30 | xentries=[tk.Entry for i in range(5)] 31 | yentries=[tk.Entry for i in range(5)] 32 | 33 | for i in range(5): 34 | xlabels[i]=tk.Label(window,text='X'+str(i+1),fg='black',font='HELVITICA 12 bold') 35 | xlabels[i].grid(row=(i+2),column=0) 36 | 37 | 38 | ylabels[i]=tk.Label(window,text='Y'+str(i+1),fg='black',font='HELVITICA 12 bold') 39 | ylabels[i].grid(row=(i+2),column=2) 40 | 41 | xentries[i]=tk.Entry(window) 42 | xentries[i].grid(row=(i+2),column=1) 43 | 44 | yentries[i]=tk.Entry(window) 45 | yentries[i].grid(row=(i+2),column=3) 46 | 47 | 48 | btn1=tk.Button(window,text='PLOT',font='HELVITICA 15 bold',bg='green',fg='white',command=plot) 49 | btn1.grid(row=7,column=0) 50 | 51 | 52 | btn2=tk.Button(window,text='EXIT',font='HELVITICA 15 bold',bg='red2',fg='white',command=EXIT) 53 | btn2.grid(row=7,column=4) 54 | -------------------------------------------------------------------------------- /Python/polymorphism_python.py: -------------------------------------------------------------------------------- 1 | ## Polymorphism in Python 2 | 3 | # Polymorphism with class methods: 4 | class India(): 5 | def capital(self): 6 | print("New Delhi is the capital of India.") 7 | 8 | def language(self): 9 | print("Hindi the primary language of India.") 10 | 11 | def type(self): 12 | print("India is a developing country.") 13 | 14 | class USA(): 15 | def capital(self): 16 | print("Washington, D.C. is the capital of USA.") 17 | 18 | def language(self): 19 | print("English is the primary language of USA.") 20 | 21 | def type(self): 22 | print("USA is a developed country.") 23 | 24 | obj_ind = India() 25 | obj_usa = USA() 26 | for country in (obj_ind, obj_usa): 27 | country.capital() 28 | country.language() 29 | country.type() 30 | ######################### 31 | print("") 32 | print("#####################################") 33 | print("") 34 | ######################### 35 | 36 | ## Polymorphism with Inheritance: 37 | 38 | class Bird: 39 | def intro(self): 40 | print("There are many types of birds.") 41 | 42 | def flight(self): 43 | print("Most of the birds can fly but some cannot.") 44 | 45 | class sparrow(Bird): 46 | def flight(self): 47 | print("Sparrows can fly.") 48 | 49 | class ostrich(Bird): 50 | def flight(self): 51 | print("Ostriches cannot fly.") 52 | 53 | obj_bird = Bird() 54 | obj_spr = sparrow() 55 | obj_ost = ostrich() 56 | 57 | obj_bird.intro() 58 | obj_bird.flight() 59 | 60 | obj_spr.intro() 61 | obj_spr.flight() 62 | 63 | obj_ost.intro() 64 | obj_ost.flight() 65 | -------------------------------------------------------------------------------- /Python/prime_number.py: -------------------------------------------------------------------------------- 1 | num = int(input("enter a number: ")) 2 | 3 | for i in range(2, num): 4 | if num % i == 0: 5 | print("not prime number") 6 | break 7 | else: 8 | print("prime number") 9 | -------------------------------------------------------------------------------- /Python/profanity_checker.py: -------------------------------------------------------------------------------- 1 | import urllib 2 | 3 | def read_text() : 4 | text = "Hello This is a text to check the profanity of the sentence" 5 | text2 = "This is a sentence having a profane word SHIT" 6 | 7 | profanity_checker(text) 8 | profanity_checker(text2) 9 | 10 | def profanity_checker(text) : 11 | connection = urllib.urlopen("http://www.wdylike.appspot.com/?q="+text) 12 | output = connection.read() 13 | 14 | if output == "true": 15 | print("\nProfanity Alert !! for \'"+text+"\'") 16 | elif output == "false": 17 | print("\nNo Cuss Words :) in \'"+text+"\'") 18 | 19 | read_text() -------------------------------------------------------------------------------- /Python/punctuation.py: -------------------------------------------------------------------------------- 1 | str = input("Enter a string: ") 2 | punc = ['.',',','?','!',';'] 3 | for i in range(0,len(str)): 4 | for j in range(0,len(punc)): 5 | if(str[i] in punc): 6 | str=str.replace(punc[j]," ") 7 | print(str) 8 | 9 | ''' 10 | Output:- 11 | Enter a string: Hello World! This is, a test. 12 | Hello World This is a test 13 | ''' -------------------------------------------------------------------------------- /Python/quicksort.py: -------------------------------------------------------------------------------- 1 | def partition(arr,low,high): 2 | i = ( low-1 ) # index of smaller element 3 | pivot = arr[high] # pivot 4 | 5 | for j in range(low , high): 6 | 7 | # If current element is smaller than or 8 | # equal to pivot 9 | if arr[j] <= pivot: 10 | 11 | # increment index of smaller element 12 | i = i+1 13 | arr[i],arr[j] = arr[j],arr[i] 14 | 15 | arr[i+1],arr[high] = arr[high],arr[i+1] 16 | return ( i+1 ) 17 | 18 | # The main function that implements QuickSort 19 | # arr[] --> Array to be sorted, 20 | # low --> Starting index, 21 | # high --> Ending index 22 | 23 | # Function to do Quick sort 24 | def quickSort(arr,low,high): 25 | if low < high: 26 | 27 | # pi is partitioning index, arr[p] is now 28 | # at right place 29 | pi = partition(arr,low,high) 30 | 31 | # Separately sort elements before 32 | # partition and after partition 33 | quickSort(arr, low, pi-1) 34 | quickSort(arr, pi+1, high) 35 | 36 | arr = [10, 7, 8, 9, 1, 5] 37 | n = len(arr) 38 | quickSort(arr,0,n-1) 39 | print ("Sorted array is:") 40 | for i in range(n): 41 | print ("%d" %arr[i]) 42 | -------------------------------------------------------------------------------- /Python/regular_expression: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | txt = "The rain in Spain" # Can enter any text 4 | x = re.search("^The.*Spain$", txt) #Returns true if it's a match with pateern 'The' in beggining and 'Spain' at the end. 5 | -------------------------------------------------------------------------------- /Python/reverse_string.py: -------------------------------------------------------------------------------- 1 | string=str(input("Enter a string")) 2 | 3 | rev=string[::-1] 4 | 5 | print("Reverse of teinout string is:",rev) 6 | -------------------------------------------------------------------------------- /Python/run-flask.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def index(): 7 | return 'Hello World from Flask framework!' 8 | -------------------------------------------------------------------------------- /Python/send_mail.py: -------------------------------------------------------------------------------- 1 | # need to import the smtp lib 2 | import smptplib 3 | 4 | 5 | # TLS port = 587, normal_port=465 6 | smtp_obj = smtplib.SMTP('smtp.gmail.com', 587) 7 | print("TYPE_SMTP_OBJ", type(smtp_obj)) 8 | 9 | smtp_obj.ehlo() 10 | 11 | #starttls() puts smtp in TLS mode 12 | smtp_obj.starttls() 13 | 14 | smtp_obj.login('email_address', 'password') 15 | 16 | sender_email_adress = 'abcd@efg.com' 17 | list_of_reciever_addresses = ['email_1@xxxx.com', 'email_2@xxxx.com'] 18 | 19 | smtp_obj.sendemail(sender_email_address, list_of_reciever_addresses, 'Subject: the body of the message') 20 | 21 | #close the smtp obj when done 22 | smtp_obj.quit() 23 | -------------------------------------------------------------------------------- /Python/send_text.py: -------------------------------------------------------------------------------- 1 | import twilio 2 | import twilio.rest 3 | 4 | account_sid = "" 5 | auth_token = "" 6 | 7 | client = twilio.rest.Client(account_sid,auth_token) 8 | 9 | message = client.messages.create( 10 | body = "Hello This is AG", 11 | to="+919900167683", 12 | from_="+1 971 351 1750" 13 | ) 14 | -------------------------------------------------------------------------------- /Python/sum_lst_index.py: -------------------------------------------------------------------------------- 1 | # this is a python program to find the sum of all numbers in the list except the current index 2 | 3 | 4 | 5 | from functools import reduce 6 | 7 | input_array = input("Please enter the array....\n") 8 | print("Multiplication started.....\n") 9 | 10 | original_array = list(map(int, input_array.split(' '))) 11 | 12 | lst_to_multiply = [] 13 | new_lst = [] 14 | 15 | for i in range(0,len(original_array)): 16 | if i != 0 and i != len(original_array): 17 | lst_to_multiply = original_array[0:i] + original_array[i+1:] 18 | if i == 0: 19 | lst_to_multiply = original_array[i+1:] 20 | if i == len(original_array): 21 | lst_to_multiply = original_array[0:len(original_array)-1] 22 | # print("lst_to_multiply>>>>", lst_to_multiply) 23 | new_lst.insert(i, reduce((lambda x,y: x * y), lst_to_multiply)) 24 | 25 | print("NEW_LST", new_lst) 26 | -------------------------------------------------------------------------------- /Python/vowel checker.py: -------------------------------------------------------------------------------- 1 | #Start of code 2 | x=['a','e','i','o','u','A','E','I','O','U'] 3 | y=input("Enter an Alphabet: ") 4 | if y in x: 5 | print(y,"is a vowel") 6 | else: 7 | print(y,"is not a vowel") 8 | #End of code 9 | -------------------------------------------------------------------------------- /Python/web.py: -------------------------------------------------------------------------------- 1 | import requests as r 2 | print(r.get("https://www.google.com").content) 3 | -------------------------------------------------------------------------------- /R/factorial_using_recursion.r: -------------------------------------------------------------------------------- 1 | recur_factorial <- function(n) { 2 | if(n <= 1) { 3 | return(1) 4 | } else { 5 | return(n * recur_factorial(n-1)) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /R/hello_world.r: -------------------------------------------------------------------------------- 1 | cat('Hello, world! 2 | ') 3 | -------------------------------------------------------------------------------- /R/lists.r: -------------------------------------------------------------------------------- 1 | #creating a list 2 | x <- list(TRUE,1:5,"rex") 3 | #display element at position 1 4 | 5 | x[1] 6 | 7 | # if we give x[0] we get list() 8 | 9 | x[0] 10 | 11 | #add new element in list by adding tags 12 | 13 | x[["event"]]<-"hacktober" 14 | x[["month"]]<-"October" 15 | 16 | #modify elements of a list 17 | x[["event"]]<-"hacktoberfest" 18 | 19 | 20 | # delete element of list at particular index 21 | x[["month"]] <- NULL 22 | 23 | x 24 | #check datatype 25 | typeof(x[[2]]) 26 | 27 | #partial matching this matches with event and displays the output as hacktoberfest 28 | x$eve 29 | 30 | 31 | -------------------------------------------------------------------------------- /R/uniform_distribution.r: -------------------------------------------------------------------------------- 1 | # Plotting a uniform distribution 2 | n <- floor(runif(10000)*10) 3 | t <- table(n) 4 | barplot(t) 5 | -------------------------------------------------------------------------------- /Ruby/factorial.rb: -------------------------------------------------------------------------------- 1 | print "Enter a number :" 2 | n=gets.chomp #accepting value from user 3 | x=n.to_i #converting accepted string value to integer 4 | f=1 5 | i=1 6 | while i<=x #loop that calculates factorial 7 | f=f*i 8 | i=i+1 9 | end 10 | print "Factorial is : " 11 | print f 12 | print "\n" 13 | -------------------------------------------------------------------------------- /Ruby/hello_world.rb: -------------------------------------------------------------------------------- 1 | puts "Hello, World!" 2 | -------------------------------------------------------------------------------- /Ruby/quicksort.rb: -------------------------------------------------------------------------------- 1 | def quicksort(arr) 2 | b, a = [], [] 3 | a[0] = 0 4 | b[0] = arr.size 5 | i = 0 6 | while i >= 0 do 7 | l = a[i] 8 | r = b[i] - 1; 9 | if l < r 10 | pivot = arr[l] 11 | while l < r do 12 | r -= 1 while (arr[r] >= pivot && l < r) 13 | if (l < r) 14 | arr[l] = arr[r] 15 | l += 1 16 | end 17 | l += 1 while (arr[l] <= pivot && l < r) 18 | if (l < r) 19 | arr[r] = arr[l] 20 | r -= 1 21 | end 22 | end 23 | arr[l] = pivot 24 | a[i + 1] = l + 1 25 | b[i + 1] = b[i] 26 | b[i] = l 27 | i += 1 28 | else 29 | i -= 1 30 | end 31 | end 32 | arr 33 | end 34 | -------------------------------------------------------------------------------- /Swift/Hello.World.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | print("Hello, World!") 4 | -------------------------------------------------------------------------------- /Swift/String+Anagram.swift: -------------------------------------------------------------------------------- 1 | extension String { 2 | 3 | /** 4 | Case sensitive Anagram 5 | */ 6 | var isAnagram: Bool { 7 | let array = Array(self) 8 | let lastIndex = array.count - 1 9 | for i in 0.. Int { 5 | 6 | if index < 2 { 7 | return index 8 | } 9 | 10 | var i = 2 11 | var next1 = 0 12 | var next2 = 1 13 | 14 | while i <= index { 15 | let next = next1 + next2 16 | next1 = next2 17 | next2 = next 18 | i += 1 19 | } 20 | 21 | return next2 22 | } 23 | 24 | /// Calculate up to the nth fibbonacci number 25 | /// - Parameter index: the fibbonacci number to calculate 26 | /// - Returns: the array of fibbonacci numbers 27 | func fibonacciArray(_ index: Int) -> [Int] { 28 | var result = [Int]() 29 | if index >= 0 { 30 | result.append(0) 31 | } 32 | if index >= 1 { 33 | result.append(1) 34 | } 35 | 36 | while result.count < index { 37 | let first = result[result.count - 1] 38 | let second = result[result.count - 2] 39 | result.append(first + second) 40 | } 41 | 42 | return result 43 | } --------------------------------------------------------------------------------