This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def flatflat | |
result = [] | |
self.each do |elem| | |
if elem.is_a?(Array) | |
result.concat(elem.flatflat) | |
else | |
result.push(elem) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiples(max) | |
(1...max).select {|i| i % 3 == 0 || i % 5 == 0 }.reduce(:+) | |
end | |
puts multiples(1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
river = “************~~~” | |
river1 = “****~~~~” | |
river2 = “****************~~*~~~*” | |
# NOTES: | |
# | |
# acc. by 1 | |
# stay the same speed |
NewerOlder