Skip to content

Instantly share code, notes, and snippets.

View Irene-123's full-sized avatar
🎯
Focusing

kirti purohit Irene-123

🎯
Focusing
View GitHub Profile
@Irene-123
Irene-123 / Josephus.cpp
Created July 21, 2020 15:05
THe Josephus Problem in C++
/* THE FOLLOWING CODE HAS BEEN COMPILED IN DOS TURBO C++
*/
#include<iostream.h>
#include<conio.h>
int highestPowerof2(int n)
{
int res = 0;
@Irene-123
Irene-123 / Monotone Increasing Digits.py
Created August 10, 2020 04:08
Monotone Increasing Digits
class Solution:
def monotoneIncreasingDigits(self, N: int) -> int:
n=N
if n==10:
return 9
if n<10:
return n
arr=[int(i) for i in str(n)]
for i in range (len(arr)-1):
if arr[i]>arr[i+1]:
@Irene-123
Irene-123 / word_pattern.py
Created August 13, 2020 02:45
Word Pattern-LeetCode Python Solution
#Method1 :
class Solution:
def wordPattern(self, pattern: str, str: str) -> bool:
map_words={}
map_chars={}
words=str.split(' ')
if len(words)!=len(pattern):
return False
for c,w in zip(pattern,words):
@Irene-123
Irene-123 / QueueReconstructionbyHeight.py
Created August 14, 2020 03:50
406. Queue Reconstruction by Height LeetCode Python Solution
class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
people=sorted(people, key=lambda x: (-x[0],x[1]))
res=[]
for p in people:
@Irene-123
Irene-123 / Teacher's quiz.py
Created September 27, 2020 09:42
Automate the boring stuff -generate random quiz project
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':
@Irene-123
Irene-123 / coinGuessing.py
Created October 1, 2020 14:09
Guess the coin Project-Automate the boring stuff
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:
@Irene-123
Irene-123 / hulk.py
Created November 7, 2020 03:00
Codeforces- 705A Hulk problem
# 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'
@Irene-123
Irene-123 / car_fueling.py
Created November 27, 2020 04:26
The car Fueling problem
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
@Irene-123
Irene-123 / sudan.py
Last active December 6, 2020 10:07
Sudan Neighbouring countries
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])
@Irene-123
Irene-123 / day12.py
Created December 21, 2020 12:48
Advent of Code Day-12 part 1
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]