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

rsreevishal - Completed #60

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7df19af
completed day 1
rsreevishal Dec 1, 2019
314afc7
first merge
rsreevishal Dec 4, 2019
b85cbb0
Merge remote-tracking branch 'upstream/master'
rsreevishal Dec 7, 2019
842b87c
finished till day 6
rsreevishal Dec 7, 2019
2bdccc1
completed day2
rsreevishal Dec 7, 2019
106a903
Delete d2.py
rsreevishal Dec 7, 2019
4940126
finished till day6
rsreevishal Dec 7, 2019
1351b75
Merge branch 'master' of https://github.com/rsreevishal/A-December-of…
rsreevishal Dec 7, 2019
708f8e8
finished till day 8
rsreevishal Dec 8, 2019
7458619
completed day9
rsreevishal Dec 9, 2019
12eee9c
completed till day11
rsreevishal Dec 10, 2019
ea0be52
completed till day11
rsreevishal Dec 10, 2019
5856762
merged the updates
rsreevishal Dec 14, 2019
34b823a
Merge remote-tracking branch 'upstream/master'
rsreevishal Dec 18, 2019
963f93e
completed till d16
rsreevishal Dec 21, 2019
f912500
Merge remote-tracking branch 'upstream/master'
rsreevishal Dec 22, 2019
6f4eb21
in progress
rsreevishal Dec 22, 2019
6acfffe
Merge remote-tracking branch 'upstream/master'
rsreevishal Dec 27, 2019
fd96b19
updated
rsreevishal Dec 27, 2019
4d05305
Merge remote-tracking branch 'upstream/master'
rsreevishal Dec 29, 2019
f4e2b31
Merge remote-tracking branch 'upstream/master'
rsreevishal Dec 30, 2019
b408a71
All done
rsreevishal Dec 31, 2019
68c85a8
all done
rsreevishal Dec 31, 2019
5b962cc
Delete JaSON.json
mahavisvanathan Jan 13, 2020
005d78c
Delete example.html
mahavisvanathan Jan 13, 2020
bfad0d2
Delete d11.html
mahavisvanathan Jan 13, 2020
6cae46a
Delete data.csv
mahavisvanathan Jan 13, 2020
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
18 changes: 18 additions & 0 deletions December-01/d1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def sevenis(n):
arr = []
i = 0
while(n > len(arr)):
tmp = pow(7,i)
arr.append(tmp)
for j in range(len(arr)-1):
arr.append(arr[j]+tmp)
if(len(arr) > n):
break
i += 1
return arr[n-1]

n = int(input())

print(sevenis(n))


21 changes: 21 additions & 0 deletions December-02/d2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def check(num):
s1 = 0
s2 = 0
for i in range(len(num)):
if(i%2 == 0):
s1 += int(num[i])
else:
tmp = int(num[i]) * 2
while (tmp > 9):
tmp -= 9
s2 += tmp
tot = s1 + s2
if( tot % 10 == 0):
print(num + " passes the test")
else:
print(num + " failed the test")


inp = input()

check(inp)
24 changes: 24 additions & 0 deletions December-03/d3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import math
def snap(arr,n):
if(len(arr) == 1):
return arr
elif(sorted(arr) == arr):
return arr
flag = count = 1
limit = math.ceil(n/2)
tmp = [arr[0]]
for i in range(1,len(arr)):
if(tmp[-1] < arr[i]):
tmp.append(arr[i])
count += 1
if(count == limit):
return tmp
flag = 0
if(flag == 1):
return arr[0:1]
else:
snap(arr[0:limit],limit)

n = int(input('Enter the size:'))
arr = [int(i) for i in input().split()]
print(snap(arr,n))
15 changes: 15 additions & 0 deletions December-04/d4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def h_index(n,arr):
arr.sort()
max = -1
for i in range(len(arr)):
if(len(arr) - i == arr[i]):
if(arr[i] > max):
max = arr[i]
return max



n = int(input('Enter # of papers:'))
arr = [int(e) for e in input().split()]

print(h_index(n,arr))
29 changes: 29 additions & 0 deletions December-05/d5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
file1 = open('../src/res/csv_to_html_res.csv','r')
file2 = open('example.html','a')
open('example.html', 'w').close()
openTag = "<html>\n^<body>\n^^<table>\n"
closeTag = "^^^</table>\n^^</body>\n</html>\n"
result = ""
result += openTag
flag = 0
for line in file1:
values = line.split(',')
tmp = ""
if(flag == 0):
for e in values:
e = e.replace('\n','')
tmp += "<th>{}</th>".format(e)
flag = 1
else:
for e in values:
e = e.replace('\n','')
tmp += "<td>{}</td>".format(e)
tr = "^^^^<tr>{}</tr>\n".format(tmp)
result += tr
result += closeTag
file2.write(result.replace('^',' '))
file1.close()
file2.close()



43 changes: 43 additions & 0 deletions December-06/d6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import math

def isSquare(n):
rt = int(math.sqrt(n))
return rt*rt == n

def isFib(n):
return isSquare(5*n*n + 4) or isSquare(5*n*n - 4)

def generate(m):
if(m>9):
print('This leads to memory error')
return
primes = [True for i in range(10**7)]
primes[0] = primes[1] = False
n = len(primes)
count = 0
for i in range(2,n):
if(primes[i]):
if(isFib(i)):
print(i)
count += 1
if(count == m):
return
ind = 2
tmp = i*ind
while(tmp < n):
primes[tmp] = False
ind += 1
tmp = i*ind





n = int(input("Enter a number between 1-9:"))
generate(n)






50 changes: 50 additions & 0 deletions December-07/d7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>
#include<queue>

using namespace std;

class Person {
public:
int no;
char id;
void get() {
cout<<"\nEnter the token number & id:"<<endl;
cin>>no>>id;
}
void print() {
cout<<"\n("<<no<<","<<id<<")"<<endl;
}
};

int main() {
int n;
cout<<"\nEnter the # of patients:";
cin>>n;
queue<Person> ppl,tmp;
for(int i = 0; i < n; i++) {
Person tmp;
tmp.get();
ppl.push(tmp);
}
char k;
cout<<"\nEnter the id of k:";
cin>>k;
while(!ppl.empty()) {
Person top = ppl.front();
if(top.id == k) {
ppl.pop();
top.print();
while(!tmp.empty()) {
tmp.front().print();
tmp.pop();
}
} else {
tmp.push(top);
ppl.pop();
}
}
while(!tmp.empty()) {
tmp.front().print();
tmp.pop();
}
}
59 changes: 59 additions & 0 deletions December-08/d8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
def hasFront(arr,r,c,i,j):
if(i-1 >= 0):
return arr[i-1][j] == arr[i][j]
return False

def hasBack(arr,r,c,i,j):
if(i+1 < r):
return arr[i+1][j] == arr[i][j]
return False

def hasLR(arr,r,c,i,j):
if(j+1 < c):
if(arr[i][j+1] == arr[i][j]):
return True
if(j-1 >= 0):
if(arr[i][j-1] == arr[i][j]):
return True
return False

def hasDiagonal(arr,r,c,i,j):
if(i-1 >=0 and j-1 >=0):
if(arr[i-1][j-1] == arr[i][j]):
return True
if(i+1 < r and j+1 < c):
if(arr[i+1][j+1] == arr[i][j]):
return True
if(i-1 >=0 and j+1 < c):
if(arr[i-1][j+1] == arr[i][j]):
return True
if(i+1 < r and j-1 >= 0):
if(arr[i+1][j-1] == arr[i][j]):
return True
return False


r = int(input('Enter # of rows:'))
c = int(input('Enter # of columns:'))
print('-Enter the student arrangement-')
arr = []
for _ in range(r):
arr.append([e for e in input().split()])

result = []
for _ in range(r):
result.append([0.0 for i in range(c)])

for i in range(r):
for j in range(c):
if(hasFront(arr,r,c,i,j)):
result[i][j] += 0.3
if(hasBack(arr,r,c,i,j)):
result[i][j] += 0.2
if(hasLR(arr,r,c,i,j)):
result[i][j] += 0.2
if(hasDiagonal(arr,r,c,i,j)):
result[i][j] += 0.025

for e in result:
print(e)
21 changes: 21 additions & 0 deletions December-09/d9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def get(setn,no):
print('Enter the elements in set {}'.format(no))
setn.update([int(e) for e in input().split()])

def check(set1,set2,function):
set3 = set()
func = function.replace('x','{}')
func = func.replace('^','**')
for e in set1:
set3.add(int(eval(func.format(e))))
if(len(set1) == len(set3) and set3.issubset(set2)):
print('It is one-to-one function')
else:
print('It is not one-to-one function')

set1 = set()
set2 = set()
get(set1,1)
get(set2,2)
function = input('Enter the function use \'x\' as placeholder:')
check(set1,set2,function)
29 changes: 29 additions & 0 deletions December-10/d10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<iostream>
using namespace std;

int cookie_count(int n,int p,int c) {
int cookies = 0,freeCookies = 0,remaining = 0;
cookies += n/p;
freeCookies = cookies/c;
remaining = cookies%c;
do {
cookies += freeCookies;
int tmp = freeCookies;
freeCookies /= c;
remaining += tmp%c;
} while(freeCookies > 0);
cookies += remaining / c;
return cookies;
}

int main() {
int n,p,c;
cout<<"\nEnter the total cost:";
cin>>n;
cout<<"\nEnter the cost of a cookie:";
cin>>p;
cout<<"\nEnter # of jar required for a cookie:";
cin>>c;
cout<<endl<<cookie_count(n,p,c);
return 0;
}
32 changes: 32 additions & 0 deletions December-11/d11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def check(email):
if('@' not in email):
print('@ is required')
return
elif(email.count('@') > 1):
print('@ is used more than once')
return
else:
alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
number = "1234567890"
chars = "._-"
parts = email.split('@')
name = parts[0]
domain = parts[1]
for e in name:
if(e not in alpha and e not in number and e not in chars):
print('Invalid characters')
return
for e in domain:
if(e not in alpha and e != '.'):
print('Invalid domain')
return
if(domain[-1:-5:-1] != "moc."):
print('.com is required')
return
if(len(domain) < 5):
print('domain is required')
return
print('Email is valid')

email = input('Enter the email:')
check(email)
39 changes: 39 additions & 0 deletions December-12/d12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import math

def degreesToRadians(degrees):
return degrees * math.pi / 180

def distance(lat1, lon1, lat2, lon2):
earthRadiusKm = 6371
dLat = degreesToRadians(lat2-lat1)
dLon = degreesToRadians(lon2-lon1)
lat1 = degreesToRadians(lat1)
lat2 = degreesToRadians(lat2)
a = math.sin(dLat/2) * math.sin(dLat/2) + math.sin(dLon/2) * math.sin(dLon/2) * math.cos(lat1) * math.cos(lat2);
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
return earthRadiusKm * c

JaSON = open('./src/res/JaSON.json','r')
parsed = json.loads(JaSON.read())

result = {
'directions':[
{
'message':'',
'distance':0,
'direction':'N'
}
]
}
markers = parsed['markers']
start = markers[0]['location']
destination = markers[1]['location']

result['directions'][0]['distance'] = distance(start[0],start[1],destination[0],destination[1])
result['directions'][0]['message'] = input('Enter some message:')
result['directions'][0]['direction'] = input('Enter the direction(N,S,W,E):')

print( json.dumps(result,indent = 4) )

JaSON.close()
Loading