home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
ddjmag
/
ddj9003.arc
/
SCHULMAN.LST
< prev
next >
Wrap
File List
|
1990-02-13
|
1KB
|
61 lines
INSIDE WATCOM C 7.0/386
by Andrew Schulman
[LISTING ONE]
$ PRIMES.SET
$ ISETL program to find number of primes <= n, using set notation
size := 1000 ;
sqrt_size := fix(sqrt(size)) ;
composites := {i*j : i in {3,5..sqrt_size}, j in {i..size div i}} ;
primes := {2} + {3,5..size} - composites ;
print size ;
print #primes ;
[LISTING TWO]]
$ PRIMES.TUP
$ ISETL program to find number of primes <= n, using ordered tuples
$ tuple difference operator
diff := func(t1, t2);
return [i : i in t1 | i notin t2 ] ;
end;
size := 1000 ;
sqrt_size := fix(sqrt(size)) ;
composites := [i*j : i in [3,5..sqrt_size], j in [i..size div i]] ;
primes := [2] + [3,5..size] .diff composites ;
print size ;
print #primes ;
[LISTING THREE]
$ FIB.TUP
$ ISETL program to find Fibonacci numbers, using dynamic programming
$ uses log(): only accurate up to 308 digits
digits := func(x);
if (x = 0) then return 1 ;
else return 1 + floor(log(abs(x))) ;
end;
end;
$ use "dynamic programming" to assign to fib()
fib := func(x);
fib(x) := fib(x-1) + fib(x-2) ;
return fib(x) ;
end;
fib(0) := 1 ;
fib(1) := 1 ;
fibonacci := [fib(x) : x in [1 .. 1000 ] ] ;
print fibonacci(1000) ;
print digits(fibonacci(1000)) ;