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
num_to_reverse = ARGV.first.to_i | |
class ReversedBinary | |
def reverse_it(num) | |
reversed = num.to_s(2).reverse.to_i(2) | |
puts reversed | |
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
def crackle | |
(1..100).map do |i| | |
crackle = i % 3 == 0 ? 'Crackle' : nil | |
pop = i % 5 == 0 ? 'Pop' : nil | |
crackle || pop ? "#{crackle}#{pop}" : i | |
end | |
end | |
puts crackle |
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
pattern = ',*,foo,bar,baz' | |
path = 'cat/foo/bar/baz' | |
# rules for match method: | |
# - return boolean value | |
# - asterisks are wildcards | |
# - compare pattern and path | |
# - matching letter rated higher over asterisk | |
# - if same # of asterisks, prefer wildcards that appear further to right |
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
string = 'this is a string' | |
arr = string.split(' ') | |
print arr.reverse.join(' ') |
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 fizz_buzz | |
(1..100).map do |num| | |
f = num % 3 == 0 ? 'Fizz' : nil | |
b = num % 5 == 0 ? 'Buzz' : nil | |
f || b ? "#{f}#{b}" : num | |
end | |
end | |
puts fizz_buzz |
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 reverse_string(string) | |
string.split(' ').reverse.join(' ') | |
end | |
puts reverse_string('this is a string!') |
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 leap_year?(year) | |
if year % 100 == 0 | |
true if year % 400 == 0 | |
else | |
true if year % 4 == 0 | |
end | |
end | |
def minutes_in_year(year) | |
if leap_year?(year) |
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 prompt(question) | |
puts question | |
answer = gets.chomp | |
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 leap_year?(year) | |
if year % 100 == 0 | |
year % 400 == 0 ? true : false | |
else | |
year % 4 == 0 ? true : false | |
end | |
end | |
def minutes_in_year(year) | |
if leap_year?(year) |
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
s = <<-STRING | |
Line 1: Welcome to the forum. | |
Line 2: Here you can learn Ruby. | |
Line 3: Along with other members. | |
STRING | |
puts s |
NewerOlder