Skip to content

Instantly share code, notes, and snippets.

@jingxia1219
jingxia1219 / code_war: The observed PIN.rb
Last active June 18, 2018 01:54
code_war: The observed PIN
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)
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?"
class Hangman
def initialize
@dictionary = File.open('dictionary.txt').readlines.sample
play
end
def word_length
@length = @dictionary.length - 1
@chances = @length + 2
@jingxia1219
jingxia1219 / battleShip_solution.rb
Last active June 18, 2018 01:44
App_Academy BattleShip_Solution
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