Skip to content

Instantly share code, notes, and snippets.

View lostmarinero's full-sized avatar

Kevin Berry lostmarinero

View GitHub Profile
@lostmarinero
lostmarinero / card_shuffler.rb
Last active January 3, 2016 06:29
This was a coding challenge for a company. The question was: ShufflinGiven a deck of n unique cards, cut the deck c cards from the top and perform a perfect shuffle. A perfect shuffle is where you put down the bottom card from the top portion of the deck followed by the bottom card from the bottom portion of the deck. This is repeated until one …
# Given a deck of n unique cards, cut the deck c cards from the top and perform a perfect shuffle.
# A perfect shuffle is where you put down the bottom card from the top portion of the deck followed by the bottom card from the bottom portion of the deck.
# This is repeated until one portion is used up. The remaining cards go on top.
# We want an algorithm that will determine the number of perfect shuffles that will need to happen before the deck returns to its original order. This can be done in any language.
# A successful solution will solve the problem for 1002 cards and a cut size of 101 in under a second even on a slow machine.
class Shuffler
attr_reader :initial_cards, :cut, :top_cut, :top, :bottom, :extra
@lostmarinero
lostmarinero / sports_scoring.rb
Created January 14, 2014 18:47
This was a challenge as posted on reddit: http://www.reddit.com/r/dailyprogrammer/comments/1undyd/010714_challenge_147_easy_sport_points/ The challenge: You must write code that verifies the awarded points for a fictional sport are valid. This sport is a simplification of American Football scoring rules. This means that the score values must be …
# 6 points for a "touch-down"
# 3 points for a "field-goal"
# 1 point for an "extra-point"; can only be rewarded after a touch-down. Mutually-exclusive with "two-point conversion"
# 2 points for a "two-point conversion"; can only be rewarded after a touch-down. Mutually-exclusive with "extra-point"
class Scoring
attr_reader :max_number_each, :scoring_values
attr_accessor :score, :counter
@lostmarinero
lostmarinero / flight_route.rb
Created January 14, 2014 18:52
This is a coding challenge focused on finding all the routes for a network of flights. I added Portland as a city to make it a little more complex. The original challenge: Express the following table as a static structure, and write a function, find_routes(source, destination) that efficiently outputs all possible routes.
# Flights, Ruby
#
# Express the following table as a static structure,
# and write a function, find_routes(source, destination) that
# efficiently outputs all possible routes.
#
# Source | Dest
# ~~~~~~ ~~~~
# Seattle | LA
# LA | Florida