Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created May 31, 2016 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikr7/b5f1ce9adb0319edadf2b187238b32ec to your computer and use it in GitHub Desktop.
Save ikr7/b5f1ce9adb0319edadf2b187238b32ec to your computer and use it in GitHub Desktop.
てきとう
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));
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