Created
May 28, 2013 11:24
-
-
Save abdul-shajin/5662086 to your computer and use it in GitHub Desktop.
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
a) | |
1.upto(n).each do |num| | |
if num % 3 == 0 | |
puts 'Hip' | |
next | |
elsif num % 5 == 0 | |
puts 'Hop' | |
next | |
elsif (num % 3 == 0) && ( num % 5 == 0) | |
puts 'Whazaa' | |
next | |
end | |
puts num | |
end | |
b) | |
f = File.read("filename") | |
wf = Hash.new(0) | |
f.split(' ').each do |nums| | |
wf[nums] += 1 | |
end | |
puts wf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Abdul, can you spot the bug in your first program?