Skip to content

Instantly share code, notes, and snippets.

View jdwyah's full-sized avatar

Jeff Dwyer jdwyah

View GitHub Profile
@jdwyah
jdwyah / 0_reuse_code.js
Created January 2, 2014 22:46
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
require 'ruby-debug'
NUM_SQUARES = 40
JAIL = 10
GOTO_JAIL = 30
DOUBLE_MAX = 3
MONTE = 4
TOTAL_MOVES = 1
GUESTS = 30
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
[[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]]
zipped = SQUARES.shift
zipped = zipped.zip(*SQUARES)
[[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]]
names = ["Go",
"Mediterranean Avenue (Purple)",
"Community Chest",
"Baltic Avenue (Purple)",
"Income Tax", ...
MONTE = 100000
NUM_SQUARES = 40
SQUARES = []
MONTE.times do
SQUARES << [0] * NUM_SQUARES
end
MONTE.times do |m|
GUESTS.times do |i|
move(m, 0, TOTAL_MOVES, 0)
end
end
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