Last active
May 6, 2020 17:53
-
-
Save nikasulo/5ac7ec2c278c2d6ffa693ca0564266d7 to your computer and use it in GitHub Desktop.
Test Answers
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
# More elegant | |
def alphabet_position(string) | |
string_codes = string.downcase.bytes.to_a | |
strictly_alphabets = [] | |
string_codes.each do |code| | |
unless code - 96 < 1 || code - 96 > 26 | |
strictly_alphabets << code - 96 | |
end | |
end | |
strictly_alphabets.join(' ') | |
end | |
p alphabet_position("The sunset sets at twelve o'clock.") | |
# Returns => "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" | |
# Find sum of all multiples of 3 or 5 less than 1000 | |
def sum_finder(lower_multiple, higher_multiple, limit) | |
sum = 0 | |
for i in lower_multiple...limit | |
if i % lower_multiple == 0 || i % higher_multiple == 0 | |
sum+=i | |
end | |
end | |
sum | |
end | |
p sum_finder(3,5,1000) | |
# Returns => 233168 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment