Skip to content

Instantly share code, notes, and snippets.

@nikasulo
Last active May 6, 2020 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikasulo/5ac7ec2c278c2d6ffa693ca0564266d7 to your computer and use it in GitHub Desktop.
Save nikasulo/5ac7ec2c278c2d6ffa693ca0564266d7 to your computer and use it in GitHub Desktop.
Test Answers
# 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