Skip to content

Instantly share code, notes, and snippets.

View harshildarji's full-sized avatar

Harshil harshildarji

View GitHub Profile
'''
The table below gives the age (in year) and mileage (in KMs) of four used cars:
WARTBURG MOSKVICH LADA TRABI
Age: 5 7 15 28
Mileage: 30530 90000 159899 270564
1. Determine the weights w0 and w1 for a simple linear regression to predict mileage from age.
2. Use the model from (1) to predict the mileage for a 15-year old car.
'''
@harshildarji
harshildarji / professor_boolean_workforce.py
Created December 10, 2018 19:00
Find the total number of people in Prof. Boolean's workforce.
'''
Professor Boolean is an evil villain who is up to no good.
It is your job to help bring her down. The is a gang working under her.
The chain of command of the gang is structured in such a way that each leader has 7 people working directly under him/her.
Your task is to find the total number of people in Prof. Boolean's workforce given the number of level of hierarchy.
'''
levels = int(input('Number of level(s): '))
peoples = 1
for i in range(levels):
peoples += (7 ** (i + 1))
@harshildarji
harshildarji / convert.py
Last active August 29, 2019 11:18
Convert GloVe to Gensim Word2Vec
# Usage: python convert.py glove_model.txt
import sys
import time
def file_len(fname):
line = col = 0
with open(fname, encoding = 'UTF-8') as f:
for line, l in enumerate(f):
if col == 0:
@harshildarji
harshildarji / q_learning_intro.py
Created August 29, 2019 11:12
Q-Learning Intro
# Tutorial links:
# https://youtu.be/yMk_XtIEzH8?list=PLQVvvaa0QuDezJFIOU5wDdfy4e9vdnx-7
# https://youtu.be/Gq1Azv_B4-4?list=PLQVvvaa0QuDezJFIOU5wDdfy4e9vdnx-7
# https://youtu.be/CBTbifYx6a8?list=PLQVvvaa0QuDezJFIOU5wDdfy4e9vdnx-7
import gym
import numpy as np
import matplotlib.pyplot as plt
env = gym.make('MountainCar-v0')
@harshildarji
harshildarji / generate_random_number.py
Created April 20, 2020 11:38
Generate Random Number
import random, time
def generate_random_number():
number = list(map(str, str(time.time()).replace('.', '')))
return int(''.join(random.sample(number, len(number))))
print(generate_random_number())
@harshildarji
harshildarji / word_chain.py
Created October 24, 2020 05:04
Word Chain Game
import random, json, requests, string, sys
def game():
chain = 0
usedWords = []
answer_Word = None
chainGood = True
min_length = 3
while chainGood:
# if chain != 0 and chain % 5 == 0: min_length += 1
# Video link: https://youtu.be/3P3TcKaegbA?list=PLxvWWIq3F0k0GE1EYvricLniNSdv9gvZS
import os
import time
from datetime import datetime
from github import Github
from curtsies.fmtfuncs import yellow
ACCESS_TOKEN = open('token', 'r').read()
g = Github(ACCESS_TOKEN)
@harshildarji
harshildarji / color_mastermind.py
Created May 21, 2021 09:28
Color Mastermind Game in Python
def solution(secret, guess):
while secret != guess:
correct_position_guessed = [0] * len(secret)
correct_color_guessed = [color for color in secret if color in guess]
for i in range(len(secret)):
if secret[i] == guess[i]:
correct_position_guessed[i] = 1
print('Correct colors guessed: {}'.format(' '.join(color for color in correct_color_guessed)))
@harshildarji
harshildarji / reber.py
Created May 24, 2021 09:17
Generate true Reber grammar sequences.
# This Python script can be used to generate true Reber grammar sequences.
# To generate false Reber grammar sequences, just change tuple values in 'traversal' at line 8.
import numpy as np
chars = 'BTSXPVE'
traversal = [[('T', 'P'), (1, 4)], [('S', 'X'), (1, 2)], [('S', 'X'), (3, 4)], [('E'), (-1,)], [('V', 'T'), (5, 4)], [('V', 'P'), (3, 2)]]
def generate_seq(min_length):
@harshildarji
harshildarji / ner.py
Created March 4, 2022 12:27
Generate NER predictions
import os
import pickle
import warnings
from functools import reduce
from operator import add
import numpy as np
import pandas as pd
import torch
from tqdm import tqdm