Skip to content

Instantly share code, notes, and snippets.

@begin-again
Created October 20, 2016 21:45
Show Gist options
  • Save begin-again/b0bbdbfd4637bc6aa4a1113bcfd5ae3c to your computer and use it in GitHub Desktop.
Save begin-again/b0bbdbfd4637bc6aa4a1113bcfd5ae3c to your computer and use it in GitHub Desktop.
My attempt at CodeEval.com's FizzBizz challenge.
# FizzBizz
# https://www.codeeval.com/open_challenges/1/
# Each line of input file: X Y Z
# where: X = first divisor, Y = second divisor, Z = number to count up to
# example:
# 3 5 10 => 1 2 F 4 B F 7 8 F B
# 2 7 15 => 1 F 3 F 5 F B F 9 F 11 F 13 FB 15
myfile = ARGV[0]
if File.exists?(myfile)
File.open(myfile) do |file|
file.each_line do |line|
input = line.split(" ").map{ |e| e.to_i }
next if input.size == 0
output = []
1.upto(input[2]) do |i|
a_char = ""
a_char << "F" if i % input[0] == 0
a_char << "B" if i % input[1] == 0
output << (a_char.empty? ? i : a_char)
end
p output.join(' ')
end
end
end
@begin-again
Copy link
Author

The output seems correct to me but CodeEval consistently fails it.

@begin-again
Copy link
Author

Doh! The error is that there are double quotes in the output. Replace the p output.join(' ') with puts output.join(' ') and CodeEval accepts the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment