Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Executable-library/C/executable-library-1.c
Normal file
7
Task/Executable-library/C/executable-library-1.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef HAILSTONE
|
||||
#define HAILSTONE
|
||||
|
||||
long hailstone(long, long**);
|
||||
void free_sequence(long *);
|
||||
|
||||
#endif/*HAILSTONE*/
|
||||
44
Task/Executable-library/C/executable-library-2.c
Normal file
44
Task/Executable-library/C/executable-library-2.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
long hailstone(long n, long **seq)
|
||||
{
|
||||
long len = 0, buf_len = 4;
|
||||
if (seq)
|
||||
*seq = malloc(sizeof(long) * buf_len);
|
||||
|
||||
while (1) {
|
||||
if (seq) {
|
||||
if (len >= buf_len) {
|
||||
buf_len *= 2;
|
||||
*seq = realloc(*seq, sizeof(long) * buf_len);
|
||||
}
|
||||
(*seq)[len] = n;
|
||||
}
|
||||
len ++;
|
||||
if (n == 1) break;
|
||||
if (n & 1) n = 3 * n + 1;
|
||||
else n >>= 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void free_sequence(long * s) { free(s); }
|
||||
|
||||
const char my_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
|
||||
/* "ld-linux.so.2" should be whatever you use on your platform */
|
||||
|
||||
int hail_main() /* entry point when running along, see compiler command line */
|
||||
{
|
||||
long i, *seq;
|
||||
|
||||
long len = hailstone(27, &seq);
|
||||
printf("27 has %ld numbers in sequence:\n", len);
|
||||
for (i = 0; i < len; i++) {
|
||||
printf("%ld ", seq[i]);
|
||||
}
|
||||
printf("\n");
|
||||
free_sequence(seq);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
20
Task/Executable-library/C/executable-library-3.c
Normal file
20
Task/Executable-library/C/executable-library-3.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include "hailstone.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long i, longest, longest_i, len;
|
||||
|
||||
longest = 0;
|
||||
for (i = 1; i < 100000; i++) {
|
||||
len = hailstone(i, 0);
|
||||
if (len > longest) {
|
||||
longest_i = i;
|
||||
longest = len;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Longest sequence at %ld, length %ld\n", longest_i, longest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue