This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil,os | |
def selectiveCopy(folder,extensions,destFolder): | |
folder=os.path.abspath(folder) | |
print(folder) | |
destFolder=os.path.abspath(destFolder) | |
print(destFolder) | |
print('Looking in '+ folder+ ' for files with extensions of ', ','.join(extensions)) | |
for foldername,subfolders,filenames in os.walk(folder): | |
print("***",foldername, "**", subfolders , "*",filenames) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!usr/bin/python3 | |
import re | |
file=open('mad.txt') | |
text=file.read() | |
file.close() | |
regex=re.compile(r'(NOUN) | (ADJECTIVE) | (VERB)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', 'Arizona': 'Phoenix', | |
'Arkansas': 'Little Rock', 'California': 'Sacramento', 'Colorado': 'Denver', | |
'Connecticut': 'Hartford', 'Delaware': 'Dover', 'Florida': 'Tallahassee', | |
'Georgia': 'Atlanta', 'Hawaii': 'Honolulu', 'Idaho': 'Boise', 'Illinois': | |
'Springfield', 'Indiana': 'Indianapolis', 'Iowa': 'Des Moines', 'Kansas': | |
'Topeka', 'Kentucky': 'Frankfort', 'Louisiana': 'Baton Rouge', 'Maine': | |
'Augusta', 'Maryland': 'Annapolis', 'Massachusetts': 'Boston', 'Michigan': | |
'Lansing', 'Minnesota': 'Saint Paul', 'Mississippi': 'Jackson', 'Missouri': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=magic(4); | |
fprintf('The original matrix is:\n'); | |
disp(a); | |
b=a.'; | |
fprintf('\n'); | |
fprintf('The transposed matrix is :\n'); | |
disp(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def rotate(origin, point, angle): | |
# source: https://stackoverflow.com/a/34374437 | |
ox, oy = origin | |
px, py = point | |
qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy) | |
qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy) | |
return int(round(qx)), int(round(qy)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("day12.txt", "r") as file: | |
lines = [(line.rstrip()[0], int(line.rstrip()[1:])) for line in file.readlines()] | |
dirs = ["E", "S", "W", "N", "L", "R", "F"] | |
curr_dir = "E" | |
curr_state = {"E":0, "W":0, "N":0, "S":0} | |
for line in lines: | |
if line[0] == "F": | |
curr_state[curr_dir] += line[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = dict(type = 'choropleth', | |
locations = ['Egypt','Eritrea','Ethiopia', | |
'Central African Republic','Chad','Libya', | |
'South Sudan','Sudan'], | |
locationmode = 'country names', | |
colorscale= 'Portland', | |
text= ['EG','ER','ET','CF','TD','LBY','SDN','SD'], | |
z=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0], | |
colorbar = {'title':'Country Colours', 'len':200,'lenmode':'pixels' }) | |
col_map = gobj.Figure(data = [data]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def car_fueling(dist,miles,n,gas_stations): | |
num_refill, curr_refill, limit = 0,0,miles | |
while limit < dist: | |
# While the destination cannot be reached with current fuel | |
if curr_refill >= n or gas_stations[curr_refill] > limit: | |
# Cannot reach the destination nor the next gas station | |
return -1 | |
# Find the furthest gas station we can reach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# KIRTI PUROHIT | |
# [email protected] | |
n=int(input()) | |
hate='' | |
for i in range(1,n): | |
if i%2==0: | |
hate+=' I love that' | |
else: | |
hate+=' I hate that' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
guess='' | |
while guess not in ('head','tail'): | |
print('Guess the coin Toss ! heads or tails ?!') | |
guess=input() | |
toss=random.randint(0,1) | |
if toss: | |
tt='head' | |
else: |