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 getdue | |
puts "What is the amount due?" | |
due = gets.chomp | |
if !( /^\d*\.?\d{0,2}/.match(due) ) | |
getdue | |
end | |
due.to_f | |
end |
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 getguess max_num | |
puts "Guess a number between 0 and #{max_num}: " | |
guess = gets.chomp | |
if !( /^[0-9]*/.match(guess) ) | |
puts "Try again! NEED A NUMBER" | |
getguess (max_num) | |
end | |
return guess.to_i | |
end |
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
#!/usr/bin/env ruby | |
def make_guess | |
#returns a guess that is one charater long OR compares against the whole word | |
print "Guess a single letter (a-z) or the entire word: " | |
guess = gets.chomp | |
if !(/[a-zA-z]/.match(guess)) | |
puts "Please a enter a letter or word" | |
guess = make_guess |
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
|---- | |
| | |
| | |
| | |
|------\ | |
|---- | |
| 0 | |
| | |
| | |
|------\ |
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
characters = { | |
"Tyrion Lannister" => "House Lannister", | |
"Jon Snow" => "Night's Watch", | |
"Hodor" => "House Stark", | |
"Stannis Baratheon" => "House Baratheon", | |
"Theon Greyjoy" => "House Greyjoy" | |
} | |
characters.each {|key, value| puts "#{key} represents the #{value}" } |
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
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 {|movie| puts "#{movie[:year_released]}: #{movie[:title]}" } |
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
#TO DO LIST OF THING THAT NEED TO BE MADE | |
#1- count function | |
#2 - make it look pretty | |
#3- make it lose | |
def update_the_user_facing_word(hidden_word, guess, user_facing_word) | |
postion_in_the_word_hidden_word = 0 | |
hidden_word.each_char do |letter| | |
#start loop |
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
cuz_i_am_lazy= %w(75 | |
100 | |
85 | |
65 | |
84 | |
87 | |
95) | |
score= cuz_i_am_lazy.map{ |x| x.to_i} | |
puts score.inject(){|sum, value| sum + value} / score.length |
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 uniques(list) | |
list = list.split(',') | |
list.each_with_index do |num, index| | |
if list.count(num) > 1 | |
list.delete_at(index) | |
end | |
end | |
list.join(',') | |
end |
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 'minitest/spec' | |
require 'minitest/autorun' | |
require_relative '../lib/rightmost_occurrence' | |
describe "#rightmost_occurrence" do | |
it "returns nil if no matches are found" do | |
rightmost_occurrence('abc', 'x').must_equal nil | |
end |
OlderNewer