Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
:FIBONACCI:
|
||||
#11 = 0
|
||||
#12 = 1
|
||||
Repeat(#1) {
|
||||
#10 = #11 + #12
|
||||
#11 = #12
|
||||
#12 = #10
|
||||
}
|
||||
Return(#11)
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// Fibonacci, unlimited precision.
|
||||
// input: #1 = n
|
||||
// return: fibonacci(n) in text register 10
|
||||
//
|
||||
:fibo_unlimited:
|
||||
if (#1 < 2) {
|
||||
Num_Str(#1, 10)
|
||||
return
|
||||
} else {
|
||||
Buf_Switch(Buf_Free)
|
||||
IC('0') IN
|
||||
IC('1') IN
|
||||
#10 = #1
|
||||
While (#10 > 1) {
|
||||
#12 = 0 // carry out
|
||||
#15 = 1 // column (ones, tens, hundreds...)
|
||||
Repeat (ALL) { // Sum all columns
|
||||
Line(-1) // n-1
|
||||
Goto_col(#15)
|
||||
if (At_EOL) { // all digits added
|
||||
break
|
||||
}
|
||||
#11 = Cur_Char - '0' + #12 // digit of (n-1) + carry
|
||||
Line(-1) // n-2
|
||||
Goto_Col(#15)
|
||||
if (!At_EOL) { // may contain fewer digits than n-1
|
||||
#11 += Cur_Char - '0'
|
||||
}
|
||||
Goto_Line(3) // sum
|
||||
EOL
|
||||
#12 = #11 / 10 // carry out
|
||||
Ins_Char((#11 % 10) + '0')
|
||||
#15++ // next column
|
||||
}
|
||||
if (#12) {
|
||||
Goto_Line(3)
|
||||
EOL
|
||||
Ins_Char(#12 + '0') // any extra digit from carry
|
||||
}
|
||||
BOF
|
||||
Del_Line(1) // Next n
|
||||
Line(1) EOL
|
||||
Ins_Newline
|
||||
#10--
|
||||
}
|
||||
Goto_Line(2) // Results on line 2
|
||||
}
|
||||
// Copy the results to text register 10 in reverse order
|
||||
Reg_Empty(10)
|
||||
While(!At_EOL) {
|
||||
Reg_Copy_Block(10, CP, CP+1, INSERT)
|
||||
Char()
|
||||
}
|
||||
Buf_Quit(OK)
|
||||
return
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#1 = Get_Num("n: ", STATLINE)
|
||||
Ins_Text("fibonacci(") Num_Ins(#1, LEFT+NOCR) Ins_Text(") = ")
|
||||
Call("fibo_unlimited")
|
||||
Reg_Ins(10) IN
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue