Created
December 31, 2017 02:13
-
-
Save ijunaid8989/6dad41de93450d5aaf9a7cdb0151fd32 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
# version 1 | |
for counter in 1..100 | |
if (counter % 3 == 0) && (counter % 5 == 0) | |
puts 'Trakstar' | |
elsif (counter % 3 == 0) | |
puts 'Trak' | |
elsif (counter % 5 == 0) | |
puts 'Star' | |
else | |
puts counter | |
end | |
end | |
# version 2 | |
counter = 1 | |
while counter <= 100 | |
if (counter % 3 == 0) && (counter % 5 == 0) | |
puts 'Trakstar' | |
elsif (counter % 3 == 0) | |
puts 'Trak' | |
elsif (counter % 5 == 0) | |
puts 'Star' | |
else | |
puts counter | |
end | |
counter += 1 | |
end | |
# nerd version | |
(1..100).each { |number| | |
op = [] | |
if number%3==0 | |
op.push("Trak") | |
end | |
if number%5==0 | |
op.push("Star") | |
end | |
puts op.size > 0 ? op.join("") : number.to_s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment