Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Executable-library/Limbo/executable-library-1.limbo
Normal file
53
Task/Executable-library/Limbo/executable-library-1.limbo
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
implement Execlib;
|
||||
|
||||
include "sys.m"; sys: Sys;
|
||||
include "draw.m";
|
||||
|
||||
Execlib: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
hailstone: fn(i: big): list of big;
|
||||
};
|
||||
|
||||
init(nil: ref Draw->Context, nil: list of string)
|
||||
{
|
||||
sys = load Sys Sys->PATH;
|
||||
|
||||
seq := hailstone(big 27);
|
||||
l := len seq;
|
||||
|
||||
sys->print("hailstone(27): ");
|
||||
for(i := 0; i < 4; i++) {
|
||||
sys->print("%bd, ", hd seq);
|
||||
seq = tl seq;
|
||||
}
|
||||
sys->print("⋯");
|
||||
|
||||
while(len seq > 4)
|
||||
seq = tl seq;
|
||||
|
||||
while(seq != nil) {
|
||||
sys->print(", %bd", hd seq);
|
||||
seq = tl seq;
|
||||
}
|
||||
sys->print(" (length %d)\n", l);
|
||||
|
||||
max := 1;
|
||||
maxn := big 1;
|
||||
for(n := big 2; n < big 100000; n++) {
|
||||
cur := len hailstone(n);
|
||||
if(cur > max) {
|
||||
max = cur;
|
||||
maxn = n;
|
||||
}
|
||||
}
|
||||
sys->print("hailstone(%bd) has length %d\n", maxn, max);
|
||||
}
|
||||
|
||||
hailstone(i: big): list of big
|
||||
{
|
||||
if(i == big 1)
|
||||
return big 1 :: nil;
|
||||
if(i % big 2 == big 0)
|
||||
return i :: hailstone(i / big 2);
|
||||
return i :: hailstone(big 3 * i + big 1);
|
||||
}
|
||||
45
Task/Executable-library/Limbo/executable-library-2.limbo
Normal file
45
Task/Executable-library/Limbo/executable-library-2.limbo
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
implement ExecsExeclib;
|
||||
|
||||
include "sys.m"; sys: Sys;
|
||||
include "draw.m";
|
||||
|
||||
ExecsExeclib: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
};
|
||||
|
||||
# Usually, this would be placed into something like "execlib.m",
|
||||
# but it's fine here.
|
||||
Execlib: module {
|
||||
hailstone: fn(i: big): list of big;
|
||||
};
|
||||
|
||||
init(nil: ref Draw->Context, nil: list of string)
|
||||
{
|
||||
sys = load Sys Sys->PATH;
|
||||
# This program expects that the result of compiling Execlib is execlib.dis,
|
||||
# so you'll need to adjust this line if you used a different filename.
|
||||
lib := load Execlib "execlib.dis";
|
||||
if(lib == nil)
|
||||
die("Couldn't load execlib.dis");
|
||||
|
||||
counts := array[352] of { * => 0 };
|
||||
for(i := 1; i < 100000; i++) {
|
||||
counts[len lib->hailstone(big i)]++;
|
||||
}
|
||||
|
||||
max := 0;
|
||||
maxi := 0;
|
||||
for(i = 1; i < len counts; i++) {
|
||||
if(counts[i] > max) {
|
||||
max = counts[i];
|
||||
maxi = i;
|
||||
}
|
||||
}
|
||||
sys->print("The most common sequence length is %d (encountered %d times)\n", maxi, max);
|
||||
}
|
||||
|
||||
die(s: string)
|
||||
{
|
||||
sys->fprint(sys->fildes(2), "runls: %s: %r", s);
|
||||
raise "fail:errors";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue