March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -3,8 +3,7 @@ import std.stdio, std.bigint, std.conv;
|
|||
BigInt ipow(BigInt base, BigInt exp) pure /*nothrow*/ {
|
||||
auto result = 1.BigInt;
|
||||
while (exp) {
|
||||
//if (exp & 1)
|
||||
if (exp % 2)
|
||||
if (exp & 1)
|
||||
result *= base;
|
||||
exp >>= 1;
|
||||
base *= base;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
sub A(Int $m, Int $n) {
|
||||
|
||||
$m == 0 ?? $n + 1 !!
|
||||
$n == 0 ?? A($m - 1, 1 ) !!
|
||||
A($m - 1, A($m, $n - 1));
|
||||
|
||||
if $m == 0 { $n + 1 }
|
||||
elsif $n == 0 { A($m - 1, 1) }
|
||||
else { A($m - 1, A($m, $n - 1)) }
|
||||
}
|
||||
|
|
|
|||
15
Task/Ackermann-function/Rust/ackermann-function.rust
Normal file
15
Task/Ackermann-function/Rust/ackermann-function.rust
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// works for Rust 0.9
|
||||
fn main() {
|
||||
let a: int = ack(3, 4); // 125
|
||||
println!("{}", a.to_str());
|
||||
}
|
||||
|
||||
fn ack(m: int, n: int) -> int {
|
||||
if m == 0 {
|
||||
n + 1
|
||||
} else if n == 0 {
|
||||
ack(m - 1, 1)
|
||||
} else {
|
||||
ack(m - 1, ack(m, n - 1))
|
||||
}
|
||||
}
|
||||
23
Task/Ackermann-function/TXR/ackermann-function.txr
Normal file
23
Task/Ackermann-function/TXR/ackermann-function.txr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
@(do
|
||||
(defmacro defmemofun (name (. args) . body)
|
||||
(let ((hash (gensym "hash-"))
|
||||
(argl (gensym "args-"))
|
||||
(hent (gensym "hent-"))
|
||||
(uniq (copy-str "uniq")))
|
||||
^(let ((,hash (hash :equal-based)))
|
||||
(defun ,name (,*args)
|
||||
(let* ((,argl (list ,*args))
|
||||
(,hent (inhash ,hash ,argl ,uniq)))
|
||||
(if (eq (cdr ,hent) ,uniq)
|
||||
(set (cdr ,hent) (block ,name (progn ,*body)))
|
||||
(cdr ,hent)))))))
|
||||
|
||||
(defmemofun ack (m n)
|
||||
(cond
|
||||
((= m 0) (+ n 1))
|
||||
((= n 0) (ack (- m 1) 1))
|
||||
(t (ack (- m 1) (ack m (- n 1))))))
|
||||
|
||||
(each ((i (range 0 3)))
|
||||
(each ((j (range 0 4)))
|
||||
(format t "ack(~a, ~a) = ~a\n" i j (ack i j)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue