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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(baller, furnished, rent) | |
# This is going to evaluate to either true or false anyway, | |
# so we don't need to explicitly return true or false. | |
baller && (furnished || rent < 2100) | |
# Old clunky version | |
# if baller && (furnished || rent < 2100) # <--Put brackets around this bad boy |
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
# Find the maximum | |
def maximum(arr) | |
# My first method... Uses 0 as a default value, so | |
# kind of doesn't work for an array full of elements | |
# that are less than zero. | |
y = 0 | |
arr.each do |x| | |
if x > y | |
y = x |
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 'pry' | |
## Counts characters, omitting spaces | |
def char_count(target) | |
target = target.gsub(" ","") | |
tally = Hash.new(0) | |
target.each_char {|x| tally[x] += 1} | |
tally | |
end | |
puts char_count('Chi putao bu tu putao pi') |
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 "pry-nav" | |
##TODO: Refactor such that there is a "Player" class that has attributes for | |
## 'lives' and 'score,' put players in a "players" array and iterate through | |
## it to pass turns. | |
class Game | |
def initialize | |
@player_1_lives, |
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 newBottle(b, p) # b = number of bottles, t = type of trade | |
@bottle_tally += 1 | |
@bottlecaps += 1 | |
@emptybottles += 1 | |
@report = "F: #{@bottle_tally} E: #{@emptybottles} Caps: #{@bottlecaps}" | |
if p == true | |
puts "#{@report} New bottle purchased." | |
elsif p == false | |
puts "#{@report} New bottle redeemed." | |
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 'pry-nav' | |
module Can_fly | |
def initialize | |
@flight = "Hell yeah" | |
end | |
def can_fly? | |
true | |
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
contract NotFizzBuzz { | |
//By Garrett B | |
function selectionSort(uint[] x) returns (uint[]){ | |
uint length = x.length; | |
for (var i = 0; i < length-1; i++) { | |
for (var j = i; j < length; j++) { | |
if (x[i] > x[j]) { | |
uint a = x[i]; | |
uint b = x[j]; |
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
# Parses XML file with Nokogiri, | |
# removes text from all nodes, | |
# prints out new 'clean' file | |
# Change 'input.xml' to whatever | |
# file you want to scrub. | |
require 'nokogiri' | |
doc = File.open('input.xml') {|f| Nokogiri::XML(f)} | |
doc.traverse{|node| node.content = "" if node.class == Nokogiri::XML::Text} |
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
dsb = """Just a small town girl | |
Livin' in a lonely world | |
She took the midnight train goin' anywhere | |
Just a city boy | |
Born and raised in South Detroit | |
He took the midnight train goin' anywhere | |
A singer in a smokey room | |
The smell of wine and cheap perfume |