Skip to content

Instantly share code, notes, and snippets.

View defuse's full-sized avatar
🔬

Taylor Hornby defuse

🔬
View GitHub Profile
@defuse
defuse / gist:6375486
Last active December 21, 2015 22:29
Solution!
def factorial(n)
product = 1
1.upto(n) do |k|
product *= k
end
return product
end
def choose(n,k)
@defuse
defuse / gist:6374037
Created August 29, 2013 03:44
N boxes numbered 1..N. N balls numbered 1..N. How many ways can balls be put into boxes so that each ball's # is different from its box #?
#!/usr/bin/env ruby
#
# There are N boxes numbered 1 to N. There are N balls numbered 1 to N.
# Balls can be put into boxes. How many ways can you put each ball in a box so
# that each ball's number is *different* from the number of the box it's in?
#
# Example for N=3:
#
# RIGHT:
#
@defuse
defuse / gist:6149343
Last active December 20, 2015 14:49
#!/usr/bin/env ruby
# Here's an EXTREMELY abstract environment where oi.js is broken.
# Assumptions:
# - There are no asynchronous interupts
# - Each line of javascript code takes 1 unit of time.
# - The context switching quantum is 10
# - millis() changes on every context switch.
# - millis() ONLY changes during a context switch.
#
# Under these assumptions, let Q be the time remaining before the :wmlt loop
# Little program for testing return from interrupt privilege check.
.intel_syntax noprefix
.text
.global main
main:
# Print the CS
mov eax, cs
push eax