I hereby claim:
- I am scottchiang on github.
- I am schiang (https://keybase.io/schiang) on keybase.
- I have a public key ASB1fx_e0aOB7dm4LZjIMaRIFGi20HVSEjmHm0zIt8uucAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| import scala.collection.mutable | |
| import scala.collection.mutable.MutableList | |
| import scala.collection.immutable.IntMap | |
| import scala.collection.JavaConversions.mapAsScalaMap | |
| import scala.util.control.Breaks._ | |
| // The run time for my code is roughly 120ms. I'm pretty sure I'm not understanding something about scala because when | |
| // I implement this in ruby, it runs in around 20ms. I think I can improve performance by changing how I'm | |
| // storing and updating values using HashMap. |
| data model: | |
| seller: | |
| has_many :products | |
| attributes: balance | |
| product: | |
| has_many :purchases | |
| has_many :buyers, :through => :purchase |
| def pivot_index(ary) | |
| idx = -1 | |
| left_sum = 0 | |
| right_sum = ary[1..-1].inject(:+) | |
| #can't find pivot if array's length is less than 3 | |
| if ary.length > 2 | |
| #ignore the first and last element because they only have 1 neighbor | |
| 1.upto(ary.length - 2) do |x| | |
| left_sum += ary[x-1] |
| package main | |
| import "fmt" | |
| func main() { | |
| for i := 1; i < 101; i++ { | |
| switch { | |
| case (i % 15) == 0: fmt.Println("FizzBuzz") | |
| case (i % 3) == 0: fmt.Println("Fizz") | |
| case (i % 5) == 0: fmt.Println("Buzz") |
| class Flashcard | |
| attr_accessor :word, :definition | |
| def initialize(word, definition) | |
| @word = word | |
| @definition = definition | |
| end | |
| end | |
| class CardStack |
| class BankAccount | |
| def initialize(customer_name, type, acct_number) | |
| @customer_name = customer_name | |
| @type = type | |
| @acct_number = acct_number | |
| end | |
| def name | |
| @customer_name | |
| end |
| def in_words(n) | |
| @ones = {1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", | |
| 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 11 => "eleven", | |
| 12 => "twelve", 13 => "thirteen", 14 => "fourteen", 15 => "fifteen", | |
| 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen" | |
| } | |
| @twos = {2 => "twenty", 3 => "thirty", 4 => "forty", 5 => "fifty", 6 => "sixty", | |
| 7 => "seventy", 8 => "eighty", 9 => "ninety" | |
| } | |
| @scale = {1 => "thousand", 2 => "million", 3 => "billion", 4 => "trillion", 5 => "quadrillion", |
| def binary_search(obj, array, lower = 0, upper = array.length) | |
| mid_point = ((upper - lower) / 2) + lower | |
| if obj != array[mid_point] && (mid_point == array.length - 1 || mid_point == 0) | |
| return -1 | |
| elsif obj == array[mid_point] | |
| return mid_point | |
| elsif obj < array[mid_point] | |
| binary_search(obj, array, lower, mid_point) | |
| elsif obj > array[mid_point] | |
| binary_search(obj, array, mid_point, upper) |
| #linear search | |
| def linear_search(object, array) | |
| index = 0 | |
| while array[index] != nil | |
| if object != array[index] | |
| mismatch += 1 | |
| end | |
| if object == array[index] |