Author Topic: Re: fibonacci numbers [SOLVED]  (Read 926 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: fibonacci numbers [SOLVED]
« on: November 07, 2019, 03:02:46 pm »
That's amazing Ron! Simple equation to make such a neat sequence. I had to look up the meaning and found out that it's fairly simple:
Each number is the sum of the two preceding ones.

I noticed how your _DELAY works. People can use that or instead of that you can add an INPUT command for every 50 to give as much time as people need to look them over and then press Enter for the next ones. Like this:
Code: QB64: [Select]
  1. IF count = 50 THEN INPUT A$: count = 0
  2.  
But make sure you delete the _DELAY line first if you use that.





Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: fibonacci numbers [SOLVED]
« Reply #1 on: January 17, 2020, 08:38:22 am »
Fibonacci & Rosetta Code & WE

Code: QB64: [Select]
  1. 'Fibo11.bas
  2.  
  3. DECLARE FUNCTION fibonacci (n)
  4.  
  5. OPEN "fi.txt" FOR OUTPUT AS #1
  6.  
  7. FOR i = 1 TO 35
  8.     PRINT i, fibonacci(i)
  9.     PRINT #1, i, fibonacci(i)
  10.  
  11. FUNCTION fibonacci (n)
  12. IF (n <= 2) THEN
  13.     fibonacci = 1
  14.     fibonacci = fibonacci(n-1) + fibonacci(n-2)
Code: QB64: [Select]
  1. 'Fibo22.bas
  2.  
  3. DIM F(40): F(1) = 0: F(2) = 1
  4. OPEN "fifi.txt" FOR OUTPUT AS #1
  5.  
  6. FOR i = 3 TO 35
  7.     F(i) = F(i-1) + F(i-2)
  8.  
  9. FOR i = 1 TO 35
  10.     PRINT i, F(i)
  11.     PRINT #1, i, F(i)
Code: QB64: [Select]
  1. 'Fibo33.bas
  2.  
  3. DIM f1, f2, f3 AS DOUBLE
  4. f1 = 0: f2 = 1
  5.  
  6. OPEN "fififi.txt" FOR OUTPUT AS #1
  7. PRINT 1, f1: PRINT 2, f2
  8. PRINT #1, 1, f1: PRINT #1, 2, f2
  9.  
  10. FOR s = 3 TO 80
  11.     f3 = f2 + f1
  12.     PRINT s, f3: PRINT #1, s, f3
  13.     f1 = f2: f2 = f3
? first number is 0 or 1 ?
Code: [Select]
1             1
2             1
3             2
4             3
5             5
6             8
7             13
8             21
9             34
10            55
11            89
12            144
13            233
14            377
15            610
16            987
17            1597
18            2584
19            4181
20            6765
21            10946
22            17711
23            28657
24            46368
25            75025
26            121393
27            196418
28            317811
29            514229
30            832040
31            1346269
32            2178309
33            3524578
34            5702887
35            9227465

Fibonacci n-step number sequences
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences

Fibonacci sequence
http://rosettacode.org/wiki/Fibonacci_sequence   
http://rosettacode.org/wiki/Fibonacci_sequence#QBasic

Fibonacci word
http://rosettacode.org/wiki/Fibonacci_word
« Last Edit: January 18, 2020, 04:44:25 pm by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: fibonacci numbers [SOLVED]
« Reply #2 on: January 17, 2020, 10:11:03 am »
here are the first 9 Fibonacci numbers
Code: [Select]
'https://www.futilitycloset.com/2015/06/28/made-to-order-4/
n# = 9899
r# = 1000 / n#
f$ = STR$(r#)
f$ = "000" + MID$(f$, 3)
FOR i = 1 TO 18 STEP 2
    PRINT MID$(f$, i, 2)
NEXT
with multi-precision arithmetic this can be expanded to give more numbers
the reason for dividing 1000 by n instead of 1 by n is to avoid exponential notation in the string f
« Last Edit: January 17, 2020, 10:16:34 am by jack »

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: fibonacci numbers [SOLVED]
« Reply #3 on: January 18, 2020, 05:36:12 pm »
Code: QB64: [Select]
  1. 'Fibo55.bas
  2.  
  3. DIM F(80) AS DOUBLE
  4. F(1) = 0: F(2) = 1
  5. OPEN "fifi55.txt" FOR OUTPUT AS #1
  6.  
  7. FOR i = 3 TO 80
  8.     F(i) = F(i - 1) + F(i - 2)
  9.  
  10. FOR i = 1 TO 80
  11.  
  12.     f$ = STR$(F(i))
  13.     lf = 22 - LEN(f$)
  14.  
  15.     n$ = ""
  16.     FOR j = 1 TO lf: n$ = " " + n$: NEXT
  17.     f$ = n$ + f$
  18.  
  19.     PRINT i, f$
  20.     PRINT #1, i, f$
  21.  
Code: [Select]
1                                 0
2                                 1
3                                 1
4                                 2
5                                 3
6                                 5
7                                 8
8                                13
9                                21
10                               34
11                               55
12                               89
13                              144
14                              233
15                              377
16                              610
17                              987
18                             1597
19                             2584
20                             4181
21                             6765
22                            10946
23                            17711
24                            28657
25                            46368
26                            75025
27                           121393
28                           196418
29                           317811
30                           514229
31                           832040
32                          1346269
33                          2178309
34                          3524578
35                          5702887
36                          9227465
37                         14930352
38                         24157817
39                         39088169
40                         63245986
41                        102334155
42                        165580141
43                        267914296
44                        433494437
45                        701408733
46                       1134903170
47                       1836311903
48                       2971215073
49                       4807526976
50                       7778742049
51                      12586269025
52                      20365011074
53                      32951280099
54                      53316291173
55                      86267571272
56                     139583862445
57                     225851433717
58                     365435296162
59                     591286729879
60                     956722026041
61                    1548008755920
62                    2504730781961
63                    4052739537881
64                    6557470319842
65                   10610209857723
66                   17167680177565
67                   27777890035288
68                   44945570212853
69                   72723460248141
70                  117669030460994
71                  190392490709135
72                  308061521170129
73                  498454011879264
74                  806515533049393
75                 1304969544928657
76                 2111485077978050
77                 3416454622906707
78                 5527939700884757
79                 8944394323791464
80            1.447233402467622D+16

fibonacci-like sequences?
https://www.qb64.org/forum/index.php?topic=2095.msg113280#msg113280

Fibonacci numbers my randomness tests won't pass
and twice fraud will be detected:
even\odd alternates and is first less than average

https://www.qb64.org/forum/index.php?topic=1976.30
« Last Edit: January 18, 2020, 05:41:45 pm by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself