Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions sohan-k Code Gym/counting_sundays.py
Original file line number Diff line number Diff line change
@@ -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)
179 changes: 179 additions & 0 deletions sohan-k Code Gym/palindrom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
//Important 1381114114111831

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

#include <string>
#include <sstream>

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<int> 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"<<endl;
cout<<"iesjf"<<endl;
cout<<"starting......"<<endl;
string i = "138111149";
string prime = "10000019";
string ans;
int counter = 0;

while( i != "10000000000000000000000000" ){
ans = multiply(i, prime);
if(isPalindrome(ans)){
cout<<ans<<endl;
counter++;
}
i = findSum("1",i);
}
cout<<endl<<"Total freaking palindroms are "<<counter<<endl;

return 0;
}