Sum a dimension N square matrix main and anti diagonal values.
Given the Matrix:
[ [ 1, 2, 3, 4]
, [ 5, 6, 7, 8]
, [ 9, 10, 11, 12]
, [13, 14, 15, 16]
]
const | |
composeN = (...fs) => x => | |
fs.reduceRight((x, f) => f(x), x) | |
, map = f => xs => | |
xs.map(f) | |
, reduce = f => xs => | |
xs.reduce(f) | |
/** | |
* Show Me the Evens - Show me the Odds | |
* Diana is learning to count and she just learned the difference between odds and even numbers. | |
* She wants to have some fun, so she picks a random number. | |
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input. | |
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input. | |
**/ | |
const | |
range = x => y => |
/** | |
* Show Me the Evens - Show me the Odds | |
* Diana is learning to count and she just learned the difference between odds and even numbers. | |
* She wants to have some fun, so she picks a random number. | |
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input. | |
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input. | |
**/ | |
function counting(x){ | |
return [...Array(x).keys()] |
const clamp = l => h => x => | |
x > h | |
? h | |
: x < l | |
? l | |
: x | |
const | |
ascend = i => xs => { | |
let |
const | |
composeN = (...fs) => y => | |
fs.reduceRight((x, f) => f(x), y) | |
, flatten = xs => | |
xs.reduce((acc, x) => acc.concat(x)) | |
, filter = pred => xs => | |
xs.filter(pred) | |
const | |
composeN = (...fs) => y => | |
fs.reduceRight((x, f) => f(x), y) | |
, concat = ys => xs => | |
xs.concat(ys) | |
, flatten = xs => | |
reduce(uncurry2(concat))(xs) |
const | |
id = x => | |
x | |
, always = x => () => | |
x | |
, not = prop => | |
!prop | |
Sum a dimension N square matrix main and anti diagonal values.
Given the Matrix:
[ [ 1, 2, 3, 4]
, [ 5, 6, 7, 8]
, [ 9, 10, 11, 12]
, [13, 14, 15, 16]
]