From 89af2a2261fdf5d6f0e88f2573385dc988c65e34 Mon Sep 17 00:00:00 2001 From: sohan-k <45841802+sohan-k@users.noreply.github.com> Date: Sat, 16 Nov 2019 09:36:10 +0530 Subject: [PATCH] Add files via upload --- sohan-k Code Gym/counting_sundays.py | 39 ++++++ sohan-k Code Gym/palindrom.cpp | 179 +++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 sohan-k Code Gym/counting_sundays.py create mode 100644 sohan-k Code Gym/palindrom.cpp diff --git a/sohan-k Code Gym/counting_sundays.py b/sohan-k Code Gym/counting_sundays.py new file mode 100644 index 0000000..5ab98eb --- /dev/null +++ b/sohan-k Code Gym/counting_sundays.py @@ -0,0 +1,39 @@ + +months = [ 'jan', 'feb','mar','apr','may','jun','jul','agu','sep','oct','nov','dec', ] + +days = { + + 'jan' : 31, + 'feb' : 31, + 'mar' : 31, + 'apr' : 30, + 'may' : 31, + 'jun' : 30, + 'jul' : 31, + 'agu' : 31, + 'sep' : 30, + 'oct' : 31, + 'nov' : 30, + 'dec' : 31, +} + +sunday_count = 0 + +current_date = 6 # Sunday on 6th Jan 1901 + +for year in range(1901,2001): + if year%4 == 0: #leap year + days['feb'] = 29 + else: + days['feb'] = 28 + + for month in months : + while current_date <= days[month]: + current_date = current_date + 7 + current_date = current_date - days[month] + if current_date == 1: + sunday_count = sunday_count+1 + #print(f"date: {current_date}/{month}/{year}") + + +print(sunday_count) \ No newline at end of file diff --git a/sohan-k Code Gym/palindrom.cpp b/sohan-k Code Gym/palindrom.cpp new file mode 100644 index 0000000..37c7a69 --- /dev/null +++ b/sohan-k Code Gym/palindrom.cpp @@ -0,0 +1,179 @@ +//Important 1381114114111831 + +#include +#include +using namespace std; + +#include +#include + +namespace patch +{ + template < typename T > std::string to_string( const T& n ) + { + std::ostringstream stm ; + stm << n ; + return stm.str() ; + } +} + +string findSum(string str1, string str2) +{ + + // Take an empty string for storing result + string str = ""; + + // Calculate length of both string + int n1 = str1.length(), n2 = str2.length(); + int diff = n2 - n1; + + // Initially take carry zero + int carry = 0; + + // Traverse from end of both strings + for (int i=n1-1; i>=0; i--) + { + + int sum = ((str1[i]-'0') + + (str2[i+diff]-'0') + + carry); + str.push_back(sum%10 + '0'); + carry = sum/10; + } + + + for (int i=n2-n1-1; i>=0; i--) + { + int sum = ((str2[i]-'0')+carry); + str.push_back(sum%10 + '0'); + carry = sum/10; + } + + // Add remaining carry + if (carry) + str.push_back(carry+'0'); + + // reverse resultant string + reverse(str.begin(), str.end()); + return str; +} + +string multiply(string num1, string num2) +{ + int len1 = num1.size(); + int len2 = num2.size(); + if (len1 == 0 || len2 == 0) + return "0"; + + // will keep the result number in vector + // in reverse order + vector result(len1 + len2, 0); + + // Below two indexes are used to find positions + // in result. + int i_n1 = 0; + int i_n2 = 0; + + // Go from right to left in num1 + for (int i=len1-1; i>=0; i--) + { + int carry = 0; + int n1 = num1[i] - '0'; + + + i_n2 = 0; + + // Go from right to left in num2 + for (int j=len2-1; j>=0; j--) + { + // Take current digit of second number + int n2 = num2[j] - '0'; + + int sum = n1*n2 + result[i_n1 + i_n2] + carry; + + // Carry for next iteration + carry = sum/10; + + // Store result + result[i_n1 + i_n2] = sum % 10; + + i_n2++; + } + + // store carry in next cell + if (carry > 0) + result[i_n1 + i_n2] += carry; + + // To shift position to left after every + // multiplication of a digit in num1. + i_n1++; + } + + // ignore '0's from the right + int i = result.size() - 1; + while (i>=0 && result[i] == 0) + i--; + + // If all were '0's - means either both or + // one of num1 or num2 were '0' + if (i == -1) + return "0"; + + // generate the result string + string s = ""; + + while (i >= 0) + s += patch::to_string(result[i--]); + + /*delete(&len1); + delete(&len2); + delete(&i_n1); + delete(&i_n2); + delete(&i);*/ + + return s; +} + +int isPalindrome(string str) +{ + // Start from leftmost and rightmost corners of str + int l = 0; + int h = str.length() - 1; + + // Keep comparing characters while they are same + while (h > l) + { + if (str[l++] != str[h--]) + { + return 0; + } + } +/* delete(&h); + delete(&l);*/ + return 1; +} + +//100000000000000000000000000000000 +//10000000000000000000000000 +int main(){ + + cout<<"jhsr"<