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
/** | |
* A sloppy example on JavaScript curry function | |
* | |
* @author Vladimir Ivic <[email protected]> | |
* @github http://github.com/mancmelou | |
*/ | |
/** | |
* Here we are, the curried function definition | |
*/ |
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
# 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))) |
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
# 2013-07-29 | |
(0..9).reduce([]) { |sum, n| sum.push *[10-n]*(n+1) } | |