Skip to content

Instantly share code, notes, and snippets.

@kitroed
Created May 31, 2014 04:28
Show Gist options
  • Save kitroed/97a3df836e4b4b063dca to your computer and use it in GitHub Desktop.
Save kitroed/97a3df836e4b4b063dca to your computer and use it in GitHub Desktop.
Challenge #164 [Easy] Assemble this Scheme into Python
puts "Hello World"
# initialize an array of 100 elements
a = Array.new(100)
i = 0
count = 0
while count < 100 do
# looking for 100 successfull adds
if i % 3 == 0 && i % 5 == 0
a[count] = i
count += 1
end
i += 1
end
print a
print "\n"
puts "Enter first potential anagram to evaluate:"
a = gets.chomp
puts "Enter second:"
b = gets.chomp
if a.upcase.chars.sort.join == b.upcase.chars.sort.join
puts "Confirmed! Anagram detected!"
else
puts "\"" + a + "\" is not an anagram of \"" + b + "\""
end
puts "Enter word:"
word = gets.chomp
puts "Enter letter to remove from word:"
letter = gets.chomp
puts "The resulting word is: \"" + word.gsub(letter, "") + "\""
array = [1, 2, 3, 4, 5, 112]
sum = 0
array.each { |a| sum += a }
puts "The sum of the array is: " + sum.to_s
array_of_numbers_to_sort = [17, 2, 14, 112, 3, 62, 13]
puts "Array to sort:"
print array_of_numbers_to_sort
puts
sequence_modified = true
while sequence_modified do
sequence_modified = false
i = 0
while i < array_of_numbers_to_sort.length - 1 do
if array_of_numbers_to_sort[i] > array_of_numbers_to_sort[i + 1]
temp = array_of_numbers_to_sort[i + 1]
array_of_numbers_to_sort[i + 1] = array_of_numbers_to_sort[i]
array_of_numbers_to_sort[i] = temp
sequence_modified = true
end
i += 1
end
end
puts "Results of bubble sort:"
print array_of_numbers_to_sort
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment