Skip to content

Commit 7b8bdac

Browse files
authored
Merge pull request #1 from devcoder007/CODER-001
CODER-001 Uploaded some more problems
2 parents 2305a94 + 7679c06 commit 7b8bdac

File tree

11 files changed

+357
-19
lines changed

11 files changed

+357
-19
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

aa.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

compress_k_words.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# A function which will take two arguements, the string and number
2+
# of consecutive charecters to be compressed.
3+
def compressWord(word):
4+
#initializing a empty result string so that we can concatenate our resultant string.
5+
res = ""
6+
#initial value of i is 0 so that we can check the consecutiveness from starting.
7+
i = 0
8+
k=2
9+
while i < len(word):
10+
# it will run starting from the first element of string to the last element of string.
11+
if i < len(word) - (k-1) and [True for j in range(5,0,-1) if word[i]*(k+j) == word[i:i+k+j]]:
12+
#if stmt i <len(word) - (k-1) to prevent index out of range error.
13+
#and word[i]*k == word[i:i+k] will check whether we have k consecutive charecter
14+
#in string or not as word[i] ='c, word[i]*k ='ccc', word[i:i+k] = 'ccc', that means
15+
# we have k consecutive charecter. we will go for first recursion(it will work for i =3).
16+
i += k
17+
# if k consecutive charecter found then we will skip the i value upto k that is 3
18+
else:
19+
#if not then that means no need to compress, so we will concatenate that charecter
20+
#with our res variable
21+
res += word[i]
22+
#increment the i value to +1 to so that we can move to next charecter
23+
i += 1
24+
25+
26+
if len(res) == len(word):
27+
# if both strings have same length that means we have compressed succesfully
28+
#return the resulting string
29+
return res
30+
else:
31+
# recurssion (if the word again consist of group of k consecutive characters)
32+
return compressWord(res)
33+
34+
35+
word ="abbbbbcc"
36+
37+
c=compressWord(word)
38+
print(c)

customer_island.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
l=[1, 2, 3, 4, 5, 6, 7, 8]
2+
l1=[(1,2), (3,4), (6,5), (6,7), (2,8)]
3+
tt=[]
4+
count=0
5+
for i in l1:
6+
if i[0] in tt or i[1] in tt:
7+
continue
8+
else:
9+
if i[0] not in tt:
10+
tt.append(i[0])
11+
if i[1] not in tt:
12+
tt.append(i[1])
13+
count = count+1
14+
print(count)

email_scrap.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# from bs4 import BeautifulSoup
2+
# import requests
3+
# import requests.exceptions
4+
# from urllib.parse import urlsplit
5+
# from collections import deque
6+
# import re
7+
8+
# # a queue of urls to be crawled
9+
# new_urls = deque(['https://mail.google.com/mail/u/1/#inbox'])
10+
11+
# # a set of urls that we have already crawled
12+
# processed_urls = set()
13+
14+
# # a set of crawled emails
15+
# emails = set()
16+
17+
# # process urls one by one until we exhaust the queue
18+
# while len(new_urls):
19+
20+
# # move next url from the queue to the set of processed urls
21+
# url = new_urls.popleft()
22+
# processed_urls.add(url)
23+
24+
# # extract base url to resolve relative links
25+
# parts = urlsplit(url)
26+
# base_url = "{0.scheme}://{0.netloc}".format(parts)
27+
# path = url[:url.rfind('/')+1] if '/' in parts.path else url
28+
29+
# # get url's content
30+
# print("Processing %s" % url)
31+
# try:
32+
# response = requests.get(url)
33+
# except (requests.exceptions.MissingSchema, requests.exceptions.ConnectionError):
34+
# # ignore pages with errors
35+
# continue
36+
37+
# # extract all email addresses and add them into the resulting set
38+
# new_emails = set(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I))
39+
# emails.update(new_emails)
40+
41+
# # create a beutiful soup for the html document
42+
# soup = BeautifulSoup(response.text)
43+
44+
# # find and process all the anchors in the document
45+
# for anchor in soup.find_all("a"):
46+
# # extract link url from the anchor
47+
# link = anchor.attrs["href"] if "href" in anchor.attrs else ''
48+
# # resolve relative links
49+
# if link.startswith('/'):
50+
# link = base_url + link
51+
# elif not link.startswith('http'):
52+
# link = path + link
53+
# # add the new url to the queue if it was not enqueued nor processed yet
54+
# if not link in new_urls and not link in processed_urls:
55+
# new_urls.append(link)
56+
57+
import imaplib
58+
import email
59+
from email.header import decode_header
60+
import HTMLParser
61+
62+
63+
# to unescape xml entities
64+
_parser = HTMLParser.HTMLParser()
65+
66+
def decodeHeader(value):
67+
if value.startswith('"=?'):
68+
value = value.replace('"', '')
69+
70+
value, encoding = decode_header(value)[0]
71+
if encoding:
72+
value = value.decode(encoding)
73+
74+
return _parser.unescape(value)
75+
76+
def listLastInbox(top = 10):
77+
mailbox = imaplib.IMAP4_SSL('imap.gmail.com')
78+
mailbox.login('[email protected]', 'Rish@1996')
79+
80+
selected = mailbox.select('INBOX')
81+
assert selected[0] == 'OK'
82+
messageCount = int(selected[1][0])
83+
84+
for i in range(messageCount, messageCount - top, -1):
85+
reponse = mailbox.fetch(str(i), '(RFC822)')[1]
86+
for part in reponse:
87+
if isinstance(part, tuple):
88+
message = email.message_from_string(part[1])
89+
# for h in ('subject','from','date'):
90+
# if "Firebase" in decodeHeader(message['from']):
91+
# print(decodeHeader(message['from']))
92+
yield {h: decodeHeader(message[h]) for h in ('subject', 'from', 'date') if "Firebase" in decodeHeader(message['from']) }
93+
94+
mailbox.logout()
95+
96+
97+
if __name__ == '__main__':
98+
for message in listLastInbox():
99+
print ('-' * 40)
100+
for h, v in message.items():
101+
print (u'{0:8s}: {1}'.format(h.upper(), v))
102+
103+
104+
105+
106+
107+
108+
# def scramble(s1, s2):
109+
# # your code here
110+
# # print(list(s1),list(s2))
111+
# l = len(s2)
112+
# s1 = list(s1)
113+
# s2 = list(s2)
114+
# count = 0
115+
# for i in s2:
116+
# if i in s1:
117+
# count = count+1
118+
# # print(list(s1))
119+
# s1.remove(i)
120+
# # print(list(s1))
121+
# # if count == l:
122+
# # return True
123+
# # else:
124+
# # return False
125+
# print(count,l,len(s1))
126+
127+
# scramble('scriptjava','javascript')

fizzbuzz.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# def fizzbuzz(n):
2+
3+
# if n % 3 == 0 and n % 5 == 0:
4+
# return 'FizzBuzz'
5+
# elif n % 3 == 0:
6+
# return 'Fizz'
7+
# elif n % 5 == 0:
8+
# return 'Buzz'
9+
# else:
10+
# return str(n)
11+
12+
# print("\n".join(fizzbuzz(n) for n in range(1, 21)))
13+
14+
# Recursive FizzBuzz
15+
def fizzbuzz_recursive(n):
16+
if n == 0:
17+
return
18+
fizzbuzz_recursive(n - 1)
19+
if n % 3 == 0 and n % 5 == 0:
20+
print('FizzBuzz')
21+
elif n % 3 == 0:
22+
print('Fizz')
23+
elif n % 5 == 0:
24+
print('Buzz')
25+
else:
26+
print(n)
27+
n = [n for n in range(21)]
28+
fizzbuzz_recursive(n)

ideal_prime_factors.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import math
2+
def primeFactors(n):
3+
prime_factors = set()
4+
5+
6+
# Print the number of two's that divide n
7+
while n % 2 == 0:
8+
prime_factors.add(2)
9+
n = n / 2
10+
11+
# n must be odd at this point
12+
# so a skip of 2 ( i = i + 2) can be used
13+
for i in range(3,int(math.sqrt(n)),2):
14+
15+
# while i divides n , print i ad divide n
16+
while n % i== 0:
17+
prime_factors.add(i)
18+
n = n / i
19+
20+
# Condition if n is a prime
21+
# number greater than 2
22+
if n > 2:
23+
prime_factors.add(n)
24+
return prime_factors
25+
26+
def factor_of_three_and_five(first,last):
27+
#initializing value of count with 0 so that we can count ideal prime factors.
28+
count = 0
29+
# empty list for three and five div
30+
three_and_fives_div =[]
31+
#loop will run starting from the first arguement to last arguement
32+
for i in range(first,last+1):
33+
#it will check whether the i is a multiple of 3 or 5 or not.
34+
if (i%3==0) or (i%5==0):
35+
# if i is a multiple of 3 or 5 then pass it to the primeFactors function defined
36+
#above
37+
prime_factors = primeFactors(i)
38+
39+
# there are two primeFactors, so we will check whether we have two or less than
40+
# two
41+
if len(set(prime_factors)) <= 2:
42+
# check whether we have 1 prime factor
43+
if len(set(prime_factors)) == 1:
44+
# if yes than just increment the count variable
45+
if (3 in prime_factors) or (5 in prime_factors):
46+
count += 1
47+
# if not equal to 1 then check whether that set has these elemnts or not
48+
# but to check we have a sorted list that's why we are converting the
49+
# returned set sorted list and again increment count if yes
50+
elif (sorted(list(set(prime_factors))) == [3,5]):
51+
count +=1
52+
53+
54+
55+
56+
57+
# if 1 in range(first,last+1):
58+
# count += 1
59+
#just return value of count
60+
return count
61+
62+
63+
f = factor_of_three_and_five(200,405)
64+
print(f)
65+
66+
67+
68+
69+
70+
71+
72+
# string="aaabbccaaee"
73+
# lst=list(string)
74+
# #print(lst)
75+
# count=1
76+
# ls=[]
77+
# for i in range(len(lst)):
78+
# if i+1 == len(lst):
79+
# # print(lst[i]," ",count," ",i)
80+
# ls.append((lst[i],count))#dict[lst[i]]=count
81+
# if i+1 < len(lst):
82+
# if lst[i] == lst[i+1]:
83+
# count=count+1
84+
# #print(i,count,lst[i])
85+
# continue
86+
# else:
87+
# ls.append((lst[i],count))#dict[lst[i]]=count
88+
# count=1
89+
# #print(i,lst[i],count,ls)
90+
# continue
91+
# # print(ls)
92+
# for i in ls:
93+
# print(i[0],i[1],sep="",end="")

least_common.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from collections import Counter
2+
line = [4,4,4,1,1,1,1,1,1,1,2,3,4,5,6,-1,1,2]
3+
4+
5+
temp = Counter(line)
6+
# # print(temp.keys())
7+
# print(temp)
8+
9+
# t_l = [0]
10+
# ss = set(temp)
11+
# max = 0
12+
# for i in ss:
13+
# if temp[i]>max:
14+
# t_l.insert(0,i)
15+
# max = temp[i]
16+
# # print(max)
17+
18+
# print(t_l[0])
19+
# print(t_l)
20+
21+
print(temp)
22+
for k,v in temp:
23+
print(k,v)

nested_list_to_single.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import itertools
2+
a = [[1, 2], [3, 4], [5, 6]]
3+
print(list(itertools.chain.from_iterable(a)))

spiral_draw.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pyautogui, time
2+
time.sleep(5)
3+
pyautogui.click() # click to put drawing program in focus
4+
distance = 200
5+
while distance > 0:
6+
pyautogui.dragRel(distance, 0, duration=0.2) # move right
7+
distance = distance - 2.5
8+
pyautogui.dragRel(0, distance, duration=0.2) # move down
9+
pyautogui.dragRel(-distance, 0, duration=0.2) # move left
10+
distance = distance - 2.5
11+
pyautogui.dragRel(0, -distance, duration=0.2) # move up

0 commit comments

Comments
 (0)