Skip to content

Instantly share code, notes, and snippets.

View Sustainability4's full-sized avatar
🤠
Bhai ! Bhai ! Bhai !

Rohan Sharma Sustainability4

🤠
Bhai ! Bhai ! Bhai !
View GitHub Profile
@Sustainability4
Sustainability4 / svd.py
Created September 17, 2021 05:12
SVD_1
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import time
from PIL import Image
# Converting the image to greyscale make it into a simpler matrix and easy to process
img = Image.open('panda.jpg')
img_gray = img.convert('LA')
#include <iostream>
using namespace std;
#include <cmath>
// Change in the given string itself. So no need to return or print the changed string.
void towerOfHanoi(int n, char source, char auxiliary, char destination) {
// Power of Recursion
if (n == 0){
return;
@Sustainability4
Sustainability4 / equal_recursion.cpp
Created April 13, 2021 05:50
recursively a new string where identical chars that are adjacent in the original string are separated from each other by a "*"
#include <iostream>
using namespace std;
#include <cmath>
// Change in the given string itself. So no need to return or print the changed string.
void pair(char input[], int size){
if (size < 2){
return;
}
@Sustainability4
Sustainability4 / string_to_integer_recursion.cpp
Created April 13, 2021 05:25
String to integers using recursion
#include <iostream>
using namespace std;
#include <cmath>
int number(char input[], int size){
if (size < 1){
return 0;
}
int sum = number(input+1, size-1);
int i = input[0];
@Sustainability4
Sustainability4 / removex_recursion.cpp
Created April 13, 2021 04:49
remove all occurrences of x from the string
#include <iostream>
using namespace std;
void remove(char input[], int size){
if (size < 1){
return;
}
if (input[0] == 'x'){
int i = 0;
for(i;i<=size;i++){
@Sustainability4
Sustainability4 / pi_3.14_recursion.cpp
Created April 13, 2021 04:36
recursively a new string where all appearances of "pi" have been replaced by "3.14".
#include <iostream>
using namespace std;
void replacestring(char input[], int size){
if (size < 2){
return;
}
if ( input[0] == 'p' && input[1] == 'i'){
int i = size;
for(i; i>=0; i--){
@Sustainability4
Sustainability4 / sumofdigits.cpp
Created April 11, 2021 12:30
Calculating the sum of digits using recursion
#include <iostream>
using namespace std;
int sumOfDigits(int n) {
// base case
if ( n == 0){
return 0;
}
// Recursive Call
int sum1 = sumOfDigits(n/10);
@Sustainability4
Sustainability4 / palindrome_recursion.cpp
Created April 11, 2021 12:30
Checking whether a string is a palindrome or not using recursion
#include <iostream>
using namespace std;
bool isPalin(char input[], int si , int ei){
// Base Case
if ( si >= ei ){
return true;
}
// Small Calculation
if (input[si] != input[ei]){
@Sustainability4
Sustainability4 / count_zeros_recursion.cpp
Created April 11, 2021 11:13
Counting number of zeros in an integer using recursion
#include <iostream>
using namespace std;
int countZeros(int n) {
// Base Case and Special case
if (n>0 && n<10){
return 0;
}
if (n == 0){
return 1;
@Sustainability4
Sustainability4 / array_indices_recursion.cpp
Created April 11, 2021 10:44
Getting index values of a number in an array
#include <iostream>
using namespace std;
int firstIndex(int input[], int size, int x) {
// Base case
if (size == 0){
return -1;
}
// Small Calculation
if (input[0]==x){