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
calculateDistribution = (results) -> | |
dict = {} | |
for res in results | |
prop = res.join('') | |
if dict.hasOwnProperty(prop) then dict[prop]++ else dict[prop]=1 | |
for key, value of dict | |
console.log key+":"+value | |
console.log "Sort by random" |
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
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ |
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
m = 673 | |
n = 7 | |
product = 0 | |
console.log "#{m} times #{n} by Ethiopian Multiplication\n" | |
while m >= 1 | |
product += n unless m % 2 == 0 | |
m = Math.floor(m / 2) | |
n = Math.floor(n * 2) |
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
# http://stackoverflow.com/a/13961420/44620 | |
class Sequence_tester | |
def self.max_running_sequence(arr_of_chararr) | |
reduced = [] | |
all_same_chars = [] | |
arr_of_chararr.each do |str| | |
arr = str.chars.to_a | |
if arr.all? {|c| c == arr.first} |
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
#CoffeScript | |
fib = (n, i=0, j=1) -> i=j+j=i for _ in [1..n] | |
fib(7) | |
=> [1, 1, 2, 3, 5, 8, 13] | |
#Ruby | |
fib = ->(n, i=0, j=1){(1..n).map{i=j+j=i}} | |
fib[7] | |
=> [1, 1, 2, 3, 5, 8, 13] |
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
class Array | |
alias_method :brackets, :[] | |
def [](*args) | |
return brackets(*args) if args.length != 3 | |
start, stop, step = *args | |
self.values_at(*(start...stop).step(step)) | |
end | |
end |
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
(0!+0!+0!)! = 6 | |
(1+1+1)! = 6 | |
2+2+2 = 6 | |
3*3-3 = 6 | |
√4+√4+√4 = 6 | |
5/5+5 = 6 | |
6-6+6 = 6 | |
7-7/7 = 6 | |
8-√√(8+8) = 6 | |
√9*√9-√9 = 6 |
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
require 'prime' | |
primes = Prime.lazy | |
n = 4 | |
loop do | |
n += 2 | |
prime1 = primes.next | |
prime2 = n - 1 | |
prime2 -= 2 until prime2.prime? |
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
require 'json' | |
require 'httpclient' | |
domain = "runkeeper.com" | |
sslhost = "https://#{domain}/" | |
host = "http://#{domain}/" | |
email, user, password = "[email protected]", "jonelf", "password" | |
client = HTTPClient.new | |
body = { '_eventName' => 'submit', 'redirectUrl' => '/index', 'failUrl' => '', 'email' => email, 'password' => password } |
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
Start_tags = {"*" => :emphasis, "{" => :footnote} | |
End_tags = {emphasis: "*", footnote: "}"} | |
Tags = Start_tags.keys.join | |
def split_by_paragraph(text, &block) | |
mode = Start_tags[text[0]] || :normal | |
if mode == :normal | |
index = text[1..-1].index /[#{Tags}]/ | |
if index.nil? | |
yield ({:type => mode, :content => text}) |