Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,7 @@
#ifndef HAILSTONE
#define HAILSTONE
long hailstone(long, long**);
void free_sequence(long *);
#endif/*HAILSTONE*/

View 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);
}

View 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;
}