All Source For elastic |
Ackermann's Function |
// $Id: ackermann.elastic,v 1.0 2002/04/30 10:49:00 dada Exp $
package ackermann;
import basic;
import sys;
import array;
private function Ack( M, N )
{
if (M == 0) return( N + 1 );
if (N == 0) return( Ack(M - 1, 1) );
return( Ack(M - 1, Ack(M, (N - 1))) );
}
private n = 1;
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
basic.print("Ack(3,", n, "): ", Ack(3, n));
|
Fibonacci Numbers |
// $Id: fibo.elastic,v 1.0 2002/04/19 11:54:00 dada Exp $
package fibo;
import basic;
import sys;
import array;
private function fib( n )
{
if (n < 2) return(1);
return(fib(n-2) + fib(n-1));
}
private n = 1;
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
basic.print(fib(n));
|
Hash (Associative Array) Access |
// $Id: hash.elastic,v 1.0 2002/05/21 14:38:00 dada Exp $
package xhash;
import basic;
import sys;
import array;
import hash;
private n = 1;
private i;
private c = 0;
private X = %[];
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
for(i=1; i<=n; i++) {
X[basic.sprintf("%x", i)] = i;
}
for(i=n; i>0; i=i-1) {
if(hash.has_key(X, basic.sprintf("%d", i))) {
c = c + 1;
}
}
basic.print(c);
|
Heapsort |
// $Id: heapsort.elastic,v 1.0 2002/05/17 09:57:00 dada Exp $
package heapsort;
import basic;
import sys;
import array;
local IM = 139968;
local IA = 3877;
local IC = 29573;
private function gen_random( n )
{
static LAST = 42.0;
LAST = (LAST * IA + IC) % IM;
return(n * LAST / IM);
}
private function heapsort( n, ra )
{
local rra;
local i;
local j;
local l = (n / 2) + 1;
local ir = n;
while (1) {
if (l > 1) {
rra = ra[--l];
} else {
rra = ra[ir];
ra[ir] = ra[1];
if (--ir == 1) {
ra[1] = rra;
return;
}
}
i = l;
j = l * 2;
while (j <= ir) {
if ( (j < ir) && (ra[j] < ra[j+1]) ) {
j++;
}
if (rra < ra[j]) {
ra[i] = ra[j];
i = j;
j = j + i;
} else {
j = ir + 1;
}
}
ra[i] = rra;
}
}
private n = 1;
private i;
private result = 0;
private ary = #[];
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
for(i=1; i<=n; i++) {
ary[i] = gen_random(1.0);
}
heapsort(n, ary);
basic.print(ary[-1]);
|
Hello World |
// $Id: hello.elastic,v 1.0 2002/05/09 15:48:00 dada Exp $
package hello;
import basic;
basic.print("hello world\n");
|
Nested Loops |
// $Id: nestedloop.elastic,v 1.0 2002/04/30 10:56:00 dada Exp $
package nestedloop;
import basic;
import sys;
import array;
private n = 1;
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
private a, b, c, d, e, f, x = 0;
for (a=0; a<n; a++)
for (b=0; b<n; b++)
for (c=0; c<n; c++)
for (d=0; d<n; d++)
for (e=0; e<n; e++)
for (f=0; f<n; f++)
x++;
basic.print(x);
|
Random Number Generator |
// $Id: random.elastic,v 1.0 2002/05/09 15:36:00 dada Exp $
package random;
import basic;
import sys;
import array;
local IM = 139968;
local IA = 3877;
local IC = 29573;
private function gen_random( n )
{
static LAST = 42.0;
LAST = (LAST * IA + IC) % IM;
return(n * LAST / IM);
}
private n = 1;
private result = 0;
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
while(n--) {
result = gen_random(100.0);
}
basic.print(result);
|
Sieve of Erathostenes |
// $Id: sieve.elastic,v 1.0 2002/05/17 10:07:00 dada Exp $
package sieve;
import basic;
import sys;
import array;
private n = 1;
private i, k;
private result = 0;
private flags = #[];
private count;
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
while(n--) {
count = 0;
for (i=2; i <= 8192; i++) {
flags[i] = 1;
}
for (i=2; i <= 8192; i++) {
if (flags[i]) {
// remove all multiples of prime: i
for (k=i+i; k <= 8192; k=k+i) {
flags[k] = 0;
}
count++;
}
}
}
basic.print("Count: ", count);
|
String Concatenation |
// $Id: strcat.elastic,v 1.0 2002/05/09 17:22:00 dada Exp $
package strcat;
import basic;
import sys;
import array;
import string;
private n = 1;
private str = "";
if(array.length(sys.args) > 0) {
n = basic.int(sys.args[0]);
} else {
n = 1;
}
while(n--) {
str = str + "hello\n";
}
basic.print(string.length(str));
|