Skip to content

Instantly share code, notes, and snippets.

View ruxandrafed's full-sized avatar
🎯
Focusing

Ruxandra Fediuc ruxandrafed

🎯
Focusing
View GitHub Profile
# Determine whether a string contains a SIN (Social Insurance Number).
# A SIN is 9 digits and we are assuming that they must have dashes in them
def has_sin?(string)
my_match = /\b\d\d\d\-\d\d\d\-\d\d\d\b/.match(string)
my_match == nil ? false : true
end
puts "has_sin? returns true if it has what looks like a SIN"
puts has_sin?("please don't share this: 234-604-142") == true
@states = Hash.new { |h, k| h[k][1] = []}
@states = {
OR: ['Oregon', ['Portland', 'Jacksonville']],
FL: ['Florida', ['Miami']],
CA: ['California', ['San Jose', 'San Francisco', 'Monterrey']],
NY: ['New York', ['New York City', 'Long Island']],
MI: ['Michigan', ['Detroit']]
}
states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
def count_letters(str)
letters = Hash.new{0}
str = str.gsub(/\s+/, "") #removes spaces
str.each_char { |c| letters[c] += 1 }
puts letters.inspect
end
puts "What's your string?"
user_input = gets.chomp
@ruxandrafed
ruxandrafed / debug01.rb
Last active September 7, 2015 19:01 — forked from rafd/debug01.rb
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'}
# Why is it returning nil instead of first element of the list above
p list['yvr']
def fizz_buzz_puts(start, finish)
# loops through each number in the range
start.upto(finish) do |number|
puts fizz_buzz(number)
end
end
def fizz_buzz(number)
# checks if number is divisible by both 3 and 5
if div_3?(number) && div_5?(number)
@ruxandrafed
ruxandrafed / fizzbuzz_messy.rb
Last active September 2, 2015 05:50 — forked from kvirani/fizzbuzz_messy.rb
W1D2 Homework Exercise - Ruby - Messy Fizzbuzz
def fb(s, f)
s.upto(f) { |x|
puts e(x)
}
end
def e(y)
if div_3?(y) && div_5?(y)
"FizzBuzz"
elsif div_5?(y)
def merge_sort(arr)
# if array is empty or has just one element, no need to sort
return arr if arr.size <= 1
# split array in 2 halves (divide)
mid = arr.size/2
left = arr[0, mid] # arr[start,length]
right = arr[mid, arr.size-mid]
return merge(merge_sort(left),merge_sort(right))
def area_price(length,width)
length * width * 15
end
def colour_price(colour_count)
colour_count <= 2 ? 10 * colour_count : 15 * colour_count
end
def add_tax(price_without_tax)
(price_without_tax * 1.15).round(2)
@ruxandrafed
ruxandrafed / sort.rb
Last active September 2, 2015 00:51 — forked from davidvandusen/sort.rb
# Implemented bubble sort & radix sort
# Included benchmarking module & benchmarked both methods
# Included manual benchmarking for radix_sort
# Sort the array from lowest to highest
def bubble_sort(arr)
return arr if arr.size <= 1 # already sorted
swapped = true
while swapped do
swapped = false