Skip to content

Instantly share code, notes, and snippets.

View rkuang's full-sized avatar

Ricky Kuang rkuang

View GitHub Profile
@rkuang
rkuang / ruby-bubble-sort.rb
Last active September 20, 2020 21:51
Ruby Bubble Sort Project from TOP
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
@rkuang
rkuang / ruby-stockpicker.rb
Last active September 20, 2020 21:30
Stock Picker Ruby Project from TOP
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
@rkuang
rkuang / ruby-substrings.rb
Last active September 20, 2020 21:01
Ruby Substrings Project from The Odin Project
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
@rkuang
rkuang / ruby-caesar-cipher.rb
Last active September 20, 2020 21:51
Ruby Caesar Cipher Project from The Odin Project
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)