Last active
March 8, 2016 21:34
-
-
Save LittleHelicase/20584f68434250948e0f to your computer and use it in GitHub Desktop.
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
// After | |
// Hutton, Graham. "A tutorial on the universality and expressiveness of fold." Journal of Functional Programming 9.04 (1999): 355-372. | |
// Lodash has no currying making it necessary to call a few partials. Fold is reduce in lodash and the order of | |
// the arguments is different. _.reduce(data, fn, initial) = fold(fn, inital, data) | |
var _ = require('lodash') | |
var ack = _.partial( | |
_.reduce, | |
_, | |
(g, x) => | |
_.partial(_.reduce, _, (xs, y) => g(xs), g([1])), | |
_.partial(_.concat, [1], _) | |
) | |
var arr = (n) => { | |
return Array.apply(null, Array(n)).map((n) => 1) | |
} | |
var ackn = (n,m) => { | |
return ack(arr(n))(arr(m)).length | |
} | |
console.log("ack(0,1):", ackn(0,1)) | |
console.log("ack(1,0):", ackn(1,0)) | |
console.log("ack(1,1):", ackn(1,1)) | |
console.log("ack(2,1):", ackn(2,1)) | |
console.log("ack(1,2):", ackn(1,2)) | |
console.log("ack(3,4):", ackn(3,4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment