Skip to content

Instantly share code, notes, and snippets.

View sukhchander's full-sized avatar
💭
console.log('Solutions' ? '' ? 'Architect' ? '@aws' : '' : '🚀☁️' : '🍺🍜')

sukhchander sukhchander

💭
console.log('Solutions' ? '' ? 'Architect' ? '@aws' : '' : '🚀☁️' : '🍺🍜')
View GitHub Profile
@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
@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.
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 / flatflat.rb
Last active April 19, 2016 21:02
flatten an array of arbitrarily nested arrays of integers into a flat array of integers
class Array
def flatflat
result = []
self.each do |elem|
if elem.is_a?(Array)
result.concat(elem.flatflat)
else
result.push(elem)
end
end
@sukhchander
sukhchander / max_sum_path.rb
Created December 31, 2015 17:22
max sum path
#!/usr/bin/env ruby
def max_path_sum(file)
input = File.open(file).readlines
numbers = input.collect { |line| line.split(" ").map(&:to_i) }
# started from the bottom
triangle_size = numbers.size - 2
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
DIRECT-roku-138 b0:a7:37:0b:17:2b -45 11 Y US WPA2(PSK/AES/AES)
DIRECT-roku-696 b0:a7:37:0e:3c:c3 -48 11 Y US WPA2(PSK/AES/AES)
VCHO0 00:26:b8:11:6d:e4 -70 6 Y US WEP
SBG65803E 20:10:7a:7f:59:55 -81 1 Y -- WPA(PSK/AES/AES) WPA2(PSK/AES/AES)
@sukhchander
sukhchander / install-go.sh
Last active August 29, 2015 14:07
install-go.sh
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
brew update
brew install go
brew install git
brew install mercurial
mkdir $HOME/go
mkdir -p $GOPATH/src/github.com/user
@sukhchander
sukhchander / collapse.rb
Created June 18, 2014 14:41
collapse entries
input = [
{ time: 201_201, x: 2 },
{ time: 201_201, y: 7 },
{ time: 201_201, z: 2 },
{ time: 201_202, a: 3 },
{ time: 201_202, b: 4 },
{ time: 201_202, c: 0 }
]
output = [
def multiples(max)
(1...max).select {|i| i % 3 == 0 || i % 5 == 0 }.reduce(:+)
end
puts multiples(1000)
@sukhchander
sukhchander / cross_river.rb
Created April 2, 2014 03:00
can cross river?
river = “************~~~”
river1 = “****~~~~”
river2 = “****************~~*~~~*”
# NOTES:
#
# acc. by 1
# stay the same speed