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 get_pins(observed) | |
adjacents = [] | |
chars = observed.chars | |
chars.each do |char| | |
adjacents << adjacent(char) | |
end | |
adjacents.reduce { |acc,el| acc.product el }.map { |el| el.join("")}.sort | |
end | |
def adjacent(str) |
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 Hanoi | |
def initialize | |
@disc = Array.new(3) {Array.new(1)} | |
@disc[0] = (1..3).to_a.reverse | |
choose_mode | |
play | |
end | |
def choose_mode | |
puts "Welcome to Hanoi! It starts with 3 discs, would you like to play more?\ny/n?" |
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 Hangman | |
def initialize | |
@dictionary = File.open('dictionary.txt').readlines.sample | |
play | |
end | |
def word_length | |
@length = @dictionary.length - 1 | |
@chances = @length + 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
require_relative "board" | |
require_relative "player" | |
class BattleshipGame | |
attr_reader :board, :player | |
def initialize(player = HumanPlayer.new("Jeff"), board = Board.random) | |
@player = player | |
@board = board | |
@hit = false |