Skip to content

Instantly share code, notes, and snippets.

View Parassharmaa's full-sized avatar
🎯
Focusing

Paras Sharma Parassharmaa

🎯
Focusing
View GitHub Profile
@Parassharmaa
Parassharmaa / int_partition.py
Last active March 15, 2017 08:13
Integer Partition Algorithm
def partition(n):
if n==0:
yield []
for p in partition(n-1):
p.append(1)
yield p
p.pop()
if p and (len(p)<2 or p[-2] > p[-1]):
p[-1]+=1
@Parassharmaa
Parassharmaa / solution.py
Last active March 14, 2017 11:41
Solution to hacker rank problem
# A businessman dealing in salt goes to do business in a country named "strangeland" . The pricing of commodities in this country is quite strange indeed. Here salt is sold only in quantised packets which are multiple of 1 kilogram. The pricing is such that for a packet of i kilogram , the price is p[i] silver coins. The businessman has N kilogram of salt to sell. He wants your help to pack it so that he can earn maximum profit in "strangeland".
# Input Format
# First line of the input file contains a single integer T, the number of test cases.
# Every test case starts with a line containing the integer N , total amount of salt.
# The next line contains N space separated integers where the i-th integer is P[i] , the price of a salt packet of i Kilogram.
#int partition function
@Parassharmaa
Parassharmaa / car_data.cpp
Last active February 25, 2024 14:16
Program to illustrate example of file handling in c++
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
using namespace std;
class DataCar {
string brand_name;
string model_name;
@Parassharmaa
Parassharmaa / bst.cpp
Created November 23, 2016 16:50
Binary Search Tree: Insertion and traversing.
//Binary Search Tree: Insertion and traversing.
//Coded by: Paras Sharma
# include <iostream>
using namespace std;
class node {
public:
int key;
node *left;
@Parassharmaa
Parassharmaa / digit_words.cpp
Last active November 12, 2016 17:31
Program to converts digits into words (International system).
/*
Program to converts digits into words (International System).
(Supports upto 18 digits)
Program by Paras Sharmaa
*/
#include <iostream>
#include <cstring>
#include <stack>
@Parassharmaa
Parassharmaa / rand_word.py
Created October 15, 2016 07:55
Generate random word.
import random
df = open("sowpods.txt")
x = list(map(str,df.read().split()))
n = len(x)
r = int(input("Enter Number of words:"))
for i in range(r):
rand = random.randrange(0,n)
print(str(i+1)+"." + x[rand])
@Parassharmaa
Parassharmaa / string_divide.cpp
Last active November 26, 2016 12:18
Cpp program to divide the string in equal parts and sort out the substrings
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
class str_op {
string s;
@Parassharmaa
Parassharmaa / string_divide.py
Last active October 13, 2016 20:04
python program to divide string in equal sub-string and print in sorted form.
def mul(s):
l = len(s)
for i in range(2, l):
if l%i==0:
return(i)
break
else:
return 1
s = input("Input String:")
@Parassharmaa
Parassharmaa / stack_.cpp
Created October 5, 2016 02:50
Stack implementation via dynamic array
#include <iostream>
#include <cstring>
using namespace std;
class stack {
int top;
int size;
int *arr;
@Parassharmaa
Parassharmaa / queue.cpp
Last active October 5, 2016 02:56
Queue implementation via dynamic array.
#include <iostream>
using namespace std;
class queue {
int *arr;
int f,r, max;
public:
queue(int n) {