Skip to content

Instantly share code, notes, and snippets.

@LittleHelicase
Last active March 8, 2016 21:34
Show Gist options
  • Save LittleHelicase/20584f68434250948e0f to your computer and use it in GitHub Desktop.
Save LittleHelicase/20584f68434250948e0f to your computer and use it in GitHub Desktop.
// 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