Created
May 31, 2014 04:28
-
-
Save kitroed/97a3df836e4b4b063dca to your computer and use it in GitHub Desktop.
Challenge #164 [Easy] Assemble this Scheme into Python
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
puts "Hello World" |
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
# 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" |
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
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 |
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
puts "Enter word:" | |
word = gets.chomp | |
puts "Enter letter to remove from word:" | |
letter = gets.chomp | |
puts "The resulting word is: \"" + word.gsub(letter, "") + "\"" |
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
array = [1, 2, 3, 4, 5, 112] | |
sum = 0 | |
array.each { |a| sum += a } | |
puts "The sum of the array is: " + sum.to_s |
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
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