Skip to content

Instantly share code, notes, and snippets.

View sukhchander's full-sized avatar
💭
console.log('Fail' ? '' ? 'Better' ? '☕️🎾' : '' : '🚀☁️' : '🍺🍜')

sukhchander sukhchander

💭
console.log('Fail' ? '' ? 'Better' ? '☕️🎾' : '' : '🚀☁️' : '🍺🍜')
View GitHub Profile
TEXT = 'Given an arbitrary text document written in English, write a program
that will generate a concordance, i.e. an alphabetical list of all word
occurrences, labeled with word frequencies. Bonus: label each word with the
sentence numbers in which each occurrence appeared.'
def concordance1(string)
result = {}
string.split(".").each_with_index do |sentence, index|
sentence.gsub(",", "").split(" ").each do |word|
@sukhchander
sukhchander / NiceBag.java
Created July 30, 2018 13:54
NiceBag.java
/*
The package has a weight limitation.
Your goal is to determine which things to put into the package so that the total weight is less than or equal to the package limit and the total cost is as large as possible.
You would prefer to send a package which has less weight if there is more than one package with the same price.
This is a variation of the Knapsack problem.
Input:
Your program should read lines from standard input. Each line contains the weight that a package can take (before the colon) and the list of things you need to pick from. Each thing is enclosed in parentheses where the 1st number is a thing's index number, the 2nd is its weight and the 3rd is its cost.
Max weight any package can take is <= 100.
There might be up to 15 things you need to choose from.
Max weight and max cost of any thing is <= 100.
@sukhchander
sukhchander / Parentheses.java
Created July 31, 2018 13:09
Parentheses.java
import java.util.Stack;
/*
Using a Stack
Traverse the string expression
- If the current character is a opening bracket ('(' or '{') then push it to stack
- If the current character is a closing bracket (')' or '}') then pop from stack
and
if the popped character is the matching opening bracket then balanced
else