├── Shell Scripting ├── Cut#4.sh ├── Cut#9.sh ├── Cut#2.sh ├── Cut#3.sh ├── Cut#5.sh ├── Cut#6.sh ├── Cut#7.sh ├── Cut#8.sh ├── Grep #1.sh ├── Grep #2.sh ├── Paste-1.sh ├── Paste-3.sh ├── Sort_Command_#1.sh ├── Uniq-Command#1.sh ├── Uniq-Command#4.sh ├── let's-echo.sh ├── Awk-4.sh ├── Grep-B.sh ├── Paste-4.sh ├── Sort_Command_#2.sh ├── Sort_Command_#3.sh ├── Sort_Command_#4.sh ├── Tr_command_#2.sh ├── Tr_command_#3.sh ├── looping-with-number.sh ├── Sed command #1.sh ├── Sed command #3.sh ├── Tail_of_a_Text_File#2.sh ├── Uniq-Command#3.sh ├── Grep-A.sh ├── Sed command #2.sh ├── Sort_Command_#5.sh ├── Sort_Command_#6.sh ├── Sort_Command_#7.sh ├── Tail_of_a_Text_File#1.sh ├── Uniq-Command#2.sh ├── Sed command #4.sh ├── Tr_command_#1.sh ├── Paste-2.sh ├── Slice-an-Array.sh ├── A-Personalized-Echo.sh ├── Cut#1.sh ├── Grep #3.sh ├── Awk-1.sh ├── Display-an-element-of-an-array.sh ├── Head_of_a_Text_File#2.sh ├── Arithmetic-Operations.cpp ├── Count-the-number-of-elements-in-an-Array.sh ├── looping-and-skipping.sh ├── Sed command #5.sh ├── Concatenate-an-array-with-itself.sh ├── Middle_of_a_Text_File.sh ├── The-World-of-Numbers.sh ├── Filter-an-array-with-Patterns.sh ├── Lonely_integer_Bash.sh ├── Remove-first-capital-letter-from-each-element.sh ├── Awk-2.sh ├── Compute-the-Average.sh ├── Read-in-an-Array.sh ├── Getting-started-with-conditionals.sh ├── Comparing-Numbers.sh ├── Head_of_a_Text_File#1.sh ├── More-on-Conditionals.sh ├── Awk-3.sh └── Function and Fractals-Recursive Trees-Bash!.sh ├── .gitignore ├── Python ├── Python Evaluation.py ├── Set .add().py ├── Input().py ├── Mod Divmod.py ├── Polar Coordinates.py ├── Tuples.py ├── Power - Mod Power.py ├── Integers Come In All Sizes.py ├── Symmetric Difference.py ├── Any or All.py ├── Numpy │ ├── Shape and Reshape.py │ └── Arrays.py ├── Set .difference() Operation.py ├── Set .intersection() Operation.py ├── Set .union() Operation.py ├── Calendar Module.py ├── Find Angle MBC.py ├── Set .symmetric_difference() Operation.py ├── ginortS.py ├── itertools.product().py ├── Zipped!.py ├── Triangle Quest.py ├── Word Order.py ├── itertools.permutations().py ├── Athlete Sort.py ├── Compress the String!.py ├── The Captain's Room.py ├── Check Subset.py ├── Incorrect Regex.py ├── No Idea!.py ├── Triangle Quest 2.py ├── Collections.namedtuple().py ├── String Split and Join.py ├── itertools.combinations().py ├── Designer Door Mat.py ├── Finding the percentage.py ├── Nested Lists.py ├── sWAP cASE.py ├── Time Delta.py ├── itertools.combinations_with_replacement().py ├── Company Logo.py ├── String Validators.py ├── Introduction to Sets.py ├── Check Strict Superset.py ├── Mutations.py ├── Detect Floating Point Number.py ├── Text Wrap.py ├── Re.start() & Re.end().py ├── collections.Counter().py ├── Exceptions.py ├── Collections.OrderedDict().py ├── DefaultDict Tutorial.py ├── String Formatting.py ├── Validating Postal Codes.py ├── Collections.deque().py ├── Set .discard(), .remove() & .pop().py ├── Alphabet Rangoli.py ├── Maximize It!.py ├── Iterables and Iterators.py ├── Merge the Tools!.py ├── Map and Lambda Function.py ├── Reduce Function.py ├── The Minion Game.py ├── Capitalize!.py ├── Validating Credit Card Numbers.py ├── What's Your Name?.py ├── Set Mutations.py ├── Decorators 2 - Name Directory.py ├── Matrix Script.py ├── Lists.py ├── Piling Up!.py ├── Find a string.py ├── Text Alignment.py ├── Default Arguments.py ├── Sparse Arrays.py └── Class 2 - Find the Torsional Angle.py ├── 30 Days of Code ├── Day-28.sh ├── Day-07.cpp ├── Day-29.cpp ├── Day-06.cpp ├── Day-09.cpp ├── Day-03.cpp ├── Day-26.cpp ├── Day-20.cpp ├── Day-01.cpp ├── Day-25.cpp ├── Day-16.cpp ├── Day-02.cpp ├── Day-05.cpp ├── Day-19.cpp ├── Day-21.cpp ├── Day-17.cpp ├── Day-14.cpp ├── Day-10.cpp ├── Day-11.cpp ├── Day-15.cpp ├── Day-08.cpp └── Day-04.cpp ├── C++ ├── Hello-World-With-C++.cpp ├── strings.cpp ├── Input-and-Output.cpp ├── basic-data-types.cpp ├── Pointer.cpp ├── pointer.cpp ├── functions.cpp ├── Vector-Sort.cpp ├── Variable-Sized-Array.cpp ├── array-introduction.cpp ├── structs.cpp ├── Vector-Erase.cpp ├── Lower Bound-STL.cpp ├── Print Pretty.cpp ├── Sets-STL.cpp ├── StringStream.cpp ├── Inheritance Introduction.cpp ├── Multi Level Inheritance.cpp ├── Maps-STL.cpp ├── conditional-statements.cpp ├── Preprocessor Solution.cpp ├── deque-stl.cpp ├── Overloading Ostream Operator.cpp ├── Cpp exception handling.cpp ├── Rectangle Area.cpp ├── C++:Variadics.cpp ├── Inherited Code.cpp ├── C++ Class Template Specialization.cpp ├── for loop.cpp ├── Overload Operators.cpp ├── Classes and Objects.cpp ├── Exceptional Server.cpp └── Hotel Prices.cpp ├── Maths ├── Cutting Paper Square.cpp ├── Jim and the Jokes.py ├── Leonardo's Prime Factors.py ├── Diwali Lights.cpp ├── Strange Grid Again.cpp ├── Minimum Height Triangle.cpp ├── Shelock and Moving tiles.cpp ├── Find the Point.cpp ├── Handshake.cpp ├── Maximum Draws.cpp ├── number-group.cpp ├── Summing N Series.cpp ├── Connecting Towns.cpp ├── Restaurant.cpp ├── Halloween Party.cpp ├── Sumar and the Floating Rocks.cpp ├── harry-potter-and-the-floating-rocks.cpp ├── Sherlock and Divisors.cpp ├── Filling Jars.cpp ├── Possible Paths.cpp ├── john-and-gcd.cpp ├── K Candy Store.cpp ├── die-hard-3.cpp ├── Best Divisors.cpp ├── sherlock-and-permutation.cpp ├── Sherlock-And-GCD.cpp ├── ncr-table.cpp ├── Reverse Game.cpp ├── Identify-Smith-Numbers.cpp ├── Russian Peasant Exponentiation.cpp ├── Euler's Criterion.cpp ├── even-odd-query.cpp ├── is-fibo.cpp ├── Little Panda Power.cpp ├── the-chosen-one.cpp └── Most Distant.cpp ├── Algorithms ├── Dynamic Programming │ ├── Fibonacci Modified.py │ ├── Sam and substrings.cpp │ ├── String Reduction.cpp │ └── coin-change-problem.cpp ├── Warmup │ ├── Solve Me First.go │ ├── Solve-Me-First.cpp │ └── Simple-Array-Sum.cpp ├── Implementation │ ├── Extra_Large_Factorials.py │ ├── Find Digits.cpp │ ├── Counting-Valleys.cpp │ ├── The Grid Search.cpp │ ├── Repeated-String.cpp │ └── Climbing-the-Leaderboard.cpp ├── Bit Manipulation │ ├── Sansa and XOR.cpp │ ├── AND Product.cpp │ ├── Maximizing Xor.cpp │ ├── The great XOR.cpp │ ├── Cipher.cpp │ ├── Counter Game.cpp │ └── Sum vs Xor.cpp ├── Greedy │ ├── Priyanka and Toys.cpp │ ├── Jim and the Orders.cpp │ └── Sherlock and MiniMax.cpp ├── Recursion │ └── The Power Sum.cpp ├── Game Theory │ ├── Counter Game.cpp │ ├── Chessboard Game, Again!.cpp │ ├── Alice and Bob's Silly Game.cpp │ └── Game of Stones.cpp ├── Strings │ └── Bear and Steady Gene.cpp ├── Stack and Queues │ └── Balanced Brackets.cpp └── Sorting │ └── The Full Counting Sort.cpp ├── README.md ├── 10 Days of Statistics ├── Day 2: Basic Probability.go ├── Day 2: More Dice.go ├── Day 2: Compound Event Probability.go ├── Day 0: Weighted Mean.cpp ├── Day 1: Standard Deviation.cpp ├── Day 0: Mean, Median, and Mode.cpp ├── Day 1: Quartiles.cpp └── Day 1: Interquartile Range.cpp ├── C ├── Hello World! in C.c ├── sum-of-digits-of-a-five-digit-number.c ├── Array-Reversal.c ├── Printing Pattern using Loops.c ├── pointer-in-c.c ├── Printing Tokens.c ├── Playing-with-Characters.c ├── Sum and Difference of Two Numbers.c ├── Digit_Frequency.c ├── Function in C.c ├── Array-Reversal-2.c ├── 1d-arrays-in-c.c ├── Bitwise Operator.c └── for-loop-in-c.c ├── Interview-Preparation-Kit ├── Recursion and Backtracking │ ├── Recursion:Fibonacci Numbers.cpp │ └── Recursion: Davis Staircase.cpp ├── Miscellaneous │ ├── Flipping_bits.cpp │ └── Time_Complexity:Primality.cpp ├── Linked_Lists │ └── Detect a Cycle.cpp ├── String Manipulation │ ├── Strings: Making Anagrams.cpp │ ├── Alternating Characters.cpp │ ├── Common_Child.cpp │ └── Special_String_Again.cpp ├── Trees │ └── Trees:Is This a Binary Search Tree.cpp ├── Stack and Queues │ ├── Poisonous Plants.cpp │ └── Balanced Brackets.cpp ├── Dictionaries and Hashmaps │ └── Sherlock-and-Anagrams.cpp ├── Greedy_Algorithms │ ├── Max_Min.cpp │ └── Reverse_Shuffle_Merge.cpp ├── Dynamic_Programming │ ├── Candies.cpp │ └── Abberviation.cpp ├── Warm-up-Challenges │ ├── Counting-Valleys.cpp │ └── Repeated-String.cpp └── Arrays │ ├── Array_Manipulation.cpp │ └── 2D-Array-DS.cpp └── Data-Structure ├── Stacks ├── Simple Text Editor.py ├── Poisonous Plants.cpp └── Simple Text Editor.cpp ├── Linked Lists └── Insert a Node at the Tail of a Linked List.cpp ├── Trees └── Is This a Binary Search Tree.cpp ├── Queue ├── Down to Zero II.cpp └── Queue-using-Two-Stacks.cpp └── Arrays ├── Array_Manipulation.cpp └── 2D-Array-DS.cpp /Shell Scripting/Cut#4.sh: -------------------------------------------------------------------------------- 1 | cu -c -4 2 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#9.sh: -------------------------------------------------------------------------------- 1 | cut -f 2- 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .gitignore 3 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#2.sh: -------------------------------------------------------------------------------- 1 | cut -c 2,7 2 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#3.sh: -------------------------------------------------------------------------------- 1 | cut -c 2-7 2 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#5.sh: -------------------------------------------------------------------------------- 1 | cut -f 1-3 2 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#6.sh: -------------------------------------------------------------------------------- 1 | cut -c 13- 2 | -------------------------------------------------------------------------------- /Python/Python Evaluation.py: -------------------------------------------------------------------------------- 1 | eval(input()) 2 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#7.sh: -------------------------------------------------------------------------------- 1 | cut -d ' ' -f 4 2 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#8.sh: -------------------------------------------------------------------------------- 1 | cut -d ' ' -f -3 2 | -------------------------------------------------------------------------------- /Shell Scripting/Grep #1.sh: -------------------------------------------------------------------------------- 1 | grep -w the $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Grep #2.sh: -------------------------------------------------------------------------------- 1 | grep -iw the $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Paste-1.sh: -------------------------------------------------------------------------------- 1 | paste -sd ";" 2 | -------------------------------------------------------------------------------- /Shell Scripting/Paste-3.sh: -------------------------------------------------------------------------------- 1 | paste -sd "\t" 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#1.sh: -------------------------------------------------------------------------------- 1 | sort $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Uniq-Command#1.sh: -------------------------------------------------------------------------------- 1 | uniq $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Uniq-Command#4.sh: -------------------------------------------------------------------------------- 1 | uniq -u 2 | -------------------------------------------------------------------------------- /Shell Scripting/let's-echo.sh: -------------------------------------------------------------------------------- 1 | echo 'HELLO' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Awk-4.sh: -------------------------------------------------------------------------------- 1 | awk 'ORS=NR%2?";":"\n"' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Grep-B.sh: -------------------------------------------------------------------------------- 1 | grep '\([0-9]\) *\1' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Paste-4.sh: -------------------------------------------------------------------------------- 1 | paste -sd '\t\t\n' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#2.sh: -------------------------------------------------------------------------------- 1 | sort -r $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#3.sh: -------------------------------------------------------------------------------- 1 | sort -n $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#4.sh: -------------------------------------------------------------------------------- 1 | sort -r -n $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Tr_command_#2.sh: -------------------------------------------------------------------------------- 1 | tr -d "[a-z]" $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Tr_command_#3.sh: -------------------------------------------------------------------------------- 1 | tr -s " " $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/looping-with-number.sh: -------------------------------------------------------------------------------- 1 | seq 50 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sed command #1.sh: -------------------------------------------------------------------------------- 1 | sed 's/the /this /' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sed command #3.sh: -------------------------------------------------------------------------------- 1 | sed 's/thy/{&}/ig' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Tail_of_a_Text_File#2.sh: -------------------------------------------------------------------------------- 1 | tail -c 20 2 | -------------------------------------------------------------------------------- /Shell Scripting/Uniq-Command#3.sh: -------------------------------------------------------------------------------- 1 | uniq -ic | cut -c7- 2 | -------------------------------------------------------------------------------- /Shell Scripting/Grep-A.sh: -------------------------------------------------------------------------------- 1 | grep -iw -E 'th(e|at|en|ose)' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sed command #2.sh: -------------------------------------------------------------------------------- 1 | sed 's/thy /your /ig' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#5.sh: -------------------------------------------------------------------------------- 1 | sort -t $'\t' -k2 -rn $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#6.sh: -------------------------------------------------------------------------------- 1 | sort -t $'\t' -k2 -n $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sort_Command_#7.sh: -------------------------------------------------------------------------------- 1 | sort -t '|' -rn -k2 $1 2 | -------------------------------------------------------------------------------- /Shell Scripting/Tail_of_a_Text_File#1.sh: -------------------------------------------------------------------------------- 1 | 2 | tail -n 20 3 | -------------------------------------------------------------------------------- /Shell Scripting/Uniq-Command#2.sh: -------------------------------------------------------------------------------- 1 | uniq -c $1 | cut -c7- 2 | -------------------------------------------------------------------------------- /Shell Scripting/Sed command #4.sh: -------------------------------------------------------------------------------- 1 | sed -e 's/[0-9]\+ /**** /g' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Tr_command_#1.sh: -------------------------------------------------------------------------------- 1 | tr "[(,)]" "[[,]]" < /dev/stdin 2 | -------------------------------------------------------------------------------- /Shell Scripting/Paste-2.sh: -------------------------------------------------------------------------------- 1 | #paste -sd ';;\n' 2 | paste - - - -d ";" 3 | -------------------------------------------------------------------------------- /Shell Scripting/Slice-an-Array.sh: -------------------------------------------------------------------------------- 1 | arr=($(cat)) 2 | echo ${arr[*]:3:5} 3 | -------------------------------------------------------------------------------- /30 Days of Code/Day-28.sh: -------------------------------------------------------------------------------- 1 | grep -i '@gmail.com' | sort | awk '{print $1}' 2 | -------------------------------------------------------------------------------- /Python/Set .add().py: -------------------------------------------------------------------------------- 1 | print(len(set(input() for i in range(int(input()))))) 2 | -------------------------------------------------------------------------------- /Shell Scripting/A-Personalized-Echo.sh: -------------------------------------------------------------------------------- 1 | read name 2 | echo "Welcome $name" 3 | -------------------------------------------------------------------------------- /Shell Scripting/Cut#1.sh: -------------------------------------------------------------------------------- 1 | cut -c3 2 | 3 | # you can also use : cut -b3 4 | -------------------------------------------------------------------------------- /Python/Input().py: -------------------------------------------------------------------------------- 1 | x,k = map(int,input().split()) 2 | print(eval(input()) == k) 3 | -------------------------------------------------------------------------------- /Shell Scripting/Grep #3.sh: -------------------------------------------------------------------------------- 1 | #awk '!/that|That/' $1 2 | 3 | grep -iv that $1 4 | -------------------------------------------------------------------------------- /Shell Scripting/Awk-1.sh: -------------------------------------------------------------------------------- 1 | awk '$4==""{print "Not all scores are available for",$1}' 2 | -------------------------------------------------------------------------------- /Shell Scripting/Display-an-element-of-an-array.sh: -------------------------------------------------------------------------------- 1 | arr=($(cat)) 2 | echo ${arr[3]} 3 | -------------------------------------------------------------------------------- /Shell Scripting/Head_of_a_Text_File#2.sh: -------------------------------------------------------------------------------- 1 | #head -c 20 < /dev/stdin 2 | 3 | head -c 20 $1 4 | -------------------------------------------------------------------------------- /Python/Mod Divmod.py: -------------------------------------------------------------------------------- 1 | a,b=int(input()),int(input()) 2 | print(a//b,a%b,divmod(a,b),sep='\n') 3 | -------------------------------------------------------------------------------- /Python/Polar Coordinates.py: -------------------------------------------------------------------------------- 1 | import cmath 2 | print(*cmath.polar(complex(input())),sep='\n') 3 | -------------------------------------------------------------------------------- /Python/Tuples.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | t = tuple(map(int,input().split())) 3 | print(hash(t)) 4 | -------------------------------------------------------------------------------- /Shell Scripting/Arithmetic-Operations.cpp: -------------------------------------------------------------------------------- 1 | read exp 2 | printf "%.3f\n" $( echo $exp | bc -l ) 3 | -------------------------------------------------------------------------------- /Shell Scripting/Count-the-number-of-elements-in-an-Array.sh: -------------------------------------------------------------------------------- 1 | arr=($(cat)) 2 | echo ${#arr[@]} 3 | -------------------------------------------------------------------------------- /Shell Scripting/looping-and-skipping.sh: -------------------------------------------------------------------------------- 1 | for i in {1..100..2} 2 | do 3 | echo $i 4 | done 5 | -------------------------------------------------------------------------------- /Shell Scripting/Sed command #5.sh: -------------------------------------------------------------------------------- 1 | sed -E 's/([0-9]{4}) ([0-9]{4}) ([0-9]{4}) ([0-9]{4})/\4 \3 \2 \1 /g' 2 | -------------------------------------------------------------------------------- /Python/Power - Mod Power.py: -------------------------------------------------------------------------------- 1 | a,b,m=int(input()),int(input()),int(input()) 2 | print(a**b,pow(a,b,m),sep='\n') 3 | -------------------------------------------------------------------------------- /Python/Integers Come In All Sizes.py: -------------------------------------------------------------------------------- 1 | l = list(map(int,[input() for i in range(4)])) 2 | print(l[0]**l[1]+l[2]**l[3]) 3 | 4 | -------------------------------------------------------------------------------- /Python/Symmetric Difference.py: -------------------------------------------------------------------------------- 1 | a,b = [set(input().split()) for i in range(4)][1::2] 2 | print('\n'.join(sorted(a^b, key=int))) 3 | -------------------------------------------------------------------------------- /Shell Scripting/Concatenate-an-array-with-itself.sh: -------------------------------------------------------------------------------- 1 | arr=($(cat)) 2 | arr=("${arr[@]}" "${arr[@]}" "${arr[@]}") 3 | echo ${arr[*]} 4 | -------------------------------------------------------------------------------- /Python/Any or All.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = input().split() 3 | print(all([int(j)>0 for j in l]) and any([j==j[::-1] for j in l])) 4 | -------------------------------------------------------------------------------- /Shell Scripting/Middle_of_a_Text_File.sh: -------------------------------------------------------------------------------- 1 | 2 | head -n 22 $1 | tail -n 11 3 | 4 | #cut -d$'\n' -f12-22 $1 5 | 6 | #sed -n '12,22p' $1 7 | -------------------------------------------------------------------------------- /Python/Numpy/Shape and Reshape.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | lst = np.array(list(map(int,input().split()))) 4 | print(lst.reshape(3,3)) 5 | -------------------------------------------------------------------------------- /Python/Set .difference() Operation.py: -------------------------------------------------------------------------------- 1 | a,b = [input().split() for i in range(4)][1::2] 2 | print(len(set(map(int,a)) - set(map(int,b)))) 3 | -------------------------------------------------------------------------------- /Python/Set .intersection() Operation.py: -------------------------------------------------------------------------------- 1 | a,b = [input().split() for i in range(4)][1::2] 2 | print(len(set(map(int,a)) & set(map(int,b)))) 3 | -------------------------------------------------------------------------------- /Python/Set .union() Operation.py: -------------------------------------------------------------------------------- 1 | a,b = [input().split() for i in range(4)][1::2] 2 | print(len(set(map(int,a)).union(set(map(int,b))))) 3 | -------------------------------------------------------------------------------- /Shell Scripting/The-World-of-Numbers.sh: -------------------------------------------------------------------------------- 1 | read a 2 | read b 3 | echo $(( a+b )) 4 | echo $(( a-b )) 5 | echo $(( a*b )) 6 | echo $(( a/b )) 7 | -------------------------------------------------------------------------------- /Python/Calendar Module.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | m,d,y = map(int,input().split()) 3 | print(calendar.day_name[calendar.weekday(y,m,d)].upper()) 4 | -------------------------------------------------------------------------------- /Python/Find Angle MBC.py: -------------------------------------------------------------------------------- 1 | import math 2 | a=int(input()) 3 | b=int(input()) 4 | print(str(int(round(math.degrees(math.atan2(a,b)))))+chr(176)) 5 | -------------------------------------------------------------------------------- /Python/Set .symmetric_difference() Operation.py: -------------------------------------------------------------------------------- 1 | a,b=[input().split() for i in range(4)][1::2] 2 | print(len(set(map(int,a)) ^ set(map(int,b)))) 3 | -------------------------------------------------------------------------------- /Python/ginortS.py: -------------------------------------------------------------------------------- 1 | order = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1357902468' 2 | print(*sorted(input(), key=order.index), sep='') 3 | -------------------------------------------------------------------------------- /Python/itertools.product().py: -------------------------------------------------------------------------------- 1 | from itertools import product 2 | l = [map(int,input().split()) for i in range(2)] 3 | print(*product(*l)) 4 | 5 | -------------------------------------------------------------------------------- /Shell Scripting/Filter-an-array-with-Patterns.sh: -------------------------------------------------------------------------------- 1 | 2 | #awk '!/a|A/' $1 3 | 4 | #grep -vi a 5 | 6 | arr=($(cat)) 7 | echo ${arr[@]/*[aA]*/} 8 | -------------------------------------------------------------------------------- /Shell Scripting/Lonely_integer_Bash.sh: -------------------------------------------------------------------------------- 1 | num=0 2 | read N 3 | read arr 4 | for i in ${arr[*]} 5 | do 6 | num=$(( $num^$i)) 7 | done 8 | echo $num 9 | -------------------------------------------------------------------------------- /Shell Scripting/Remove-first-capital-letter-from-each-element.sh: -------------------------------------------------------------------------------- 1 | #sed s/[A-Z]/./ $1 | paste -sd ' ' 2 | 3 | arr=($(cat)) 4 | echo ${arr[@]/[A-Z]/.} 5 | -------------------------------------------------------------------------------- /Shell Scripting/Awk-2.sh: -------------------------------------------------------------------------------- 1 | awk 'OFS=" : "{ 2 | if( $2>50 && $3>50 && $4>50 ) 3 | print $1,"Pass" 4 | else 5 | print $1,"Fail" 6 | }' 7 | -------------------------------------------------------------------------------- /Python/Zipped!.py: -------------------------------------------------------------------------------- 1 | n,x = map(int,input().split()) 2 | l = [list(map(float,input().split())) for _ in range(x)] 3 | for i in zip(*l): 4 | print(sum(i)/x) 5 | -------------------------------------------------------------------------------- /Python/Triangle Quest.py: -------------------------------------------------------------------------------- 1 | for i in range(1,int(input())): #More than 2 lines will result in 0 score. Do not leave a blank line also 2 | print(((10**i)//9)*i) 3 | -------------------------------------------------------------------------------- /Python/Word Order.py: -------------------------------------------------------------------------------- 1 | d = dict() 2 | for i in range(int(input())): 3 | x = input() 4 | d.setdefault(x,0) 5 | d[x]+=1 6 | print(len(d)) 7 | print(*d.values()) 8 | -------------------------------------------------------------------------------- /Python/itertools.permutations().py: -------------------------------------------------------------------------------- 1 | from itertools import permutations 2 | s,a = input().split() 3 | for i in permutations(sorted(s),int(a)): 4 | print(''.join(i)) 5 | -------------------------------------------------------------------------------- /C++/Hello-World-With-C++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | cout<<"Hello, World!"; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Python/Athlete Sort.py: -------------------------------------------------------------------------------- 1 | n,m = map(int,input().split()) 2 | l =[input() for i in range(n)] 3 | k = int(input()) 4 | print(*sorted(l, key=lambda r: int(r.split()[k])),sep='\n') 5 | -------------------------------------------------------------------------------- /Python/Compress the String!.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | s = input() 3 | l = [] 4 | for i,j in groupby(s): 5 | l.append((len(list(j)),int(i))) 6 | print(*l,sep=' ') 7 | -------------------------------------------------------------------------------- /Python/The Captain's Room.py: -------------------------------------------------------------------------------- 1 | l = [input().split() for i in range(2)][1] 2 | s=set() 3 | m=set() 4 | for i in l: 5 | s.add(i) if i not in s else m.add(i) 6 | print((s-m).pop()) 7 | -------------------------------------------------------------------------------- /Maths/Cutting Paper Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void){ 4 | long long n,m;cin>>n>>m; 5 | cout<=1: 8 | l[x]-=1 9 | counter+=y 10 | print(counter) 11 | -------------------------------------------------------------------------------- /C++/strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // Complete the program 7 | string a,b;cin>>a>>b; 8 | cout< 2 | 3 | 4 | 5 |

6 | 7 | 8 | 9 | Solution of HackerRank Problems 10 | -------------------------------------------------------------------------------- /Python/DefaultDict Tutorial.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | d = defaultdict(list) 3 | n,m = map(int,input().split()) 4 | for i in range(1,n+1): 5 | x = input() 6 | d[x].append(i) 7 | for i in range(m): 8 | x = input() 9 | if x in d: 10 | print(*d[x]) 11 | else: 12 | print(-1) 13 | -------------------------------------------------------------------------------- /Shell Scripting/Awk-3.sh: -------------------------------------------------------------------------------- 1 | aw '{ 2 | avg=($2+$3+$4)/3 3 | if( avg>=80 ) 4 | print $1,$2,$3,$4,": A" 5 | else if(avg<80 && avg>=60 ) 6 | print $1,$2,$3,$4,": B" 7 | else if(avg<60 && avg>=50) 8 | print $1,$2,$3,$4,": C" 9 | else 10 | print $1,$2,$3,$4,": FAIL"; 11 | }' 12 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 2: Basic Probability.go: -------------------------------------------------------------------------------- 1 | // 2 dice have 6 * 6 outcomes and out of those if we count those who have sum less then 9 they 2 | // will be 30 {should have counted those who have sum greater then 9 ;)} 3 | // P(A) = favourable_outcome / total_outcome 4 | // = > 30 / 36 5 | // = > 5 / 6 6 | // So option B is correct. 7 | -------------------------------------------------------------------------------- /30 Days of Code/Day-07.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void){ 4 | int n; cin>>n; 5 | stacks; 6 | while(n--){ 7 | int x;cin>>x; 8 | s.push(x); 9 | } 10 | while(s.size()){ 11 | cout< 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | 9 | char s[100]; 10 | scanf("%[^\n]%*c", &s); 11 | printf("Hello, World!\n%s",s); 12 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Python/String Formatting.py: -------------------------------------------------------------------------------- 1 | def print_formatted(number): 2 | n = len(str(bin(number))) 3 | for i in range(1,number+1): 4 | print(str(i).rjust(n-2)+str(oct(i))[2::].rjust(n-1,' ')+str(hex(i).upper())[2::].rjust(n-1,' ')+str(bin(i))[2::].rjust(n-1,' ')) 5 | 6 | if __name__ == '__main__': 7 | n = int(input()) 8 | print_formatted(n) 9 | -------------------------------------------------------------------------------- /Python/Validating Postal Codes.py: -------------------------------------------------------------------------------- 1 | regex_integer_in_range = r"^[1-9][0-9]{5}$" # Do not delete 'r'. 2 | regex_alternating_repetitive_digit_pair = r"(\d)(?=\d\1)" # Do not delete 'r'. 3 | 4 | 5 | import re 6 | P = input() 7 | 8 | print (bool(re.match(regex_integer_in_range, P)) 9 | and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2) 10 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 2: More Dice.go: -------------------------------------------------------------------------------- 1 | // 1. Values should be different so (1,1) (2,2) (3,3) .... (6,6) will be excluded, after it 2 | // remaining favourable cases 30 3 | // 2. Now we have to look for those values whose sum is 6 then (1,5) , (2,4) , (4,2) , (5, 1) are remaining. 4 | // 5 | 6 | // So P = 4 / 36 -> 1/9 7 | 8 | // Option A is correct. 9 | -------------------------------------------------------------------------------- /Python/Collections.deque().py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | d = deque() 3 | for _ in range(int(input())): 4 | l = input().split() 5 | if l[0] == 'append': 6 | d.extend(l[1]) 7 | elif l[0] == 'pop': 8 | d.pop() 9 | elif l[0] == 'appendleft': 10 | d.appendleft(l[1]) 11 | else: 12 | d.popleft() 13 | print(*d) 14 | -------------------------------------------------------------------------------- /Python/Set .discard(), .remove() & .pop().py: -------------------------------------------------------------------------------- 1 | n =int(input()) 2 | s =set(map(int,input().split())) 3 | for i in range(int(input())): 4 | l = input().split() 5 | if l[0]== 'remove': 6 | s.remove(int(l[1])) 7 | elif l[0] == 'pop': 8 | s.pop() 9 | elif l[0] == 'discard': 10 | s.discard(int(l[1])) 11 | print(sum(s)) 12 | 13 | -------------------------------------------------------------------------------- /Python/Alphabet Rangoli.py: -------------------------------------------------------------------------------- 1 | import string 2 | def print_rangoli(n): 3 | alpha = string.ascii_lowercase 4 | L = [] 5 | for i in range(n): 6 | s = "-".join(alpha[i:n]) 7 | L.append((s[::-1]+s[1:]).center(4*n-3, "-")) 8 | print('\n'.join(L[:0:-1]+L)) 9 | 10 | if __name__ == '__main__': 11 | n = int(input()) 12 | print_rangoli(n) 13 | -------------------------------------------------------------------------------- /C++/Input-and-Output.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 | int a , b, c; 12 | cin>>a>>b>>c; 13 | cout< 2 | 3 | using namespace std; 4 | 5 | int fibonacci(int n) { 6 | // Complete the function. 7 | return (n<=1)?n:fibonacci(n-1)+fibonacci(n-2); 8 | } 9 | 10 | int main() { 11 | int n; 12 | cin >> n; 13 | cout << fibonacci(n); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Maths/Leonardo's Prime Factors.py: -------------------------------------------------------------------------------- 1 | prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79] 2 | x = int(input()) 3 | while x>0: 4 | x = x-1 5 | n = int(input()) 6 | ans = 0 7 | counter = 1 8 | for i in prime: 9 | if counter*i<=n: 10 | ans+=1 11 | counter*=i 12 | else: 13 | break 14 | print(ans) 15 | -------------------------------------------------------------------------------- /Python/Maximize It!.py: -------------------------------------------------------------------------------- 1 | k,m = map(int,input().split()) 2 | ans = 0 3 | 4 | def sol(l , a , i): 5 | global ans 6 | if i == k: 7 | ans = max(ans , a%m) 8 | return 9 | for j in l[i]: 10 | a += j*j 11 | sol(l, a, i+1) 12 | a -= j*j 13 | 14 | 15 | l = [list(map(int,input().split()))[1:] for i in range(k)] 16 | sol(l,0,0) 17 | print(ans) 18 | -------------------------------------------------------------------------------- /Python/Iterables and Iterators.py: -------------------------------------------------------------------------------- 1 | from itertools import combinations 2 | n = int(input()) 3 | s = input().split() 4 | k = int(input()) 5 | l = list(combinations(s , k)) 6 | counter=0 7 | for i in l: 8 | found = False 9 | for k in i: 10 | if k == 'a': 11 | found =True 12 | break 13 | if found: 14 | counter+=1 15 | print('{:.3}'.format(counter/len(l))) 16 | -------------------------------------------------------------------------------- /Python/Merge the Tools!.py: -------------------------------------------------------------------------------- 1 | def merge_the_tools(string, k): 2 | for st in zip(*([iter(string)] * k)): 3 | s = set() 4 | l=[] 5 | for i in st: 6 | if i not in s: 7 | l.append(i) 8 | s.add(i) 9 | 10 | print(''.join(l)) 11 | if __name__ == '__main__': 12 | string, k = input(), int(input()) 13 | merge_the_tools(string, k) 14 | -------------------------------------------------------------------------------- /C++/basic-data-types.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | // Complete the code. 8 | int a; long long b; char c; float d; double e; 9 | cin>>a>>b>>c>>d>>e; 10 | cout< 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | int n; 9 | scanf("%d", &n); 10 | //complete the code to calculate the sum of the five digits on n. 11 | int sum=0; 12 | while(n){ 13 | sum += n%10; 14 | n /= 10; 15 | } 16 | printf("%d",sum); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/Warmup/Solve-Me-First.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int solveMeFirst(int a, int b) { 9 | // Hint: Type return a+b; below: 10 | return a+b; 11 | } 12 | 13 | int main() { 14 | int num1, num2; 15 | int sum; 16 | cin>>num1>>num2; 17 | sum = solveMeFirst(num1,num2); 18 | cout< 3 | #include 4 | 5 | int main() 6 | { 7 | int num, *arr, i; 8 | scanf("%d", &num); 9 | arr = (int*) malloc(num * sizeof(int)); 10 | for(i = 0; i < num; i++) { 11 | scanf("%d", arr + i); 12 | } 13 | 14 | 15 | /* Write the logic to reverse the array. */ 16 | 17 | for(i = num-1; i>=0; i--) 18 | printf("%d ", *(arr + i)); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Python/Map and Lambda Function.py: -------------------------------------------------------------------------------- 1 | cube = lambda x: x**3# complete the lambda function 2 | 3 | def fibonacci(n): 4 | # return a list of fibonacci numbers 5 | if n==0: 6 | return [] 7 | if n==1: 8 | return [0] 9 | l=[0,1] 10 | for _ in range(2,n): 11 | l.append(l[-1]+l[-2]) 12 | return l 13 | 14 | if __name__ == '__main__': 15 | n = int(input()) 16 | print(list(map(cube, fibonacci(n)))) 17 | -------------------------------------------------------------------------------- /Python/Reduce Function.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | 3 | def product(fracs): 4 | import operator 5 | t = reduce(operator.mul, fracs)# complete this line with a reduce statement 6 | return t.numerator, t.denominator 7 | 8 | if __name__ == '__main__': 9 | fracs = [] 10 | for _ in range(int(input())): 11 | fracs.append(Fraction(*map(int, input().split()))) 12 | result = product(fracs) 13 | print(*result) 14 | -------------------------------------------------------------------------------- /30 Days of Code/Day-29.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void){ 4 | int t; cin>>t; 5 | while(t--){ 6 | int a, b;cin>>a>>b; 7 | if(b&1){ 8 | cout< 2 | #include 3 | 4 | void update(int *a,int *b) { 5 | // Complete this function 6 | int tempA = *a; 7 | int tempB = *b; 8 | *a = tempA+tempB; 9 | *b = abs(tempA - tempB); 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 | -------------------------------------------------------------------------------- /C++/pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void update(int *a,int *b) { 5 | // Complete this function 6 | int tempA = *a; 7 | int tempB = *b; 8 | *a = tempA+tempB; 9 | *b = abs(tempA - tempB); 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 | -------------------------------------------------------------------------------- /Data-Structure/Stacks/Simple Text Editor.py: -------------------------------------------------------------------------------- 1 | c = '' 2 | stk=[] 3 | stk.append(c) 4 | for _ in range(int(input())): 5 | l = input().split() 6 | if l[0] == "1": 7 | c+=l[1] 8 | stk.append(c) 9 | elif l[0] == "2": 10 | c = c[0:len(c)-int(l[1]):] 11 | stk.append(c) 12 | elif l[0] == "3": 13 | print(c[int(l[1])-1]) 14 | else: 15 | stk.pop() 16 | c = stk[len(stk)-1] 17 | 18 | 19 | -------------------------------------------------------------------------------- /Python/The Minion Game.py: -------------------------------------------------------------------------------- 1 | def minion_game(string): 2 | b=0 3 | k=0 4 | vow='AIEOUaeiou' 5 | for i in range(len(s)): 6 | if s[i] in vow: 7 | k+=(len(s)-i) 8 | else: 9 | b+=(len(s)-i) 10 | if b==k: 11 | print("Draw") 12 | elif b>k: 13 | print(f'Stuart {b}') 14 | else: 15 | print(f'Kevin {k}') 16 | 17 | if __name__ == '__main__': 18 | s = input() 19 | minion_game(s) 20 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 2: Compound Event Probability.go: -------------------------------------------------------------------------------- 1 | // possible cases are that 2 | // black ball from 1 and red ball from other two : 3/7 * 5/9 * 1/2 3 | // black ball from 2 and red ball from other two : 4/9 * 4/7 * 1/2 4 | // black ball from 3 and red ball from other two : 1/2 * 5/9 * 4/7 5 | 6 | // -> 15/126 + 16/126 + 20/126 7 | // -> 51 / 126 8 | 9 | // gcd will be 3 so dividing both num & deno by 3 we get 10 | // -> 17/42 11 | // So option C is correct 12 | -------------------------------------------------------------------------------- /C++/functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | /* 7 | Add `int max_of_four(int a, int b, int c, int d)` here. 8 | */ 9 | int max_of_four(int a, int b , int c, int d){ 10 | return max({a,b,c,d}); 11 | } 12 | int main() { 13 | int a, b, c, d; 14 | scanf("%d %d %d %d", &a, &b, &c, &d); 15 | int ans = max_of_four(a, b, c, d); 16 | printf("%d", ans); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Maths/Diwali Lights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() { 9 | long long r,c,num; cin>>r>>c; 10 | if(r%2 == 0) { 11 | num = 10*((r/2)-1)+1; 12 | num = num + 2*(c-1); 13 | } else { 14 | num = 10*(r/2); 15 | num = num + 2*(c-1); 16 | } 17 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() { 9 | long long r,c,num; cin>>r>>c; 10 | if(r%2 == 0) { 11 | num = 10*((r/2)-1)+1; 12 | num = num + 2*(c-1); 13 | } else { 14 | num = 10*(r/2); 15 | num = num + 2*(c-1); 16 | } 17 | cout< 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 | int n; cin >> n; 12 | vectorv(n); 13 | for(auto&itr:v) 14 | cin >> itr; 15 | sort(v.begin(), v.end()); 16 | for(auto&itr:v) 17 | cout << itr << ' '; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/Printing Pattern using Loops.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | int n; 7 | scanf("%d", &n); 8 | int len = n*2 - 1; 9 | for(int i=0;i 2 | #include 3 | 4 | void update(int *a,int *b) { 5 | // Complete this function 6 | int tempPtrOne = *a; 7 | int tempPtrTwo = *b; 8 | *b = abs(tempPtrOne - tempPtrTwo); 9 | *a = tempPtrOne + tempPtrTwo; 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 | -------------------------------------------------------------------------------- /C/Printing Tokens.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | char *s; 9 | s = malloc(1024 * sizeof(char)); 10 | scanf("%[^\n]", s); 11 | s = realloc(s, strlen(s) + 1); 12 | //Write your logic to print the tokens of the sentence here. 13 | s = strtok(s , " "); 14 | while(s!=NULL){ 15 | printf("%s\n",s); 16 | s = strtok(NULL , " "); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Maths/Minimum Height Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int lowestTriangle(int base, int area){ 6 | // Complete this function 7 | for(int i=1;;++i){ 8 | if((base*i)/2>=area){ 9 | return i; 10 | } 11 | } 12 | } 13 | 14 | int main() { 15 | int base; 16 | int area; 17 | cin >> base >> area; 18 | int height = lowestTriangle(base, area); 19 | cout << height << endl; 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Python/Capitalize!.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the solve function below. 10 | def solve(s): 11 | for i in s.split(): 12 | s = s.replace(i,i.capitalize()) 13 | return s 14 | 15 | if __name__ == '__main__': 16 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 17 | 18 | s = input() 19 | 20 | result = solve(s) 21 | 22 | fptr.write(result + '\n') 23 | 24 | fptr.close() 25 | -------------------------------------------------------------------------------- /Python/Validating Credit Card Numbers.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | is_grouping = re.compile(r'^(?:.{4}\-){3}.{4}$').match 4 | is_consecutive = re.compile(r'(.)\1{3}').search 5 | is_valid = re.compile(r'^[456]\d{15}$').match 6 | 7 | for _ in range(int(input())): 8 | card_no = input() 9 | if is_grouping(card_no): 10 | card_no = card_no.replace('-', '') 11 | if is_valid(card_no) and not is_consecutive(card_no): 12 | print('Valid') 13 | else: 14 | print('Invalid') 15 | -------------------------------------------------------------------------------- /Python/What's Your Name?.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'print_full_name' function below. 3 | # 4 | # The function is expected to return a STRING. 5 | # The function accepts following parameters: 6 | # 1. STRING first 7 | # 2. STRING last 8 | # 9 | 10 | def print_full_name(first, last): 11 | print(f'Hello {first} {last}! You just delved into python.') 12 | 13 | if __name__ == '__main__': 14 | first_name = input() 15 | last_name = input() 16 | print_full_name(first_name, last_name) 17 | -------------------------------------------------------------------------------- /30 Days of Code/Day-06.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void){ 4 | int n; cin>>n; 5 | while(n--){ 6 | string s; 7 | cin>>s; 8 | string e{""},o{""}; 9 | for(int i=0;i<(int)s.size();++i){ 10 | if((i+1)&1){ 11 | o.push_back(s[i]); 12 | }else{ 13 | e.push_back(s[i]); 14 | } 15 | } 16 | cout< 2 | using namespace std; 3 | int main(void){ 4 | int n , q; 5 | cin>>n>>q; 6 | vector>arr(n); 7 | for(int i=0;i>e; 10 | for(int k,j=0;j>k; 12 | arr[i].push_back(k); 13 | } 14 | } 15 | while(q--){ 16 | int i ,j; 17 | cin>>i>>j; 18 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | typedef long long ll; 9 | 10 | int main() { 11 | ll l,s1,s2,q,qi; 12 | cin>>l>>s1>>s2>>q; 13 | if(s1 > s2) swap(s1,s2); 14 | while(q--){ 15 | cin>>qi; 16 | cout< 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n ; cin>>n; 12 | vectorv(n); 13 | for(auto&itr:v){ 14 | cin>>itr; 15 | } 16 | for(auto itr = v.rbegin(); itr!=v.rend(); ++itr){ 17 | cout<<*itr<<' '; 18 | } 19 | cout< 2 | 3 | using namespace std; 4 | 5 | // Complete the factorial function below. 6 | int factorial(int n) { 7 | return (n==0 || n==1)?1:n*factorial(n-1); 8 | } 9 | 10 | int main() 11 | { 12 | ofstream fout(getenv("OUTPUT_PATH")); 13 | 14 | int n; 15 | cin >> n; 16 | cin.ignore(numeric_limits::max(), '\n'); 17 | 18 | int result = factorial(n); 19 | 20 | fout << result << "\n"; 21 | 22 | fout.close(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/Playing-with-Characters.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | 9 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ char a , arr[20] , ar[1000]; 10 | scanf("%c",&a); 11 | scanf("%s",arr); 12 | scanf("\n"); 13 | scanf("%[^\n]%*c" , ar); 14 | printf("%c\n",a); 15 | printf("%s\n",arr); 16 | for(int i=0;i 3 | 4 | using namespace std; 5 | 6 | 7 | 8 | int main() 9 | { 10 | int N; 11 | cin >> N; 12 | cin.ignore(numeric_limits::max(), '\n'); 13 | if(N&1){ 14 | cout<<"Weird"<=2){ 17 | cout<<"Not Weird"<=6 and N<=20){ 19 | cout<<"Weird"< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | /* 9 | add code for struct here. 10 | */ 11 | struct Student{ 12 | int age , standard; 13 | string first_name , last_name; 14 | }; 15 | 16 | int main() { 17 | Student st; 18 | 19 | cin >> st.age >> st.first_name >> st.last_name >> st.standard; 20 | cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Sum and Difference of Two Numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int firstIntNumber , secondIntNumber; 9 | double firstFloatNumber , secondFloatNumber; 10 | scanf("%d%d%lf%lf",&firstIntNumber, &secondIntNumber,&firstFloatNumber, &secondFloatNumber); 11 | printf("%d %d \n%.1lf %.1lf\n",firstIntNumber+secondIntNumber , firstIntNumber - secondIntNumber , firstFloatNumber+secondFloatNumber , firstFloatNumber-secondFloatNumber); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Python/Lists.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = [] 3 | for i in range(n): 4 | x = input().split() 5 | if x[0] == 'append': 6 | l.append(int(x[1])) 7 | elif x[0] == 'print': 8 | print(l) 9 | elif x[0] == 'remove': 10 | l.remove(int(x[1])) 11 | elif x[0] == 'sort': 12 | l = sorted(l) 13 | elif x[0] == 'pop': 14 | l.pop() 15 | elif x[0] == 'reverse': 16 | l = l.reverse() 17 | elif x[0] == 'insert': 18 | l.insert(int(x[1]),int(x[2])) 19 | else: 20 | print("temp") 21 | 22 | -------------------------------------------------------------------------------- /Python/Piling Up!.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s = list(map(int,[input().split() for i in range(2)][1])) 3 | i,j = 0, len(s)-1 4 | maxR=s[i] 5 | maxL=s[j] 6 | changed=True 7 | while is[j] and s[i]>=s[i+1]: 10 | changed=True 11 | i+=1 12 | maxR = s[i] 13 | elif s[j]>=s[j-1]: 14 | changed=True 15 | j-=1 16 | maxL = s[j] 17 | if (i==j): 18 | print("Yes") 19 | else: 20 | print("No") 21 | -------------------------------------------------------------------------------- /C/Digit_Frequency.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 9 | char str[1000]; 10 | scanf("%d",str); 11 | int freqCounter[10] = {0}; 12 | for(int i=0;i<(int)strlen(str);++i){ 13 | if(str[i]<='0' && str[i]>='9'){ 14 | freqCounter[str[i]-'a']++; 15 | } 16 | } 17 | for(int i=0;i<10;++i){ 18 | printf("%d ",freqCounter[i]); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C/Function in C.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Add `int max_of_four(int a, int b, int c, int d)` here. 4 | */ 5 | int max_of_four(int a, int b , int c , int d) { 6 | if(a>b && a>c && a>d){ 7 | return a; 8 | }else if(b>c && b>d && b>a){ 9 | return b; 10 | }else if(c>a && c>b && c>d){ 11 | return c; 12 | }else{ 13 | return d; 14 | } 15 | } 16 | 17 | int main() { 18 | int a, b, c, d; 19 | scanf("%d %d %d %d", &a, &b, &c, &d); 20 | int ans = max_of_four(a, b, c, d); 21 | printf("%d", ans); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Array-Reversal-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int num, *arr, i , j; 7 | scanf("%d", &num); 8 | arr = (int*) malloc(num * sizeof(int)); 9 | for(i = 0; i < num; i++) { 10 | scanf("%d", arr + i); 11 | } 12 | 13 | 14 | /* Write the logic to reverse the array. */ 15 | 16 | i = 0 , j = num-1; 17 | while(i 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 | int n; cin >> n; 12 | vectorv(n); 13 | for(auto&itr:v) 14 | cin >> itr; 15 | int x; cin >> x; --x; 16 | v.erase(v.begin()+x); 17 | cin >> n >> x; --x , --n; 18 | v.erase(v.begin()+n , v.begin() + x); 19 | cout << v.size() << endl; 20 | for(auto&itr:v){ 21 | cout << itr << ' '; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/1d-arrays-in-c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 9 | // i could solve this with one for loop and without array 10 | // but let's just don't spoil the motive of HackerRank 11 | int n; 12 | scanf("%d",&n); 13 | int *array = (int*)malloc(n * sizeof(int)); 14 | for(int i=0;i 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int dd , mm , yy; 12 | int DD , MM , YY; 13 | cin>>dd>>mm>>yy>>DD>>MM>>YY; 14 | long long fine{}; 15 | if(dd > DD && MM==mm && YY == yy){ 16 | fine+=abs(dd-DD)*15; 17 | } 18 | if(MM < mm && YY == yy){ 19 | fine+=(abs(MM-mm))*500; 20 | } 21 | if(YY < yy){ 22 | fine+=10000; 23 | } 24 | cout< 2 | using namespace std; 3 | #define int int64_t 4 | 5 | signed main(void){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | cout.tie(nullptr); 9 | #ifdef HELL_JUDGE 10 | freopen("input","r",stdin); 11 | freopen("output","w",stdout); 12 | #endif 13 | int t; cin >> t; 14 | while (t--) { 15 | int n; cin >> n; 16 | int ans{}; 17 | for (int i=1; i<=n; ++i) { 18 | int x; cin >> x; 19 | if ((i*(n-i-1))&1) { 20 | ans^= x; 21 | } 22 | } 23 | cout << ans << '\n'; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Algorithms/Bit Manipulation/AND Product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int int64_t 4 | 5 | signed main(void){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | cout.tie(nullptr); 9 | #ifdef HELL_JUDGE 10 | freopen("input","r",stdin); 11 | freopen("output","w",stdout); 12 | #endif 13 | int t; cin >> t; 14 | while (t--) { 15 | int left , right; cin >> left >> right; 16 | int counter{}; 17 | while (left != right) { 18 | ++counter; 19 | left>>=1ll; 20 | right>>=1ll; 21 | } 22 | cout << (right <<= counter) << '\n'; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Maths/Find the Point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | 20 | int main(void){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(nullptr); 23 | cout.tie(nullptr); 24 | int n;cin>>n; 25 | while(n--){ 26 | int a,b,c,d;cin>>a>>b>>c>>d; 27 | cout<<2*c-a<<' '<<2*d-b< 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | vector a(n); 10 | for(int a_i = 0; a_i < n; a_i++){ 11 | cin >> a[a_i]; 12 | } 13 | int counter{}; 14 | for( int i{}; i < n; ++i ) { 15 | for( int j{i+1}; j < n; ++j ) { 16 | if( a[ j ] < a[ i ] ) { 17 | swap( a[j] , a[i]); 18 | ++counter; 19 | } 20 | 21 | } 22 | } 23 | 24 | printf("Array is sorted in %d swaps.\n",counter); 25 | printf("First Element: %d\n" , a[0]); 26 | printf("Last Element: %d\n" , a[n-1]); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /30 Days of Code/Day-01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | int main() { 8 | // Declare a variable named 'input_string' to hold our input. 9 | string input_string; 10 | 11 | // Read a full line of input from stdin (cin) and save it to our variable, input_string. 12 | getline(cin, input_string); 13 | 14 | // Print a string literal saying "Hello, World." to stdout using cout. 15 | cout << "Hello, World." << endl; 16 | 17 | // TODO: Write a line of code here that prints the contents of input_string to stdout. 18 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | 20 | int main(void){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(nullptr); 23 | cout.tie(nullptr); 24 | int n; cin>>n; 25 | int sum{}; 26 | while(n--){ 27 | int x; cin>>x; 28 | sum+=x; 29 | } 30 | cout<next != nullptr) { 19 | temp = temp->next; 20 | } 21 | temp->next = node; 22 | } 23 | return head; 24 | } 25 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 0: Weighted Mean.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int int64_t 4 | 5 | signed main(void){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | cout.tie(nullptr); 9 | #ifdef HELL_JUDGE 10 | freopen("input","r",stdin); 11 | freopen("output","w",stdout); 12 | #endif 13 | int n; cin >> n; 14 | vectorv(n); 15 | double total{}; 16 | for(auto&itr:v){ 17 | cin >> itr; 18 | } 19 | double ans{}; 20 | for(int i=0; i> x; 22 | total+=x; 23 | ans+= (x* v.at(i)); 24 | } 25 | cout << fixed << setprecision(1) << ans / total << '\n'; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C++/Lower Bound-STL.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 | int n; cin >> n; 12 | vectorv(n); 13 | for(auto&itr:v) 14 | cin >> itr; 15 | cin >> n; 16 | while(n--){ 17 | int q; cin >> q; 18 | auto itr = lower_bound(v.begin() , v.end() , q); 19 | if(v.at(itr - v.begin()) == q){ 20 | cout <<"Yes "; 21 | } else { 22 | cout <<"No "; 23 | } 24 | cout << (itr - v.begin() +1) << '\n'; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C++/Print Pretty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int T; cin >> T; 7 | cout << setiosflags(ios::uppercase); 8 | cout << setw(0xf) << internal; 9 | while(T--) { 10 | double A; cin >> A; 11 | double B; cin >> B; 12 | double C; cin >> C; 13 | 14 | /* Enter your code here */ 15 | cout << hex << left << nouppercase; 16 | cout << showbase << int64_t(A) << '\n'; 17 | cout << fixed << dec << right << setw(15) << setfill('_') << showpos << setprecision(2); 18 | cout << B << '\n'; 19 | cout << uppercase << noshowbase << scientific << noshowpos << setprecision(9); 20 | cout << C << '\n'; 21 | } 22 | return 0; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /C++/Sets-STL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 12 | int q; cin >> q; 13 | sets; 14 | while(q--){ 15 | int a , b; cin >> a >> b; 16 | switch(a){ 17 | case 1: 18 | s.insert(b); 19 | break; 20 | case 2: 21 | s.erase(b); 22 | break; 23 | case 3: 24 | puts((s.find(b)!=s.end())?"Yes":"No"); 25 | break; 26 | } 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /30 Days of Code/Day-25.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 */ int t; 11 | cin>>t; 12 | while(t--){ 13 | long long n; cin >>n; 14 | if(n==1){ 15 | cout<<"Not prime"< 2 | using namespace std; 3 | #define int int64_t 4 | 5 | signed main(void){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | cout.tie(nullptr); 9 | #ifdef HELL_JUDGE 10 | freopen("input","r",stdin); 11 | freopen("output","w",stdout); 12 | #endif 13 | int n; cin >> n; 14 | vectorv(n); 15 | for (auto&itr:v) { 16 | cin >> itr; 17 | } 18 | sort(v.begin(),v.end()); 19 | int counter{}; 20 | for (int i=0; i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector parseInts(string str) { 7 | // Complete this function 8 | int tempInt; 9 | char tempChar; 10 | vectorresult; 11 | stringstream inputStream(str); 12 | while(inputStream){ 13 | inputStream>>tempInt; 14 | if(inputStream) 15 | inputStream>>tempChar; 16 | result.push_back(tempInt); 17 | } 18 | return result; 19 | } 20 | 21 | int main() { 22 | string str; 23 | cin >> str; 24 | vector integers = parseInts(str); 25 | for(int i = 0; i < integers.size(); i++) { 26 | cout << integers[i] << "\n"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Maths/Handshake.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | /* 6 | * Complete the handshake function below. 7 | */ 8 | int handshake(int n) { 9 | /* 10 | * Write your code here. 11 | */ 12 | return (n*(n-1))/2; 13 | } 14 | 15 | int main() 16 | { 17 | ofstream fout(getenv("OUTPUT_PATH")); 18 | 19 | int t; 20 | cin >> t; 21 | cin.ignore(numeric_limits::max(), '\n'); 22 | 23 | for (int t_itr = 0; t_itr < t; t_itr++) { 24 | int n; 25 | cin >> n; 26 | cin.ignore(numeric_limits::max(), '\n'); 27 | 28 | int result = handshake(n); 29 | 30 | fout << result << "\n"; 31 | } 32 | 33 | fout.close(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /C++/Inheritance Introduction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | class Triangle{ 10 | public: 11 | void triangle(){ 12 | cout<<"I am a triangle\n"; 13 | } 14 | }; 15 | 16 | class Isosceles : public Triangle{ 17 | public: 18 | void isosceles(){ 19 | cout<<"I am an isosceles triangle\n"; 20 | } 21 | //Write your code here. 22 | void description(void){ 23 | cout <<"In an isosceles triangle two sides are equal\n"; 24 | } 25 | }; 26 | 27 | int main(){ 28 | Isosceles isc; 29 | isc.isosceles(); 30 | isc.description(); 31 | isc.triangle(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Maths/Maximum Draws.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | /* 6 | * Complete the maximumDraws function below. 7 | */ 8 | int maximumDraws(int n) { 9 | /* 10 | * Write your code here. 11 | */ 12 | return n+1; 13 | } 14 | 15 | int main() 16 | { 17 | ofstream fout(getenv("OUTPUT_PATH")); 18 | 19 | int t; 20 | cin >> t; 21 | cin.ignore(numeric_limits::max(), '\n'); 22 | 23 | for (int t_itr = 0; t_itr < t; t_itr++) { 24 | int n; 25 | cin >> n; 26 | cin.ignore(numeric_limits::max(), '\n'); 27 | 28 | int result = maximumDraws(n); 29 | 30 | fout << result << "\n"; 31 | } 32 | 33 | fout.close(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 1: Standard Deviation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int int64_t 4 | 5 | signed main(void){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | cout.tie(nullptr); 9 | #ifdef HELL_JUDGE 10 | freopen("input","r",stdin); 11 | freopen("output","w",stdout); 12 | #endif 13 | double n; cin >> n; 14 | vectorv(n); 15 | double mean{}; 16 | for(auto&itr:v){ 17 | cin >> itr; 18 | mean += itr; 19 | } 20 | mean = mean/n; 21 | double sd{}; 22 | for(auto&itr:v){ 23 | sd += ((itr-mean)*(itr-mean)); 24 | } 25 | sd /=n; 26 | cout << fixed << setprecision(1); 27 | cout << sqrt(sd) << '\n'; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Algorithms/Bit Manipulation/Maximizing Xor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // Complete the maximizingXor function below. 6 | int maximizingXor(int l, int r) { 7 | int p = l ^ r; 8 | int counter{}; 9 | while(p){ 10 | ++counter; 11 | p>>=1; 12 | } 13 | return pow(2,counter)-1; 14 | } 15 | 16 | int main() 17 | { 18 | ofstream fout(getenv("OUTPUT_PATH")); 19 | 20 | int l; 21 | cin >> l; 22 | cin.ignore(numeric_limits::max(), '\n'); 23 | 24 | int r; 25 | cin >> r; 26 | cin.ignore(numeric_limits::max(), '\n'); 27 | 28 | int result = maximizingXor(l, r); 29 | 30 | fout << result << "\n"; 31 | 32 | fout.close(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Interview-Preparation-Kit/Miscellaneous/Flipping_bits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // Complete the flippingBits function below. 6 | long flippingBits(long n) { 7 | bitset<32>b(n); 8 | b.flip(); 9 | return (long)b.to_ulong(); 10 | } 11 | 12 | int main() 13 | { 14 | ofstream fout(getenv("OUTPUT_PATH")); 15 | 16 | int q; 17 | cin >> q; 18 | cin.ignore(numeric_limits::max(), '\n'); 19 | 20 | for (int q_itr = 0; q_itr < q; q_itr++) { 21 | long n; 22 | cin >> n; 23 | cin.ignore(numeric_limits::max(), '\n'); 24 | 25 | long result = flippingBits(n); 26 | 27 | fout << result << "\n"; 28 | } 29 | 30 | fout.close(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Maths/number-group.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | using namespace std; 22 | #define MOD 1000000007 23 | 24 | int main(void){ 25 | #ifdef HELL_JUDGE 26 | freopen("input","r",stdin); 27 | freopen("output","w",stdout); 28 | freopen("error","w",stderr); 29 | #endif 30 | long long k; scanf("%lld",&k); 31 | printf("%lld",k*k*k); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /30 Days of Code/Day-16.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | 28 | int main(){ 29 | string S; 30 | cin >> S; 31 | try{ 32 | int x = stoi(S); 33 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Triangle{ 9 | public: 10 | void triangle(){ 11 | cout<<"I am a triangle\n"; 12 | } 13 | }; 14 | 15 | class Isosceles : public Triangle{ 16 | public: 17 | void isosceles(){ 18 | cout<<"I am an isosceles triangle\n"; 19 | } 20 | }; 21 | 22 | //Write your code here. 23 | class Equilateral : public Isosceles{ 24 | public: 25 | void equilateral(void){ 26 | cout << "I am an equilateral triangle\n"; 27 | } 28 | }; 29 | int main(){ 30 | 31 | Equilateral eqr; 32 | eqr.equilateral(); 33 | eqr.isosceles(); 34 | eqr.triangle(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /C++/Maps-STL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main() { 12 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 13 | int q; cin >> q; 14 | mapf; 15 | while(q--){ 16 | int a,b; string c; 17 | cin >> a >> c; 18 | switch(a){ 19 | case 1: 20 | cin >> b; 21 | f[c]+=b; 22 | break; 23 | case 2: 24 | f[c]=0; 25 | break; 26 | case 3: 27 | cout << f[c] << '\n'; 28 | break; 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Interview-Preparation-Kit/Linked_Lists/Detect a Cycle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Detect a cycle in a linked list. Note that the head pointer may be 'NULL' if the list is empty. 3 | 4 | A Node is defined as: 5 | struct Node { 6 | int data; 7 | struct Node* next; 8 | } 9 | */ 10 | 11 | bool has_cycle(Node* head) { 12 | // Complete this function 13 | // Do not write the main method 14 | Node*fast = head; 15 | Node*slow = head; 16 | while(fast != NULL){ 17 | if(fast -> next != NULL){ 18 | fast = fast -> next; 19 | slow = slow -> next; 20 | } 21 | if(fast -> next != NULL) { 22 | fast = fast -> next; 23 | } 24 | if(slow == fast) { 25 | return true; 26 | } 27 | } 28 | return false; 29 | } 30 | -------------------------------------------------------------------------------- /30 Days of Code/Day-02.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | // Complete the solve function below. 7 | void solve(double meal_cost, int tip_percent, int tax_percent) { 8 | cout<> meal_cost; 15 | cin.ignore(numeric_limits::max(), '\n'); 16 | 17 | int tip_percent; 18 | cin >> tip_percent; 19 | cin.ignore(numeric_limits::max(), '\n'); 20 | 21 | int tax_percent; 22 | cin >> tax_percent; 23 | cin.ignore(numeric_limits::max(), '\n'); 24 | 25 | solve(meal_cost, tip_percent, tax_percent); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Interview-Preparation-Kit/String Manipulation/Strings: Making Anagrams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // Complete the makeAnagram function below. 6 | int makeAnagram(string a, string b) { 7 | mapA,B; 8 | for(auto&itr:a){ 9 | A[itr]++; 10 | } 11 | for(auto&itr:b){ 12 | B[itr]++; 13 | } 14 | int counter{}; 15 | for(int i=0;i<26;++i){ 16 | counter+=abs(A[i+'a']-B[i+'a']); 17 | } 18 | return counter; 19 | } 20 | 21 | int main() 22 | { 23 | ofstream fout(getenv("OUTPUT_PATH")); 24 | 25 | string a; 26 | getline(cin, a); 27 | 28 | string b; 29 | getline(cin, b); 30 | 31 | int res = makeAnagram(a, b); 32 | 33 | fout << res << "\n"; 34 | 35 | fout.close(); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /C++/conditional-statements.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | 8 | int main() 9 | { 10 | int n; 11 | cin >> n; 12 | cin.ignore(numeric_limits::max(), '\n'); 13 | 14 | // Write Your Code Here 15 | if(n==1){ 16 | cout<<"one"; 17 | }else if(n==2){ 18 | cout<<"two"; 19 | }else if(n==3){ 20 | cout<<"three"; 21 | }else if(n==4){ 22 | cout<<"four"; 23 | }else if(n==5){ 24 | cout<<"five"; 25 | }else if(n==6){ 26 | cout<<"six"; 27 | }else if(n==7){ 28 | cout<<"seven"; 29 | }else if(n==8){ 30 | cout<<"eight"; 31 | }else if(n==9){ 32 | cout<<"nine"; 33 | }else{ 34 | cout<<"Greater than 9"; 35 | } 36 | cout< 2 | 3 | using namespace std; 4 | 5 | // Complete the powerSum function below. 6 | int powerSum(int X, int N , int num = 1) { 7 | int pw = pow(num,N); 8 | if(pw< X){ 9 | return powerSum(X , N , num+1) + powerSum(X-pw, N , num+1); 10 | }else if(pw == X){ 11 | return 1; 12 | }else{ 13 | return 0; 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | ofstream fout(getenv("OUTPUT_PATH")); 20 | 21 | int X; 22 | cin >> X; 23 | cin.ignore(numeric_limits::max(), '\n'); 24 | 25 | int N; 26 | cin >> N; 27 | cin.ignore(numeric_limits::max(), '\n'); 28 | 29 | int result = powerSum(X, N); 30 | 31 | fout << result << "\n"; 32 | 33 | fout.close(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Python/Text Alignment.py: -------------------------------------------------------------------------------- 1 | #Replace all ______ with rjust, ljust or center. 2 | 3 | thickness = int(input()) #This must be an odd number 4 | c = 'H' 5 | 6 | #Top Cone 7 | for i in range(thickness): 8 | print((c*i).rjust(thickness-1)+c+(c*i).ljust(thickness-1)) 9 | 10 | #Top Pillars 11 | for i in range(thickness+1): 12 | print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) 13 | 14 | #Middle Belt 15 | for i in range((thickness+1)//2): 16 | print((c*thickness*5).center(thickness*6)) 17 | 18 | #Bottom Pillars 19 | for i in range(thickness+1): 20 | print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) 21 | 22 | #Bottom Cone 23 | for i in range(thickness): 24 | print(((c*(thickness-i-1)).rjust(thickness)+c+(c*(thickness-i-1)).ljust(thickness)).rjust(thickness*6)) 25 | -------------------------------------------------------------------------------- /Maths/Summing N Series.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | /* 6 | * Complete the summingSeries function below. 7 | */ 8 | int summingSeries(long n) { 9 | /* 10 | * Write your code here 11 | */ 12 | const int mod = 1e9+7; 13 | n %=mod; 14 | return ((n*n)%mod+mod)%mod; 15 | 16 | } 17 | 18 | int main() 19 | { 20 | ofstream fout(getenv("OUTPUT_PATH")); 21 | 22 | int t; 23 | cin >> t; 24 | cin.ignore(numeric_limits::max(), '\n'); 25 | 26 | for (int t_itr = 0; t_itr < t; t_itr++) { 27 | long n; 28 | cin >> n; 29 | cin.ignore(numeric_limits::max(), '\n'); 30 | 31 | int result = summingSeries(n); 32 | 33 | fout << result << "\n"; 34 | } 35 | 36 | fout.close(); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/Sam and substrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int int64_t 4 | int mod = (int)1e9+7; 5 | int Int(char c) { 6 | return c-'0'; 7 | } 8 | signed main(void){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(nullptr); 11 | cout.tie(nullptr); 12 | #ifdef HELL_JUDGE 13 | freopen("input","r",stdin); 14 | freopen("output","w",stdout); 15 | #endif 16 | string s; cin >> s; 17 | vectordp(s.length()+100); 18 | dp[0] = Int(s[0]); 19 | for(int i=1; i 2 | 3 | using namespace std; 4 | 5 | // Complete the primality function below. 6 | string primality(int n) { 7 | for(auto i=2;i<=sqrt(n);++i) 8 | if(n%i==0) 9 | return "Not prime"; 10 | return (n==1)?"Not prime":"Prime"; 11 | } 12 | 13 | int main() 14 | { 15 | ofstream fout(getenv("OUTPUT_PATH")); 16 | 17 | int p; 18 | cin >> p; 19 | cin.ignore(numeric_limits::max(), '\n'); 20 | 21 | for (int p_itr = 0; p_itr < p; p_itr++) { 22 | int n; 23 | cin >> n; 24 | cin.ignore(numeric_limits::max(), '\n'); 25 | 26 | string result = primality(n); 27 | 28 | fout << result << "\n"; 29 | } 30 | 31 | fout.close(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C++/Preprocessor Solution.cpp: -------------------------------------------------------------------------------- 1 | /* Enter your macros here */ 2 | #define INF 100000000 3 | #define toStr(a) #a 4 | #define io(a) cin>>a 5 | #define foreach(a,b) for(int b=0; b 9 | #include 10 | using namespace std; 11 | 12 | #if !defined toStr || !defined io || !defined FUNCTION || !defined INF 13 | #error Missing preprocessor definitions 14 | #endif 15 | 16 | FUNCTION(minimum, <) 17 | FUNCTION(maximum, >) 18 | 19 | int main(){ 20 | int n; cin >> n; 21 | vector v(n); 22 | foreach(v, i) { 23 | io(v)[i]; 24 | } 25 | int mn = INF; 26 | int mx = -INF; 27 | foreach(v, i) { 28 | minimum(mn, v[i]); 29 | maximum(mx, v[i]); 30 | } 31 | int ans = mx - mn; 32 | cout << toStr(Result =) <<' '<< ans; 33 | return 0; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Maths/Connecting Towns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | const long long prime = 1234567ll; 20 | int main(void){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(nullptr); 23 | cout.tie(nullptr); 24 | int t; cin>>t; 25 | while(t--){ 26 | int n; cin>>n;n--; 27 | long long ans = 1ll; 28 | while(n--){ 29 | int x; cin>>x; 30 | ans = (ans * x)%prime; 31 | } 32 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | int gcd(int a,int b){ 20 | if(b==0){ 21 | return a; 22 | }else{ 23 | return gcd(b,a%b); 24 | } 25 | } 26 | int main(void){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(nullptr); 29 | cout.tie(nullptr); 30 | int t;cin>>t;while(t--){ 31 | int l , b; cin>>l>>b; 32 | // cout<<(l/gcd(l,b))*((b/gcd(l,b)))<