This file contains hidden or 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 factorial(n) | |
product = 1 | |
1.upto(n) do |k| | |
product *= k | |
end | |
return product | |
end | |
def choose(n,k) |
This file contains hidden or 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
#!/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: | |
# |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
# Little program for testing return from interrupt privilege check. | |
.intel_syntax noprefix | |
.text | |
.global main | |
main: | |
# Print the CS | |
mov eax, cs | |
push eax |
NewerOlder