Skip to content

Instantly share code, notes, and snippets.

View vividness's full-sized avatar

vividness vividness

  • San Francisco Bay Area
View GitHub Profile
# 2013-07-29
(0..9).reduce([]) { |sum, n| sum.push *[10-n]*(n+1) }
@vividness
vividness / biased_randomness.rb
Created August 22, 2013 21:26
Biased randomness with probability weights vector
# Work in progress
#
# This function generates the vector
#
# examples:
# [3, 2, 2, 1]
# [5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1]
def probability_weights_vector(n)
n.downto(1).reduce([]) { |ary, i|
ary.push(*([i] * (n -i + 1)))
@vividness
vividness / currying_example.js
Last active June 4, 2016 15:12
A sloppy example on JavaScript curry function
/**
* A sloppy example on JavaScript curry function
*
* @author Vladimir Ivic <[email protected]>
* @github http://github.com/mancmelou
*/
/**
* Here we are, the curried function definition
*/