import _ from 'underScore'
import Utils from '../lib/utils.js'
function evenOline(n) {
if(n === 0) {
return true
} else {
return Utils.partial(oddOline, Math.abs(n) - 1)
}
}
function oddOline(n) {
if(n === 0) {
return false
} else {
return Utils.partial(evenOline, Math.abs(n) - 1)
}
}
console.log(evenOline(0))
console.log(oddOline(0))
console.log(evenOline(2))
console.log(evenOline(2)())
console.log(evenOline(2)()())
console.log(oddOline(2))
console.log(oddOline(2)())
console.log(oddOline(2)()())
function trampoline(fun, ...args) {
let ret = fun.apply(fun, args)
while(_.isFunction(ret)) {
ret = ret()
}
return ret
}
console.log(trampoline(oddOline, 3))
console.log(trampoline(evenOline, 200000))
console.log(trampoline(oddOline, 300000))
function isEvenSafe(n) {
if(n === 0) {
return true
} else {
return trampoline(Utils.partial(oddOline, Math.abs(n) - 1))
}
}
function isOddSafe(n) {
if(n === 0) {
return false
} else {
return trampoline(Utils.partial(evenOline, Math.abs(n) - 1))
}
}
console.log(
isEvenSafe(2000),
isOddSafe(2000)
)