Skip to content

Instantly share code, notes, and snippets.

View ruxandrafed's full-sized avatar
🎯
Focusing

Ruxandra Fediuc ruxandrafed

🎯
Focusing
View GitHub Profile
[1] pry(main)> def say_bye(name)
[1] pry(main)* puts "Bye bye, #{name}! See you later!"
[1] pry(main)* end
=> nil
[2] pry(main)> say_bye("Rux")
Bye bye, Rux! See you later!
=> nil
[3] pry(main)> my_array = ["one", "two", "blabla"]
=> ["one", "two", "blabla"]
[4] pry(main)> my_array.sort
@ruxandrafed
ruxandrafed / max.rb
Last active September 1, 2015 19:15 — forked from davidvandusen/max.rb
# Find the maximum
# def maximum(arr)
# arr.max
# end
def maximum(arr)
return nil if arr.empty?
max = - 1.0/0 #returns negative infinity
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby shakil_the_dog.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your dog (named Shakil).
# You'll probably want to write other methods, but this
# encapsulates the core dog logic
@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
@ruxandrafed
ruxandrafed / renter.rb
Last active September 2, 2015 01:07 — forked from davidvandusen/renter.rb
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
result = baller && (furnished || rent < 2100)
puts "Furnished: #{furnished}. Rent: #{rent}. Baller: #{baller}. Rent? #{result}"
end
###
# Add your "test" ("driver") code below in order to "test drive" (run) your method above...
# The test code will call the method with different permutations of options and output the result each time.
# This way, you will be able to run the renter.rb file from the CLI and look at the output of your "tests" to validate if the method works.
def fizzbuzz_output(number)
result = ""
result << "Fizz" if number % 3 == 0
result << "Buzz" if number % 5 == 0
result = number if result.empty?
result
end
def fizzbuzz(a,b)
a.upto(b) do |number|
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)
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))
@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 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)