Created
May 24, 2012 21:14
-
-
Save mkoby/2784274 to your computer and use it in GitHub Desktop.
Intro to Ruby - 13 - Files
This file contains 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
def get_result(number) | |
if(number % 3 == 0 && number % 5 == 0) | |
return "FizzBuzz" | |
elsif(number % 3 == 0) | |
return "Fizz" | |
elsif(number % 5 == 0) | |
return "Buzz" | |
else | |
return number.to_s | |
end | |
end | |
File.open('random.txt', 'r').each do |line| | |
puts get_result(line.to_i) | |
end |
This file contains 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
def get_result(number) | |
if(number % 3 == 0 && number % 5 == 0) | |
return "FizzBuzz" | |
elsif(number % 3 == 0) | |
return "Fizz" | |
elsif(number % 5 == 0) | |
return "Buzz" | |
else | |
return number.to_s | |
end | |
end | |
File.open('results.txt', 'w') do |result_file| | |
File.open('random.txt', 'r').each do |line| | |
result_file.puts get_result(line.to_i) | |
end | |
end |
This file contains 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
25723 | |
18559 | |
7519 | |
3255 | |
32069 | |
10452 | |
14661 | |
27479 | |
21307 | |
1460 | |
22465 | |
13023 | |
4422 | |
15020 | |
6033 | |
8803 | |
3792 | |
15330 | |
6910 | |
29472 | |
29766 | |
26340 | |
5813 | |
13347 | |
11087 |
This file contains 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
25723 | |
18559 | |
7519 | |
FizzBuzz | |
32069 | |
Fizz | |
Fizz | |
27479 | |
21307 | |
Buzz | |
Buzz | |
Fizz | |
Fizz | |
Buzz | |
Fizz | |
8803 | |
Fizz | |
FizzBuzz | |
Buzz | |
Fizz | |
Fizz | |
FizzBuzz | |
5813 | |
Fizz | |
11087 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment