Skip to content

Instantly share code, notes, and snippets.

View violetguos's full-sized avatar

Violet Guo violetguos

View GitHub Profile
@violetguos
violetguos / substring.rb
Created June 8, 2020 21:00
TOP's ruby project
def substrings(words, dictionary)
result = Hash.new(0)
words = words.split(" ")
dictionary.map do |dict|
words.each do |word|
if word.downcase.include?(dict.downcase)
result[dict] += 1
end
end
end
def stonk_picker(stonk_arr)
# find the max diff between elements
max_profit = 0
max_idx = [0, 0]
stonk_arr.each_with_index do |buy, buy_idx|
stonk_arr.each_with_index do |sell, sell_idx|
# puts "%d %d" % [buy_idx, sell_idx]
if buy_idx < sell_idx && sell - buy > max_profit
max_idx[0] = buy_idx
max_idx[1] = sell_idx # get original idx
@violetguos
violetguos / bubble_sort.rb
Created June 11, 2020 19:01
TOP bubble sort assignment
def bubble_sort(arr)
# drop ignores previous sorted elems
arr.each_with_index do |dum, drop_i|
arr.drop(drop_i).each_with_index do |elem, i|
if arr[i+1] != nil && arr[i] > arr[i + 1]
temp = arr[i]
arr[i] = arr[i+1]
arr[i+1] = temp
end
end
@violetguos
violetguos / tic_tac_toe.rb
Created June 15, 2020 18:42
TOP ruby project
class Board
attr_accessor :board_config
def initialize
@board_config = [["_", "_", "_"], ["_", "_", "_"], ["_", "_", "_"]] # 3 by 3
@dim = 3
end
def lookup(coord)
return @board_config[coord[0]][coord[1]]
@violetguos
violetguos / pl-1
Last active January 25, 2021 23:45
medium
╔══════════════════╦══════════════════════╗
║ ecosystem ║ number of packages ║
╠══════════════════╬══════════════════════╣
║ Python’s `pip` ║ 235000 ║
║ Ruby’s gem ║ 133000 ║
║ Javascript’s NPM ║ 1m+ ║
╚══════════════════╩══════════════════════╝
@violetguos
violetguos / files.md
Created January 26, 2022 03:01
How to Structure Your Machine Learning Code Repository
.
├── README.md
├── data
├── evaluation
├── models
├── notebook
├── requirements.txt
├── results
├── singularity_python.sh