Skip to content

Instantly share code, notes, and snippets.

View saraswatmks's full-sized avatar
💭
I may be slow to respond.

Manish Saraswat saraswatmks

💭
I may be slow to respond.
View GitHub Profile
@saraswatmks
saraswatmks / weights
Created November 27, 2017 11:48
Weight calculation
pos_w = 1/mean(train_tmp$target)
w = ifelse(train_tmp$target == 0, 1, pos_w)
w = w/sum(w)
@saraswatmks
saraswatmks / insertion sort
Created November 26, 2017 10:33
insertion sort in R
insertion_sort <- function(line)
{
for(i in 2:length(line))
{
k <- i-1
tmp <- line[i]
while(k > 0 && line[k] > tmp)
{
@saraswatmks
saraswatmks / sol2016.py
Created November 12, 2017 01:43
Morgon Stanley Codeathon 2016 - My Solution
N, D = map(int, input().split())
rate = [int(x) for x in input().split()]
for _ in range(D):
prof1 = int(input())
d = {} # this has indexes
d1 = {} ## this has index difference
for i in range(len(rate)):
@saraswatmks
saraswatmks / sol.py
Created November 12, 2017 01:40
Morgon Stanley Codeathon - My Solution
## https://www.hackerrank.com/contests/morgan-stanley-codeathon-2017/challenges/shell-sort-command
n = int(input())
strs = [input().split() for x in range(n)]
count_space = len([item for sublist in strs for item in sublist])/ len(strs)
key, reverse_flag, c_type = input().split()
## set type first
@saraswatmks
saraswatmks / tryCatch.R
Last active July 19, 2018 16:02
tryCatch Example in R
damn <- function(x) ## x should be a vector
{
p <- list()
for(j in x)
{
out <- tryCatch({
if(j %% 2 == 0) p <- append(p, j)
else p <- append(p, 101)
@saraswatmks
saraswatmks / python_50
Created September 28, 2017 18:46
Sell Statistics
# Enter your code here. Read input from STDIN. Print output to STDOUT
T = int(raw_input())
sell = [[] for i in range(100)]
product_sell = [[[] for j in range(10)] for i in range(100)]
state_sell = [[[] for j in range(7)] for i in range(100)]
p_s_sell = [[[[] for j in range(7)] for j in range(10)] for i in range(100)]
for t in range(T):
query = 0
data = raw_input().split()
if data[0] == 'S':
#include <iostream>
#include <cstring>
using namespace std;
void parseDot(char s[100], int &first, int &second) {
int length = strlen(s);
int temp = 0, dotFound = 0, negative = 1;
for (int i = 0; i < length; i++) {
if (s[i] == '.') {
path <- "/home/manish/Desktop/temp"
setwd(path)
library(data.table)
library(lubridate)
library(tidytext)
saleData <- fread("new_data/final_model_data.txt")
head(saleData)
def calculate_ndcg(test_movies, predicted_movies, already_watched):
partial_dcgs = []
predicted_event_flags = {}
actual_events = test_movies
for pred_index, predicted_event in enumerate(predicted_movies):
try:
last_occ = predicted_event_flags.get(predicted_event, -1)
actual_index = actual_events[last_occ+1:].index(predicted_event)
effective_index = actual_index + last_occ + 1
predicted_event_flags[predicted_event] = effective_index
@saraswatmks
saraswatmks / string.py
Created September 1, 2017 12:36
python string
strn = 'abcbaabbcc'
d = {}
k = 2
prev_word = strn[0]
c = 1
for s in strn[1:]:
if prev_word == s:
c+=1
print('this is c = {} in first loop'.format(c))