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
############################# | |
#hello.rb | |
def hello | |
"Hello!" | |
end | |
def greet name | |
"Hello, " + name + "!" | |
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
#Author: Max Plomer, maxplomer@gmail.com | |
#About the code: This code combines many ruby files into one document, does some formatting (such as: prints each file name, removing whitespace at bottom of each file), it either removes or keeps comments. Then uploads to your github account as a public gist. Also a file called combined.rb is created in the folder that is same file uploaded to gist. The public gist is opened in your web browser. Installation of the gist gem is necessary using command: $ gem install gist | |
#About the input.txt file: This code uses an input file input.txt in the same directory, with first line containing the gist name, 2nd line whether or not you want comments, and the rest of the lines are the paths of the ruby files you want to combine relative to the location of this code (or just write out the entire path) | |
######sample input.txt file####### | |
#gist_name: homework_solutions | |
#keep_comments: false | |
#learn_ruby/00_hello/hello.rb |
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 binarylist(choices) | |
list = Array.new(2**choices) | |
(2**choices).times do |x| | |
list[x]=[] | |
choices.times do |y| | |
if (x & 2**y)!=0 | |
list[x] << 1 | |
else | |
list[x] << 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
def marbles(n, k) | |
free = n - k | |
if free == 0 | |
return 1 | |
end | |
combos = Array.new(k,1) | |
(free-1).times do | |
(k-1).downto(1) do |x| | |
combos[x] = combos[0..x].inject(:+) | |
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
class Integer | |
def isabundant? | |
sum_of_proper_divisors(self) > self | |
end | |
end | |
def sum_of_proper_divisors(num) #borrowed from github user mlsimpson | |
orig = num | |
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
[1] pry(main)> x = Proc.new {|i| puts i} | |
=> #<Proc:0x007fa46aa60188@(pry):1> | |
[2] pry(main)> [1,2,3].map(&x) | |
1 | |
2 | |
3 | |
=> [nil, nil, nil] | |
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
####### install Git ########## | |
Use install Git section of Pro Git | |
can install from graphical Git installer or Macports | |
http://sourceforge.net/projects/git-osx-installer/ | |
Note: I'm fine with my Git version |
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 sum_of_pairs(arr) | |
max_length = 0 #max length of subset | |
#go through all subsets | |
for i in 0..(arr.size - 2) | |
for j in (i + 1)..(arr.size - 1) | |
sub_arr = arr[i..j] | |
sub_arr_length = sub_arr.length | |
if is_good?(sub_arr) | |
max_length = sub_arr_length if sub_arr_length > max_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 argv_test | |
filename = ARGV.shift | |
game_save = File.readlines(filename) | |
p game_save | |
x = gets.chomp | |
p x | |
end | |
argv_test |
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
class Employee | |
attr_accessor :name, :title, :salary, :boss | |
def initialize | |
@name | |
@title | |
@salary | |
@boss | |
end |
OlderNewer