Created
October 20, 2016 21:45
-
-
Save begin-again/b0bbdbfd4637bc6aa4a1113bcfd5ae3c to your computer and use it in GitHub Desktop.
My attempt at CodeEval.com's FizzBizz challenge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doh! The error is that there are double quotes in the output. Replace the
p output.join(' ')
withputs output.join(' ')
and CodeEval accepts the output.