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 is_upper(ascii) | |
(ascii >= 65 and ascii <= 90) | |
end | |
def is_lower(ascii) | |
(ascii >= 97 and ascii <= 122) | |
end | |
def shift_char(ascii, shift) | |
return ascii.chr unless is_upper(ascii) || is_lower(ascii) |
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
dictionary = ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"] | |
def substrings(str, dict) | |
str = str.downcase | |
result = {} | |
dict.each do |substring| | |
scan = str.scan substring | |
result[substring] = scan.length unless scan.length == 0 | |
end | |
result |
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 stock_picker(prices) | |
tmp_buy = 0 | |
min_price = prices[tmp_buy] | |
max_profit = 0 | |
buy = -1 | |
sell = -1 | |
for i in 1...prices.length | |
if min_price > prices[i] | |
min_price = prices[i] | |
tmp_buy = i |
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 bubble_sort(prices) | |
loop do | |
swapped = false | |
for i in 1...prices.length | |
if prices[i-1] > prices[i] | |
prices[i], prices[i-1] = prices[i-1], prices[i] | |
swapped = true | |
end | |
end | |
break if not swapped |