Skip to content

Instantly share code, notes, and snippets.

View sahilbansal17's full-sized avatar
🏠
Working from home

Sahil Bansal sahilbansal17

🏠
Working from home
  • Remote
  • 10:23 (UTC +05:30)
View GitHub Profile
@sahilbansal17
sahilbansal17 / classDilemma.cpp
Last active January 24, 2020 13:04
Predict the output
#include <iostream>
using namespace std;
class A{
public:
virtual void functionA() {
cout << "function A of class A called!" << endl;
}
virtual void functionB() {
cout << "function B of class A called!" << endl;
@sahilbansal17
sahilbansal17 / deletionDistance.cpp
Created October 30, 2018 18:36
Deletion Distance problem on Pramp
#include <iostream>
#include <string>
using namespace std;
// i: str1
// j: str2
int calcDeletionDistance(string str1, string str2, int i, int j, int dp[][2000]) {
if (i == str1.length()) {
@sahilbansal17
sahilbansal17 / rational1_sig.sml
Last active March 2, 2018 10:45
RATIONAL NUMBERS SML
signature Rational =
sig
type rational
exception rat_error
val make_rat: int * int -> rational
val rat: int -> rational
val reci: int -> rational
val == : rational * rational -> bool
val << : rational * rational -> bool
@sahilbansal17
sahilbansal17 / towerOfHanoi.sml
Created February 27, 2018 12:08
Tower of Hanoi Puzzle
(*
This program is used to solve the standard Tower of Hanoi puzzle.
*)
(*
Generate a list containing the disks from 1 to n, which is the rod from where we will transfer
*)
(* fun genList(L, i, N) =
if i=N+1 then L
else genList(i::L, i+1, N) *)
@sahilbansal17
sahilbansal17 / sortWithoutDuplicates.sml
Created February 24, 2018 07:31
sortWithoutDuplicates
(*
A program to take a list of numbers and the binary relation R
then sort the numbers in the list according to R and also remove the duplicates, but not removing the duplicates after sorting, rather while sorting. It is supposed to have O(nlogn) time complexity and O(n) space complexity.
*)
(*
using Merge Sort routine from Prof. S. Arun Kumar's programs
*)
fun sortWithoutDuplicates R [] = []
@sahilbansal17
sahilbansal17 / nextDay.sml
Created February 24, 2018 06:15
Next day calculator
(* A program to calculate the next day given the current day in the format
ymmdd where y can be anything > 1, mm and dd represent the two integers representing the month and day respectively *)
exception invalid_date
fun next_day(y,m,d)=
let
fun check_valid_day(d)=
if d>=1 andalso d<=31 then true
else false
fun check_valid_month(m)=