Fibonacci Number Generator UPDATE: See the last comment where I attached anything
For anyone that may need this:
The .vb is the source file, and the .exe is the generator itself.
@bibby
>expecting a reply because it says bibby is typing >bibby stops >no reply pls
>memetext
>no. >greentext*
I'd actually make it green, but latex is messed up :(
I was going to post mine but I can't find any of my code lol
post your wat? o.o
omg post it again I didn't get to see it D:
rofl wait no I had a fibonacci code thing in c++ with phi and stuff. really basic but yheah
Mine is basic too. Really basic. Lemme make an SS.
Anyway, here's the source code, if you don't feel like downloading it: `Imports System Imports System.Windows.Forms Imports Microsoft.VisualBasic #Region "Namespace" Namespace ExampleApp #Region "EntryPoint" Public Class EntryPoint Public Shared Sub Main(args As [String]()) System.Console.WriteLine("Now Executing Custom Application...") Dim FrmMain as New Form1 System.Windows.Forms.Application.Run(FrmMain) End Sub End Class #End Region #Region "FrmMain" Public Class Form1 Inherits System.Windows.Forms.Form Private Withevents Button1 as New Button Sub New() With Button1 .Text = "Generate Next Fibonacci Number" .Top = 30 .Left = 50 .Size = New System.Drawing.Size(200, 27) End With With Me .Text = "Fibonacci Numbers" .Size = New System.Drawing.Size(300, 120) .StartPosition = FormStartPosition.CenterScreen End With Me.Controls.Add(Button1) End Sub Dim First As Integer = 0 Dim FirstThing As Boolean = True Dim Second As Integer = 1 Dim FibNum As Integer = 1 Private Sub Button1_Click(Sender as Object, E as eventargs) Handles Button1.Click If FirstThing = True Then MsgBox(1, MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") FirstThing = False Else If FibNum >= 1836311903 Then MsgBox("That is as far as we can go without causing a stack overflow.", MsgBoxStyle.OkOnly, Title:="Sorry!") Else Fibnum = First + Second First = Second Second = FibNum MsgBox(FibNum, MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") End If End If End Sub End Class #End Region End Namespace #End Region 'Thank you for trying .net Simple Compiler`
Most of that was generated by the little portable compiler I was using. The actual part with the fibonacci numbers wasn't though.
rofl I found it. ty based god. nth fibonacci number.cpp //Write a function to compute the Nth fibonacci number. #include <iostream> #include <cmath> #include <vector> using namespace std; //the golden ratio phi = 1+sqrt(5)/2 //thus fsubn is similiar to 1/(sqrt(5))*(phi^(n+1)) void genNums (int ); int main() { int fibN = 0; cout << "which fibonacci number do you wish to calculate?\n"; cin >> fibN; double phi = ((1+sqrt(5))/2); double answer = (1/(sqrt(5)))*(pow(phi, fibN+1)); cout << answer << " is answer.\n"; genNums(fibN); return 0; } void genNums(int fibN) { int fibList[fibN]; fibList[0]=1,fibList[1]=1; for(int i=2;i<fibN;i++) { fibList[i] = fibList[i-2]+fibList[i-1]; } cout << "now manually generating all the way up to n\n"; for(int j=0;j<fibN;j++) cout << fibList[j] << " "; cout << endl << fibList[fibN-1]+fibList[fibN-2]; }
at some point though, this happens to avoid an error message:
Oh geez c++. And I'm not even doing it nearly the same as you are. Lol.
I have it done recursively too though lol int a=1,b=1,c=0,sum=0; vector<int> fibSeq(41); for(int i=0;i<40;i++) { c=a+b; a=b; fibSeq.push_back(a); fibSeq.push_back(b); b=c; } but I'm pretty sure this is broken. I've not gone back to check why
is fibSeq even a thing? o.o
no thats a code segment. fibseq is a vector (array basically) that holds the generated numbers. I believe it was written for this http://projecteuler.net/problem=2
o.
I think that I should maybe add more to my generator, but I dunno.
I don't like it because I have to click way too many times :)
:( I've improved it though. I added a line on the msgbox that tells you which # you're on (number 1, number 2, number 3, number 4, etc.) and I think I should maybe include the numbers that were added.
why not have a single button set off the sequence? Also instead of going till that error perhaps have it generate the amount of numbers the user requests
I would have a single button set off the whole thing, but that would be way too fast. I can do the other thing you said though, or take them to a specific number.
Actually, making the amount of numbers that the user requests would go with the first thing, which would be too fast. But, I'll let it take them to a specific number.
@bibby `If TextBox1.Text = "1" Then MsgBox("1" & Environment.Newline & "This is Fibonacci Number #1" & Environment.Newline & "This is the first number. Nothing was added.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") ElseIf TextBox1.Text = "2" Then MsgBox("1" & Environment.Newline & "This is Fibonacci Number #2" & Environment.Newline & "The numbers added to get this were 0 and 1.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") ElseIf TextBox1.Text = "3" Then MsgBox("2" & Environment.Newline & "This is Fibonacci Number #3" & Environment.Newline & "The numbers added to get this were 1 and 1.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") ElseIf TextBox1.Text = "4" MsgBox("3" & Environment.Newline & "This is Fibonacci Number #4" & Environment.Newline & "The numbers added to get this were 1 and 2.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") ElseIf TextBox1.Text = "5" MsgBox("5" & Environment.Newline & "This is Fibonacci Number #5" & Environment.Newline & "The numbers added to get this were 2 and 3.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") ElseIf TextBox1.Text = "6" MsgBox("8" & Environment.Newline & "This is Fibonacci Number #6" & Environment.Newline & "The numbers added to get this were 3 and 5.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") ElseIf TextBox1.Text = "7" MsgBox("13" & Environment.Newline & "This is Fibonacci Number #7" & Environment.Newline & "The numbers added to get this were 5 and 8.", MsgBoxStyle.Okonly, Title:= "Next Fibonacci Number") End If`
This requires so much code, but I can't think of a more efficient way to do it. :(
are there no loops in vb? pls learn real lang IT could probably be simplified using a loop that follows the usual logic of c=a+b; a=b; etc.
vb is a real language >.> and this is just putting a number in a textbox and pressing enter. It takes you to that number in the sequence (the 46th number being where the stack overflow generates)
I'm using "c=a+b; a=b;" for the button clicking, but I don't know how I'd incorporate it with the textbox, since you can go to literally any number.
vb.net also has BigIntegers (see system.numerics) but I was having a problem converting integers to BigIntegers.
Java has BigInts. I'm sure c++ and python are also "better" :) I dunno vb but i figured you would have a variable for the step number and just do all of the logic in that loop. I am tired so pls call me out if I'm being stupid. Step 1 The numbers we added to get here were 1+1. Then store 1 and 1+1 into some variable. step 2 The numbers we added to get here were 1 and 1+1 (variable). idk what im even writing rofl
u r being stuipd. heuheuehueheuheueheueheuhee
no im being noobie
for(int i=0;i<40;i++) { c=a+b; a=b; fibSeq.push_back(a); fibSeq.push_back(b); //output here b=c; } why not do it like that
I dunno the methods with fibSeq. Also, that looks like what I'm doing with button clicking pretty much. My problem is with jumping to certain numbers. I'll explain: User types 4 into the textbox. The 4th number of the series is 5. So, it would show the messagebox with 5, and what was added. I'm not sure how to do that without using strings, since no mathematical process was used, because there aren't other integers to grab. Just the number "5".
Thank you for this Based God.
#tybg
LOL^
What a fascinating addition to the discussion.
The .ico is for the program. Just thought about the fact that you'll need to edit the source for the icon to work :<
The update supports large numbers that go past the 46th number, and has a reset button.
computer science section is that way idiot
:( this is just a program to use for math D:
would've posted it in there, but it would have been drowned by the cheaters :<
This is why I told you to learn a real language nerd. Look at how much more condensed that code is.
Well, that's not what I'm trying to achieve. :* Btw, an overwhelming majority of the code is filtering out things from the textbox that aren't numbers.
You can build you own bigint system using an array. Each spot represents one digit. A few functions are needed to handle each of the operations.
Oh well. Why do that when I can use system.numerics? :3
Pfft. Hey, you can do it as a string too. It just takes more.
Dim Int As System.Numerics.Biginteger = 1874326589734625876489763249875623 Console.Write(Int.ToString)
No, no. I mean to write your own that uses strings it takes more.
But again, system.numerics.dll :3 Also, as a byproduct of the generator, which I was developing using a little portable compiler, I have created a new file type.
Here is said compiler (it's open source)
Since there weren't any configuration files or anything that it loaded, I decided to make one that stored all of the references in a project that immediately adds the references when it is loaded into the compiler.
here's the amazing format:
oops. Accidentally hit draw.
But one question... what does this have to do with OS Feedback?
Nothing, really. I had been informed around the time I had started on OS that this was an OK place to post off topic things, so that's my reason for posting this here :3
If I tried to post this in math, it would get drowned in a sea of cheaters/one use accounts/2nd grade math. If I posted it in Computer Science, no one would really care about any of it at all.
Comp Sci and @ tad are your friends!
Join our real-time social learning platform and learn together with your friends!