Motorola 68000 montajı - 34 bayt
(GNU birleştirici sözdizimi)
| short min_fib_partition(long N asm("%d2"), long *out asm("%a0"))
min_fib_partition:
| Generate Fibonacci numbers on the stack (-1, 1, 0, 1, 1, 2, 3, ..., 1134903170).
moveq #-1, %d0 | A = -1
moveq #1, %d1 | B = 1
generate_loop:
move.l %d0, -(%sp) | Push A to the stack.
exg.l %d0, %d1 | A' = B
add.l %d0, %d1 | B' = A + B
bvc.s generate_loop | Stop when signed long overflows.
| Go back up the stack, partitioning N using the greedy algorithm.
moveq #0, %d0 | Initialize return value (number of terms).
subtract_loop:
move.l (%sp)+, %d1 | Pop a Fibonacci number F off the stack.
cmp.l %d1, %d2 | If N < F, continue to smaller Fibonacci number.
blt.s subtract_loop
addq.w #1, %d0 | Increment the term count.
move.l %d1, (%a0)+ | Append F to the output array.
sub.l %d1, %d2 | N -= F
bne.s subtract_loop | Continue if N has not yet reached zero.
| Clear the stack by searching for that -1.
clear_stack_loop:
tst.l (%sp)+
bge clear_stack_loop
done:
rts
36 → 34: Fibonacci jeneratörün sayımdan ziyade taşma üzerinde durması sağlandı ve 0kasayı [0]yerine çıkacak şekilde sabitledi []. Ancak, Nşimdi olumsuz bir çökme geçiyor .
En üstteki yorum, hangi parametrelerin nereye gittiğini belirlemek için bir dil uzantısı kullanan (varsayılan olarak yığına gider) bu işlevin C prototipidir .
Benim TI-89 , kendi 10MHz işlemcisi ile, 1 bu işlevi çalıştırmak için 5 dakika sürer - 1,000,000.
Makine kodu GolfScript çözümünden (şu anda) daha az bayt olmasına rağmen, bunu en kısa çözüm olarak kabul etmek haksızlık olur çünkü:
TI-89/92 / V200'ünüz varsa, projenin tamamını buradan indirebilirsiniz (eski):
https://rapidshare.com/files/154945328/minfib.zip
RapidShare'e gerçek dosyayı vermek için iyi şanslar. Herkes bu büyük dosyalar için iyi bir ana bilgisayar biliyor mu? 8940 çok fazla bayttır.