Skip to content

Instantly share code, notes, and snippets.

@rob0t7
Created January 5, 2016 21:16
Show Gist options
  • Save rob0t7/5cab760d3d027217e1b4 to your computer and use it in GitHub Desktop.
Save rob0t7/5cab760d3d027217e1b4 to your computer and use it in GitHub Desktop.
def fizzbuzz(start, final)
start.upto(final) do |i|
puts fizzbrain(i)
end
end
def fizzbrain(num)
output = ''
output << 'Fizz' if num % 3 == 0
output << 'Buzz' if num % 5 == 0
output << 'Blah' if num % 7 == 0
output.empty? ? num : output
end
fizzbuzz(1, 10)
input = "The cat is blue"
def reverse_sentence(input)
# break sentence into list of
# words
list_of_words = input.split(' ')
# reverese list of words
list_of_words = list_of_words.reverse
# convert list of words into
# a sentence
list_of_words.join(' ')
end
puts reverse_sentence(input)
x = ['The', 'cat', 'is', 'blue.']
def recur_concat(input, result)
if input.empty?
return result
else
return recur_concat(
input[1..-1],
result + "#{input[0]} "
)
end
end
puts recur_concat(x, '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment