Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fizzbuzz in ruby #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Adhoc/Fizz-Buzz/solution_naive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solutuon
def fizz_buzz(n)
arr = []
(1..n).each do |i|
if i%15 == 0
arr << "FizzBuzz"
elsif i%5 == 0
arr << "Buzz"
elsif i%3 == 0
arr << "Fizz"
else
arr << i.to_s
end
end
arr
end
end

21 changes: 21 additions & 0 deletions Adhoc/Fizz-Buzz/solution_string_concat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solutuon
def fizz_buzz(n)
str = ""
(1..n).each do |i|
if i%15 == 0
str += "FizzBuzz"
elsif i%5 == 0
str += "Buzz"
elsif i%3 == 0
str += "Fizz"
else
str += i.to_s
end
end
str
end
end

Solutuon.new.fizz_buzz(15)