This file contains hidden or 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
girl = 0 | |
boy = 1 | |
at_least_one_girl = 0 | |
all_girls = 0 | |
1000000.times{ | |
one_girl = false | |
num_girls = 0 | |
3.times { |
This file contains hidden or 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 Dollar(val) | |
Dollar.createRoundedDollar(val.kind_of?(Dollar) ? val.raw : val) | |
end | |
def getDollar | |
input = gets.chomp | |
return nil if (input.empty?) | |
Dollar.createRoundedDollar(input) | |
end |
This file contains hidden or 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
# This program is a demo of how to find factors for numbers | |
# But it's highly inefficient. Can you think of how to make it faster? | |
# Print message to ask the user for a number | |
puts 'What number shall we find factors for? ' | |
# Get input from user and store in a variable we've decided | |
# to name number_to_factor. | |
# 'gets' is the name of the function that takes input from the user. | |
# By default 'gets' returns a variable that's called a "string" which means its just text |
This file contains hidden or 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
# This program is a demo of how to find factors for numbers | |
# Print message to ask the user for a number | |
puts 'What number shall we find factors for? ' | |
# We want to get input from user and store in a variable. | |
# We've decided to name our variable number_to_factor. | |
# 'gets' is the name of the function that takes input from the user. | |
# By default 'gets' returns a variable that's called a "string" which means its just text. | |
# But we actually need our variable to be a number for calculations, so adding |
This file contains hidden or 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
puts 'What number shall we find factors for? ' | |
number_to_factor = gets.to_i | |
puts "Factors for #{number_to_factor} are:" | |
1.upto(number_to_factor) { |number_to_test| | |
if (number_to_factor % number_to_test == 0) | |
puts number_to_test | |
end |
This file contains hidden or 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
# This program is a demo of how to find factors for numbers | |
# Print message to ask the user for a number | |
# "puts" is shorthand for "put string". | |
# It's how we output text to the user. | |
puts "What number shall we find factors for? " | |
# We want to get input from the user and then store that input | |
# in a "variable" so that we can access it again later. | |
# We've decided to name our variable "number_to_factor". |
This file contains hidden or 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 'irb/completion' | |
require 'utility_belt' | |
require 'interactive_editor' | |
require 'awesome_print' | |
AwesomePrint.irb! | |
class Object | |
def interesting_methods |
This file contains hidden or 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 expn(a, b) | |
a = a.to_r | |
b = b.to_i | |
d = 1.to_r | |
while(b > 0) | |
d *= a if (b % 2 == 1) | |
b /= 2 | |
a *= a if (b > 0) | |
d = d.round(100) |
This file contains hidden or 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 'json' | |
require 'PP' | |
class Player | |
attr_accessor :name, :assists, :goals, :saves, :score, :shots, :teamID | |
def initialize(stats) | |
@name = stats['Name']['value']['str'] | |
@assists = stats['Assists']['value']['int'] | |
@goals = stats['Goals']['value']['int'] | |
@saves = stats['Saves']['value']['int'] |
This file contains hidden or 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 Point | |
attr_accessor :x, :y | |
def initialize(x, y) | |
@x = x | |
@y = y | |
end | |
def ==(point) | |
return (@x == point.x and @y == point.y) | |
end |