Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
58
Task/Hailstone-sequence/Aime/hailstone-sequence.aime
Normal file
58
Task/Hailstone-sequence/Aime/hailstone-sequence.aime
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
void
|
||||
print_hailstone(integer h)
|
||||
{
|
||||
list l;
|
||||
|
||||
while (h ^ 1) {
|
||||
lb_p_integer(l, h);
|
||||
h = h & 1 ? 3 * h + 1 : h / 2;
|
||||
}
|
||||
|
||||
o_form("hailstone sequence for ~ is ~1 ~ ~ ~ .. ~ ~ ~ ~, it is ~ long\n",
|
||||
l[0], l[1], l[2], l[3], l[-3], l[-2], l[-1], 1, ~l + 1);
|
||||
}
|
||||
|
||||
void
|
||||
max_hailstone(integer x)
|
||||
{
|
||||
integer e, i, m;
|
||||
index r;
|
||||
|
||||
m = 0;
|
||||
i = 1;
|
||||
while (i < x) {
|
||||
integer h, k, l;
|
||||
|
||||
h = i;
|
||||
l = 1;
|
||||
while (h ^ 1) {
|
||||
if (i_j_integer(k, r, h)) {
|
||||
l += k;
|
||||
break;
|
||||
} else {
|
||||
l += 1;
|
||||
h = h & 1 ? 3 * h + 1 : h / 2;
|
||||
}
|
||||
}
|
||||
|
||||
r[i] = l - 1;
|
||||
|
||||
if (m < l) {
|
||||
m = l;
|
||||
e = i;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
o_form("hailstone sequence length for ~ is ~\n", e, m);
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
print_hailstone(27);
|
||||
max_hailstone(100000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue