Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 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 = __hold(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_length(l) + 1);
|
||||
}
|
||||
|
||||
void
|
||||
max_hailstone(integer x)
|
||||
{
|
||||
integer e, i, m;
|
||||
record r;
|
||||
|
||||
m = 0;
|
||||
i = 1;
|
||||
while (i < x) {
|
||||
integer h, k, l;
|
||||
|
||||
h = i;
|
||||
l = 1;
|
||||
while (h ^ 1) {
|
||||
if (r_j_integer(k, r, itoa(h))) {
|
||||
l += k;
|
||||
break;
|
||||
} else {
|
||||
l += 1;
|
||||
h = __hold(h & 1, 3 * h + 1, h / 2);
|
||||
}
|
||||
}
|
||||
|
||||
r_f_integer(r, itoa(i), l - 1);
|
||||
|
||||
if (m < l) {
|
||||
m = l;
|
||||
e = i;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
o_form("hailstone sequence length for ~ is ~ long\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