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
class Crossword | |
attr_accessor :line1, :line2, :line3, :line4, :line5, :line6 | |
def initialize(layout) | |
layout_array = layout.split("\n") | |
@line1 = layout_array[0] | |
@line2 = layout_array[1] | |
@line3 = layout_array[2] | |
@line4 = layout_array[3] | |
@line5 = layout_array[4] |
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
=begin | |
#PSEUDOCODE FOR PHASE 2 | |
solve! | |
#STEP 1...next step is either step 2 or 3 | |
return false if board is valid | |
valid? => checks for duplicates | |
if attempt causes some repetition of number | |
#STEP 2... |
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
# Print the 1st, 3rd, 5th, 7th, etc. elements of a list on separate lines. | |
def print_odd_indexed_integers(array) | |
array.each_with_index do |item, index| | |
if index.even? | |
#should be .odd? in the spec | |
puts item | |
end | |
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
class GuessingGame | |
def initialize(answer) | |
@answer = answer | |
end | |
def guess(guess) | |
@guess = guess | |
if guess > @answer | |
return :high | |
elsif guess == @answer |
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
# generate a word at random and store it in a variable | |
# display the length of the word to the user | |
# correct_guesses is less than the length of the word | |
# prompt the user to guess a letter | |
# if the guess is correct increment correct_guesses by 1 | |
# if the guess is incorrect increment incorrect_guesses by 1 | |
# and draw the next part of the hangman | |
# if the incorrect_guesses is greater than 8, tell the user | |
# they lost and exit the program | |
# if correct_guesses is equal to the length of the word, tell the user they won |
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 method_4(array) | |
results = [] | |
array.each do |num| | |
if num % 2 == 0 | |
results << num | |
end | |
end | |
return results |
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 fizzblam | |
1000.times do |n| | |
if (n+1) %7 == 0 && (n+1) %5 == 0 | |
puts "FizzBlam" | |
elsif (n+1) %5 == 0 | |
puts "Fizz" | |
elsif (n+1) %7 == 0 | |
puts "Blam" | |
else | |
puts n + 1 |
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 product_odd(x) | |
odd = x.select {|y| y%2 == 1} | |
p = 1 | |
odd.each do |y| | |
p = p * y | |
end | |
p | |
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 product(x) | |
p = 1 | |
x.each do |y| | |
p = p * y | |
end | |
p | |
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 new_cat(str1, str2) | |
str1 + str2 | |
end | |
puts new_cat("Mor","dor") |