Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Executable-library/Pike/executable-library-1.pike
Normal file
39
Task/Executable-library/Pike/executable-library-1.pike
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env pike
|
||||
|
||||
int next(int n)
|
||||
{
|
||||
if (n==1)
|
||||
return 0;
|
||||
if (n%2)
|
||||
return 3*n+1;
|
||||
else
|
||||
return n/2;
|
||||
}
|
||||
|
||||
array(int) hailstone(int n)
|
||||
{
|
||||
array seq = ({ n });
|
||||
while (n=next(n))
|
||||
seq += ({ n });
|
||||
return seq;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
array(int) two = hailstone(27);
|
||||
if (equal(two[0..3], ({ 27, 82, 41, 124 })) && equal(two[<3..], ({ 8,4,2,1 })))
|
||||
write("sizeof(({ %{%d, %}, ... %{%d, %} }) == %d\n", two[0..3], two[<3..], sizeof(two));
|
||||
|
||||
mapping longest = ([ "length":0, "start":0 ]);
|
||||
|
||||
foreach(allocate(100000); int start; )
|
||||
{
|
||||
int length = sizeof(hailstone(start));
|
||||
if (length > longest->length)
|
||||
{
|
||||
longest->length = length;
|
||||
longest->start = start;
|
||||
}
|
||||
}
|
||||
write("longest sequence starting at %d has %d elements\n", longest->start, longest->length);
|
||||
}
|
||||
25
Task/Executable-library/Pike/executable-library-2.pike
Normal file
25
Task/Executable-library/Pike/executable-library-2.pike
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
void main()
|
||||
{
|
||||
.HailStone HailStone = .HailStone();
|
||||
|
||||
mapping long = ([]);
|
||||
|
||||
foreach (allocate(100000); int start; )
|
||||
long[sizeof(HailStone->hailstone(start))]++;
|
||||
|
||||
analyze(long);
|
||||
}
|
||||
|
||||
void analyze(mapping long)
|
||||
{
|
||||
mapping max = ([ "count":0, "length":0 ]);
|
||||
foreach (long; int length; int count)
|
||||
{
|
||||
if (count > max->count)
|
||||
{
|
||||
max->length = length;
|
||||
max->count = count;
|
||||
}
|
||||
}
|
||||
write("most common length %d appears %d times\n", max->length, max->count);
|
||||
}
|
||||
23
Task/Executable-library/Pike/executable-library-3.pike
Normal file
23
Task/Executable-library/Pike/executable-library-3.pike
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
void main()
|
||||
{
|
||||
mapping long = ([]);
|
||||
|
||||
foreach (allocate(100000); int start; )
|
||||
long[sizeof(.Hailstone.hailstone(start))]++;
|
||||
|
||||
analyze(long);
|
||||
}
|
||||
|
||||
void analyze(mapping long)
|
||||
{
|
||||
mapping max = ([ "count":0, "length":0 ]);
|
||||
foreach (long; int length; int count)
|
||||
{
|
||||
if (count > max->count)
|
||||
{
|
||||
max->length = length;
|
||||
max->count = count;
|
||||
}
|
||||
}
|
||||
write("most common length %d appears %d times\n", max->length, max->count);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue