search on: does fibonacci repeat
result:
"0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, ... Yes! It takes a while
before it is noticeable. In fact, the series is just 60 numbers long and then
it repeats the same sequence again and again all the way through the Fibonacci
series - for ever."
that from:https://r-knott.surrey.ac.uk/Fibonacci/fibmaths.html#:~:text=Yes!,a%20cycle%20length%20of%2060.
To test I changed the target The concern for my useage of Fibonacci
###### Initial Step Of 1 ######
005 008 013 021 034 055 089 144 233 121 098 219
061 024 085 109 194 047 241 032 017 049 066 115
181 040 221 005 226 231 201 176 121 041 162 203
109 056 165 221 130 095 225 064 033 097 130 227
101 072 173 245 162 151 057 208 009 217 226 187
157 088 245 077 066 143 209 096 049 145 194 083
021 104 125 229 098 071 169 240 153 137 034 171
205 120 069 189 002 191 193 128 065 193 002 195
197 136 077 213 034 247 025 016 041 057 098 155
253 152 149 045 194 239 177 160 081 241 066 051
117 168 029 197 226 167 137 048 185 233 162 139
045 184 229 157 130 031 161 192 097 033 130 163
037 200 237 181 162 087 249 080 073 153 226 123
093 216 053 013 066 079 145 224 113 081 194 019
213 232 189 165 098 007 105 112 217 073 034 107
141 248 133 125 002 127 129 000 129 129 002 131
133 008 141 149 034 183 217 144 105 249 098 091
###### Initial Step Of 2 ######
007 011 018 029 047 076 123 199 066 009 075 084
159 243 146 133 023 156 179 079 002 081 083 164
247 155 146 045 191 236 171 151 066 217 027 244
015 003 018 021 039 060 099 159 002 161 163 068
231 043 018 061 079 140 219 103 066 169 235 148
127 019 146 165 055 220 019 239 002 241 243 228
215 187 146 077 223 044 011 055 066 121 187 052
239 035 018 053 071 124 195 063 002 065 067 132
199 075 018 093 111 204 059 007 066 073 139 212
095 051 146 197 087 028 115 143 002 145 147 036
183 219 146 109 255 108 107 215 066 025 091 116
207 067 018 085 103 188 035 223 002 225 227 196
167 107 018 125 143 012 155 167 066 233 043 020
063 083 146 229 119 092 211 047 002 049 051 100
151 251 146 141 031 172 203 119 066 185 251 180
175 099 018 117 135 252 131 127 002 129 131 004
135 139 018 157 175 076 251 071 066 137 203 084
###### Initial Step Of 3 ######
009 014 023 037 060 097 157 254 155 153 052 205
001 206 207 157 108 009 117 126 243 113 100 213
057 014 071 085 156 241 141 126 011 137 148 029
177 206 127 077 204 025 229 254 227 225 196 165
105 014 119 133 252 129 125 254 123 121 244 109
097 206 047 253 044 041 085 126 211 081 036 117
153 014 167 181 092 017 109 126 235 105 084 189
017 206 223 173 140 057 197 254 195 193 132 069
201 014 215 229 188 161 093 254 091 089 180 013
193 206 143 093 236 073 053 126 179 049 228 021
249 014 007 021 028 049 077 126 203 073 020 093
113 206 063 013 076 089 165 254 163 161 068 229
041 014 055 069 124 193 061 254 059 057 116 173
033 206 239 189 172 105 021 126 147 017 164 181
089 014 103 117 220 081 045 126 171 041 212 253
209 206 159 109 012 121 133 254 131 129 004 133
137 014 151 165 060 225 029 254 027 025 052 077
###### Count Of Fn Value Occurances ######
(first lines are Fn values)
(second lines are occurance counts)
(the sort is by decending count)
066 002 018 254 014 206 146 126 165 129 109 133 021 229 077 073
013 012 009 009 009 008 008 008 006 006 006 006 006 006 006 005
117 041 057 034 121 137 157 081 193 093 105 049 098 127 089 125
005 005 005 005 005 005 005 005 005 005 005 005 005 004 004 004
085 071 097 197 203 194 181 189 239 241 226 217 225 143 151 141
004 004 004 004 004 004 004 004 004 004 004 004 004 004 004 004
130 131 162 167 161 153 155 055 047 007 029 025 009 013 045 017
004 004 004 004 004 004 004 004 004 004 004 004 004 004 004 004
249 019 033 251 163 060 219 215 091 213 171 119 107 253 113 187
003 003 003 003 003 003 003 003 003 003 003 003 003 003 003 003
103 123 173 011 195 061 053 243 139 145 051 063 069 233 052 076
003 003 003 003 003 003 003 003 003 003 003 003 003 003 003 003
159 223 084 083 227 079 180 147 179 175 177 148 023 164 020 156
003 003 003 003 003 003 002 002 002 002 002 002 002 002 002 002
144 172 169 149 005 228 004 212 220 221 231 245 247 252 235 236
002 002 002 002 002 002 002 002 002 002 002 002 002 002 002 002
244 211 191 012 196 183 185 188 199 008 207 209 201 204 205 027
002 002 002 002 002 002 002 002 002 002 002 002 002 002 002 002
035 036 075 100 043 031 099 037 068 116 115 108 124 065 067 132
002 002 002 002 002 002 002 002 002 002 002 002 002 002 002 002
140 092 135 028 095 044 059 087 040 192 072 112 237 048 111 101
002 002 002 002 002 002 002 002 001 001 001 001 001 001 001 001
200 080 096 208 088 104 216 232 224 168 016 136 056 064 128 248
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001
024 152 032 160 039 255 015 184 003 240 000 176 120 001 222 078
001 001 001 001 001 001 001 001 001 001 001 001 001 001 000 000
054 006 050 242 074 234 238 070 250 058 062 230 246 082 122 038
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
166 170 178 182 174 118 158 138 150 142 026 030 022 154 134 094
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
090 202 210 218 086 214 046 102 110 190 114 186 010 198 106 042
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
Any key to close.
Colors in the above were added in HTML after running the code to point out the repeating numbers.
'File: testFibonacci.bas
'
'From: https://en.wikipedia.org/wiki/Fibonacci_sequence
'"In mathematics, the Fibonacci sequence is a sequence in which each element is
'the sum of the two elements that precede it. Numbers that are part of the
'Fibonacci sequence are known as Fibonacci numbers, commonly denoted Fn."
'[code]
#compile exe
#dim all
'demo runs in either PBWin 10 or PB
#if %def(%pb_cc32) 'ignore this in PBWin
#console off 'no uneeded console in PBCC
'if before PBCC, delete this and "txt."
'if before PBWin 10, concatenate PRINTs and $CRLFs
'and show in one MSGBOX, LABEL or TEXTBOX.
#endif
function pbmain () as long
local hTwin, Fn as dword
local ColNum, FnCnt, Cntr as long
local FnStr as string
txt.window("Demo/Test Fibonacci Function", 100,50, 40, 80) to hTWin
'Fn = Fn-1 + Fn-2 for n>2 is very unclear.
'Fn = F(n-1) + F(n-2) for n>2 clearER, but no subtraction is performed.
'Fn = the previous Fn + the FN before that.
'I found that n = 2 is 3 works with this method too.
'----------------------------------------------------- make base sequence ----
'That makes 1st and 2nd previouses at start as:
' n = 1
'For my purpose the 0 and first 1 of a complete sequence are not needed.
' print "Sequence shown on many web sites."
' print "It verifies the code used to generate Fibonacci sequences."
txt.color = &hFF0000
txt.print "Step size 1"
txt.color = &h000000
txt.print dec$(FibonacciNumber(1), 7, 0, 1); '1st call passes init step size
for Cntr = 2 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7, 0, 1) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7, 0, 1) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7) '8th number then new line
txt.print
txt.color = &hFF0000
txt.print "Step size 2"
txt.color = &h000000
txt.print dec$(FibonacciNumber(2), 7, 0, 1); '1st call passes init step size
for Cntr = 2 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7, 0, 1) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7, 0, 1) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7) '8th number then new line
txt.print
txt.color = &hFF0000
txt.print "Step size 3"
txt.color = &h000000
txt.print dec$(FibonacciNumber(3), 7, 0, 1); '1st call passes init step size
for Cntr = 2 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7, 0, 1) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7, 0, 1) '8th number then new line
for Cntr = 1 to 7
txt.print dec$(FibonacciNumber(0), 7, 0, 1);
next
txt.print dec$(FibonacciNumber(0), 7) '8th number then new line
txt.print
'==================
txt.color = &hFF0000
txt.print "Initial step size 255"
txt.color = &h000000
txt.print dec$(FibonacciNumber(255), 0, 0, 1);'1st call passes init step size
FnCnt = 1
do 'for Cntr = 2 to 60
ColNum = txt.col
Fn = FibonacciNumber(0)
FnStr = dec$(Fn, 0, 0, 1)
incr FnCnt
if Fn = 0 then
txt.print
txt.print
txt.print "Initial step size 255 overflows a DWOWD after" + _
dec$(FnCnt, 0, 1, 0) + "th number."
exit do
end if
if ColNum + len(FnStr) > 80 then txt.print
txt.print FnStr;
loop 'next
' txt.print
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
txt.print
txt.color = &h00B000
txt.print
txt.print "Any key to close."
txt.waitkey$
end function
'
'¯¯\/¯¯¯\/¯¯¯\/¯¯¯\/¯¯¯\/¯¯¯\/¯¯¯\/¯¯¯\/¯¯¯\/¯¯ code being demoed ¯\/¯¯¯\/¯¯¯\/¯
'
function FibonacciNumber(byval StepSz as dword) as dword
local Fn as dword
static Fn1Prev, Fn2Prev as dword
if StepSz then
Fn2Prev = -1 '0 '1
Fn1Prev = stepSz 'Fn2Prev + StepSz
end if
'continue afterwrap goes here
Fn = (Fn1Prev) + (Fn2Prev)
Fn2Prev = Fn1Prev
Fn1Prev = Fn
'test only
if Fn1Prev < Fn2Prev then
function = 0
exit function
end if
function = Fn
end function
Created on August 03, 2025
Done with this window?