-
-
Save ikr7/b5f1ce9adb0319edadf2b187238b32ec to your computer and use it in GitHub Desktop.
てきとう
This file contains 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
const succ = (a) => a + 1; | |
const pred = (a) => a - 1; | |
const add = (a, b) => { | |
if (b === 0) { return a; } | |
else { return add(succ(a), pred(b)); } | |
} | |
const mul = (a, b) => { | |
if (b === 0) { return 0; } | |
else { return add(a, mul(a, pred(b))); } | |
} | |
const pow = (a, b) => { | |
if (b === 0) { return 1; } | |
else { return mul(a, pow(a, pred(b))); } | |
} | |
console.trace(pow(21, 3)); |
This file contains 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
def succ (a) | |
return a + 1 | |
end | |
def pred (a) | |
return a - 1 | |
end | |
def add(a, b) | |
if (b == 0) then | |
return a | |
end | |
return add(succ(a), pred(b)) | |
end | |
def mul(a, b) | |
if (b == 0) then | |
return 0; | |
end | |
return add(a, mul(a, pred(b))) | |
end | |
def pow(a, b) | |
if (b == 0) then | |
return 1; | |
end | |
return mul(a, pow(a, pred(b))) | |
end | |
puts pow(21, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment