c#


Generating Fibonacci Sequence and creating subsets for it


I am trying to generate a Fibonacci sequence computed by starting with the array [ 0, 1 ] and each subsequent number is computed by adding the two numbers before it.
// E.g. 0, 1, [0 + 1 =] 1, [1 + 1 =] 2, [1 + 2 =] 3, [2 + 3 =] 5, and so on.
Two methods I am trying to implement are below however i am badly stuck in generating a subsets(GenerateSubset(params)). Any help would be really appreciable.
public IEnumerable<long> Generate()
{
int i, count, f1 = 0, f2 = 1, f3 = 0;
Console.Write("Enter the Limit : ");
count = int.Parse(Console.ReadLine());
Console.WriteLine(f1);
Console.WriteLine(f2);
for (i = 0; i <= count; i++)
{
f3 = f1 + f2;
Console.WriteLine(f3);
f1 = f2;
f2 = f3;
}
Console.ReadLine();
}
public Task<IEnumerable<long>> GenerateSubset(int fromIndex, int toIndex)
{
throw new NotImplementedException();
}
Below is the file containing the test cases which i am trying to pass by implementing those methods.
Test cases file:
[ drive.google.com/open?id=0B_6Eur5JYu9_MDNfelVKOWswRGs]
I think you want a logic for generating a subset of Fibonacci series. here is the logic i write in java. you can convert into c#.
int fibonacci(int x) {
if (x == 0)
return 0;
if (x == 1)
return 1;
return fibonacci(x-1)+fibonacci(x-2);
}
and second function which generates the subset is
List<Integer> GenerateSubset(int fromIndex, int toIndex) {
int first=fibonacci(fromIndex);
int second= fibonacci(fromIndex+1);
int third;
List<Integer> result= new ArrayList<Integer>();
result.add(first);
result.add(second);
for(int i= fromIndex+2;i<=toIndex-1;i++) {
third= first+second;
result.add(third);
first=second;
second=third;
}
return result;
}
It returs the list which contain the subset of fibonacci series.

Related Links

LIBSVM 'decision values' in C# LibSVMsharp library
Auto-generating documentation and Inheritence
Touch pad as mouse input control
How to get the depth of the parse tree of a sentence produced by OpenNLP?
dynamically populate paypal cart with all gridview contents
How are integer literals strored?
Exact search with list of values in LINQ
Catch the event whene the search of findcontrol is lunched
Read a txt file in C#
Display database values in textbox
How to extract data from an Excel file with C# / FileHelpers ExcelNPOIStorage
Watching a table in sql server using c#
OledbException row-00001 cannot allocate memory
Internal server error in Web Api controller
Editing a textbox using multi binding
How to take a picture with iOS camera and save the image to camera roll using Xamarin

Categories

HOME
actionscript-3
swift3
macros
abc
blob
bitbucket
query-string
mailchimp
terminal
sitemap
dcos
ethereum
fetch
jetbrains
hdf5
camunda
saucelabs
dat.gui
cucumberjs
audio-streaming
react-jsx
keystone
turn.js
combinations
tcpdf
oracle-golden-gate
policy
android-wear-2.0
datanucleus
jms-topic
xlib
multilanguage
language-detection
postgresql-9.6
microstrategy
http-proxy
intersection
javafxports
kdevelop
lighting
pygraphviz
scalamock
office-interop
amazon-rds-aurora
evaluation
flask-socketio
ear
runtime-permissions
dotnet-cli
enet
senti-wordnet
wicketstuff
robotc
alarmmanager
strtol
eclipse-mars
altova
netlink
cosign-api
kik
video-embedding
alchemy
pushwoosh
dcg
waterline
mergecursor
httpmodule
frisby.js
growl
xmlserializer
nest-initiative
drawable
nspopupbutton
behance-api
code-smell
internet-radio
imaplib
nop
google-voice
angularjs-select2
xrandr
extensibility
servicemanager
derived-class
hypertable
commonsware
umfpack
vectorwise
sessiontracking
moss2007-security
n2
lwp
text-manipulation
glassfish-embedded
carbon-emacs
jettison
stackless

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App