March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -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;

View file

@ -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)) }
}

View 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))
}
}

View 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)))))