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 bday = new Random().nextInt(365) | |
def uniq(n: Int) = (1 to n).map(_ => bday).distinct.size == n | |
def puniq(n: Int, c: Int = 1000000) = (1 to c).map(_ => uniq(n)).count(_ == true).toDouble / c |
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
# ~/.bashrc | |
alias g='git' | |
# ~/.gitconfig | |
[alias] | |
l = log | |
o = checkout | |
p = pull --rebase | |
s = status | |
c = commit |
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
javascript:(function(){var a=document.getElementsByClassName("gt ii adP adO");for(b in a){var e=a[b];e.innerHTML="<pre style=\"font-family:Consolas;font-size:9pt\">"+e.innerHTML.replace(/^\s*(\+.*)$/gm,"<span style=\"color:green\">$1</span>").replace(/^\s*(-.*)$/gm,"<span style=\"color:red\">$1</span>").replace(/^\s*(@@.*)$/gm,"<span style=\"color:blue\">$1</span>").replace(/<br>/g,"")+"</pre>";}}()); |
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
describe "Converting arabic numbers to roman numerals" do | |
{ | |
1 => "I", | |
2 => "II", | |
5 => "V" | |
#... | |
}.each_pair do |arabic, roman| | |
it "converts #{arabic} to #{roman}" do | |
expect(convert(arabic)).to eq(roman) | |
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
describe ("alive cells") { | |
val cell = Cell(Alive) | |
it ("should become Dead when there are 0 live neighbours") { | |
cell.next(0) should be (Cell(Dead)) | |
} | |
it ("should become Dead when there are 1 live neighbours") { | |
cell.next(1) should be (Cell(Dead)) | |
} | |
it ("should become Alive when there are 2 live neighbours") { | |
cell.next(2) should be (Cell(Alive)) |
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
describe ("alive cells") { | |
val cell = Cell(Alive) | |
Seq( | |
(0, Dead), | |
(1, Dead), | |
(2, Alive), | |
(3, Alive) | |
// ... | |
) foreach { case (count, state) => |
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
#!/usr/bin/python | |
import socket | |
import sys | |
if (len(sys.argv) != 2 or not sys.argv[1].isdigit()): | |
print 'Usage: listen <port>', | |
exit() | |
p = int(sys.argv[1]) | |
l = [] |
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
transpose :: [[a]] -> [a] -> [a] | |
transpose [] output = output | |
transpose input output = transpose | |
(filter (\x -> not (null x)) (map (\x -> tail x) input)) | |
(output ++ (map (\x -> head x) input)) | |
print (transpose [[1, 2, 3], [4, 5], [6, 7, 8]] []) | |
-- prints [1, 4, 6, 2, 5, 7, 3, 8] |
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 transpose[T](input: List[List[T]]) = { | |
def iter[T](input: List[List[T]], output: List[T]): List[T] = | |
if (input.isEmpty) output | |
else iter( | |
input map { _.tail } filter { !_.isEmpty }, | |
output ::: (input map { _.head }) | |
) | |
iter(input, 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
transpose :: [[a]] -> [a] | |
transpose [] = [] | |
transpose input = (map (\x -> head x) input) ++ | |
transpose (filter (\x -> not (null x)) (map (\x -> tail x) input)) |
OlderNewer