Skip to content

Instantly share code, notes, and snippets.

@dmehrotra
dmehrotra / game.rb
Last active December 21, 2015 05:09
save and run this code
print "enter a max value? "
max_value = gets.to_i
target_number = rand(1..max_value);
def game(max_value, target_number)
print "Guess a number between 1 and #{max_value}? "
user_input = gets.to_i
max = max_value;
target_value = target_number
if user_input == 0 || user_input > max
#!/usr/bin/env ruby
class Game
def init(word)
@letter_array=[]
@guess_array = []
@guesses = []
@chances = 0
@target_word = word.each_char do |c|
@letter_array << c
@guess_array << '|-|'
@dmehrotra
dmehrotra / gist:6297979
Last active December 21, 2015 11:19
fizzBuzz
(1..100).each do |x|
if x % 3 == 0 && x % 5 == 0
puts 'fizzBuzz'
elsif x % 3 == 0
puts 'fizz'
elsif x % 5 == 0
puts 'Buzz'
else
puts x
end
@dmehrotra
dmehrotra / gist:6301450
Created August 21, 2013 23:20
Game of Thrones
characters = {
"Tyrion Lannister" => "House Lannister",
"Jon Snow" => "Night's Watch",
"Hodor" => "House Stark",
"Stannis Baratheon" => "House Baratheon",
"Theon Greyjoy" => "House Greyjoy"
}
characters.each do |key, value|
puts "#{key} represents the #{value}"
@dmehrotra
dmehrotra / gist:6308209
Created August 22, 2013 14:48
AverageCalculate
score_array = [75, 100, 85, 65, 84, 87, 95]
puts "the lowest score is: #{score_array.sort![0]}"
puts "the Highest score is: #{score_array.last}"
def average(scores,length)
sum = 0
scores.each do |x|
sum += x
end
favorite_movies = [
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 },
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 },
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 }
]
favorite_movies.each do |movie|
puts "#{movie[:year_released]}: Title: #{movie[:title]}"
end
@dmehrotra
dmehrotra / gist:6319756
Last active December 21, 2015 14:28
Journey
train={ 'Train 1' => 2, 'Train 2' => 5, 'Train 3' => 7.5, 'Train 4' => 8.5, 'Train 5' => 9, 'Train 6' => 10, 'Train 7' => 11.5, 'Train 8' => 13.5, 'Train 9' => 14.5, 'Train 10' => 17, 'Train 11' => 18,'Train 12' => 19, 'Train 13' => 24 }
print "what time do you want to leave: "
user_input = gets.chomp.to_f
def midnight_print
lyrics = "Just a small town girl Livin' in a lonely world She took the midnight train
Goin' anywhere
@dmehrotra
dmehrotra / transactions.rb
Created August 23, 2013 16:33
transactions.rb
#!/usr/bin/env ruby
require 'csv'
balance = 0.00
sum_income = 0.00
sum_deduction = 0.00
overdrafts=[]
deposits = []
@dmehrotra
dmehrotra / gist:6321357
Created August 23, 2013 16:34
black_jack
#!/usr/bin/env ruby
# encoding: UTF-8
class Blackjack
SUITS = ['♠', '♣', '♥', '♦']
VALUES = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
def initialize
@deck = []
@player=[]
@dmehrotra
dmehrotra / cardShuffler
Created August 26, 2013 15:17
CardShuffler
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
@rank = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A'].sample
else