Skip to content

Instantly share code, notes, and snippets.

@katiebuilds
katiebuilds / battleship.md
Last active August 29, 2015 14:13
Battleship Instructions

#Battleship Instructions ##General Vision I looked this up on Wikipedia first, and after reading that it started as a pen-and-paper game, I started visualizing this game as based on a grid of squares, and the different states they might be in. I was thinking of things along these lines:

  • Each side has the following:
    • Target Grid Squares
    • empty
    • hit enemy
    • missed enemy
    • Ocean Grid Squares
  • empty
def fish_length(lower, upper)
return rand(upper) + lower
end
puts "What kind of fish did you catch?"
species = gets.chomp
puts "What is the biggest (in inches) that kind of fish can be?"
upper = gets.chomp.to_i
puts "How small (in inches) is the smallest fish you would keep?"
class Ship
def initialize(length)
@length = length
@coordinates_covered = []
@has_been_placed = false
@is_sunk = false
@red_pegs = []
end
def length
return @length
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which returns:
#
# * "Fizz" if the number is divisible by 3
# * "Buzz" if the number is divisible by 5
# * "FizzBuzz" if the number is divisible by 3 and 5
# * Otherwise, return the number itself
#
require 'minitest/autorun'
require 'minitest/pride'
# Write two methods:
#
# * `first_name`: given a name in string, return the first name.
# * `last_name`: given a name in string, return the last name.
# WRITE YOUR CODE HERE.
@katiebuilds
katiebuilds / tacocat
Created February 11, 2015 14:10
Palindromes...passes all tests
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts one parameter. The method should return true if
# the string passed to it is a palindrome. It should return false if the string
# is not a palindrome
# WRITE YOUR CODE HERE.
def palindrome?(string)
s = string.downcase.split.join
require 'minitest/autorun'
require 'minitest/pride'
# Write a series of methods which use the .any, .all, .map, .select, .reject, and
# .reduce methods in Enumerable. Each of your methods should be one line.
#ONE LINE...uggggghhhhh. will worry about that later.
# WRITE YOUR CODE HERE. In this challenge, names longer than 5 characters are
# considered long.
def has_even?(array)
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array as the first paramater and a number
# as the second parameter. Return true if two of the numbers in the array sum
# to the second parameter.
# WRITE YOUR CODE HERE. Name your method `complements?`.
def complements?(array, number)
return false if array == nil || array.length < 2
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array as the first paramater and a number
# as the second parameter. Return true if two of the numbers in the array sum
# to the second parameter.
# WRITE YOUR CODE HERE. Name your method `complements?`.
def complements?(array, sum)
return false if array == nil || array.length < 2
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array and returns a hash. Each item in the
# array will be a string, and the returned hash should have last names as keys
# and first names as values.
# WRITE YOUR CODE HERE. Name your method `names`.
def names(array)
hash = Hash.new