Created
May 23, 2017 17:26
-
-
Save ecancino/c92b6e67ae95391c77ec27d5829c2fa0 to your computer and use it in GitHub Desktop.
pascal
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
| 'use strict'; | |
| const { compose, curry, times, max, add, map, join, memoize } = require('ramda') | |
| const toFixed = curry((p, n) => Number(n.toFixed(p))) | |
| const format = compose(join('\n'), map(join(', ')), map(map(toFixed(3)))) | |
| const pascal = memoize((n, s = 1) => { | |
| const result = [[s]] | |
| times((n) => { | |
| const row = n + 1 | |
| result[row] = [] | |
| times((col) => { | |
| result[row][col] = add( | |
| max(0, result[row - 1][col]), | |
| max(0, result[row - 1][col - 1]) | |
| ) | |
| }, row + 1) | |
| }, n) | |
| return result | |
| }) | |
| const Φ = 1.618033988749894848204586834 | |
| const C = toFixed(10, Φ) | |
| console.log(format(pascal(10, C))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment