Jeff Dwyer jdwyah

View 0_reuse_code.js
1 2
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View monopoly.rb
1 2 3 4 5 6 7 8 9 10
require 'ruby-debug'
 
NUM_SQUARES = 40
JAIL = 10
GOTO_JAIL = 30
DOUBLE_MAX = 3
 
MONTE = 4
TOTAL_MOVES = 1
GUESTS = 30
View results.rb
1 2 3 4 5 6 7 8 9 10
names.each_with_index do |name, i|
z = zipped[i].sort
avg = z.inject{ |sum, el| sum + el }.to_f / z.size
index = (MONTE * 0.95).to_i
 
if(HUMAN)
puts "Avg servings #{avg} 95th pct #{z[index]} max #{z[-1]} #{name}"
else
puts "\"#{name}\", #{avg}, #{z[index]}, #{z[-1]}"
end
View zipped.rb
1
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 3], [0, 2, 1, 3], [3, 0, 2, 4], [3, 4, 3, 5], [4, 2, 3, 2], [5, 3, 4, 3], [5, 10, 7, 5], [3, 2, 5, 2], [2, 3, 1, 2], [3, 3, 3, 1], [2, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
View zip.rb
1 2
zipped = SQUARES.shift
zipped = zipped.zip(*SQUARES)
View squares.rb
1
[[0, 0, 0, 0, 3, 3, 4, 5, 5, 3, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 4, 2, 3, 10, 2, 3, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 2, 3, 3, 4, 7, 5, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 3, 4, 5, 2, 3, 5, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
View names.rb
1 2 3 4 5
names = ["Go",
"Mediterranean Avenue (Purple)",
"Community Chest",
"Baltic Avenue (Purple)",
"Income Tax", ...
View setup.rb
1 2 3 4 5 6
MONTE = 100000
NUM_SQUARES = 40
SQUARES = []
MONTE.times do
SQUARES << [0] * NUM_SQUARES
end
View loop.rb
1 2 3 4 5
MONTE.times do |m|
GUESTS.times do |i|
move(m, 0, TOTAL_MOVES, 0)
end
end
View move.rb
1 2 3 4 5 6 7 8 9 10
def move(curMonte, space, moves, doubles)
dieOne = rand(6) + 1
dieTwo = rand(6) + 1
doubles += 1 if dieOne == dieTwo
nextSpace = (space + dieOne + dieTwo) % NUM_SQUARES
SQUARES[curMonte][nextSpace] += 1
if moves > 1
move(curMonte, nextSpace, moves - 1, doubles)
end
end
Something went wrong with that request. Please try again.