Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View noqcks's full-sized avatar
🏠
Working from home

Benji Visser noqcks

🏠
Working from home
View GitHub Profile
puts "hello"
"Benjamin".reverse
puts "Hi, {#name}"
def say_hi
print "What is your name: "
name = gets.chomp
puts "Hi, #{name}"
say_hi
def say_hello
puts "Hello, Ben"
def fizzbuzz(startNum,endNum)
startNum.upto(endNum) do |i|
if i % 5 == 0 && i % 3 == 0
puts "FizzBuzz"
elsif i % 5 == 0
puts "Buzz"
elsif i % 3 == 0
puts "Fizz"
else
puts i
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
baller && (furnished || rent < 2100) ? true : false
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.
# Without the test code, it will be hard for you to know if this method is working as it should or not.
###
# 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
def shakil_the_dog
def BubbleSort(to_sort)
n = to_sort.length
sorted = false
until sorted
sorted = true
for i in 0..(n - 2)
if to_sort[i] > to_sort[i + 1]
sorted = false
def BubbleSort(to_sort)
n = to_sort.length
sorted = false
until sorted
sorted = true
for i in 0..(n - 2)
if to_sort[i] > to_sort[i + 1]
sorted = false
def fizz_buzz(num_start,num_stop)
num_start.upto(num_stop) { |num|
puts evaluate(num)
}
end
def evaluate(num)
if div_3?(num) && div_5?(num)
"FizzBuzz"
elsif div_5?(num)
def average(numbers)
sum = 0
numbers.each do |num|
sum += num
end
if numbers.empty? || numbers.nil?
0
else
sum / numbers.size
end
### 1. Tells the Numbers of Characters
def count_letters(string)
array = string.delete(" ").split("")
hash = Hash.new(0)
array.each do |letter|
letter = letter.downcase
hash[letter] += 1
end
@noqcks
noqcks / State Info
Created September 4, 2014 21:52
w1d3
$states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
#1. adding new states to state hash
$states[:TX] = 'Texas'