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

how to use interface with singleton class
Repository and static methods
NHProf C# API — determine if profiler has been initialized
Visual Studio 2012 Architecture Tools UML Class Diagram Code Generation
Stored Value in Checkbox and Capture Submitted Values Checked
Select from list with list as property
multiple usercontrols in a page in jQuery
Can't get index of DataGridRow during button click event. Sometimes -1.
Microsoft Unity 3.0 DI with Lazy<List<IFoo>> does not work
Instantiating a delegate method to be used in a class library
Reading from a text file using C#
How can I group by Linq statement
When exactly is the MouseLeave event triggered?
How to enable a button only if a row is selected in DataGrid?
How Do I Properly Setup MySQLConnection in C#?
How to search data in database and add it to textboxes in C#? [closed]

Categories

HOME
qlikview
internet-explorer
typo3
oracle-sqldeveloper
fortran
packet
azure-eventhub
highmaps
magento-1.9.2.1
bitbucket
mingw
browser-cache
doctrine2
ephesoft
core-data
fetch
websharper
swift3.1
luis
accordion
sonarlint
keystone
connection-pooling
oracle-golden-gate
ps
suitescript
rollupjs
visual-studio-community
orgchart
resx
uibarbuttonitem
pypy
osgi-bundle
recreate
concrete5
mobile-development
ng2-bootstrap
qt-designer
tunnel
hippocms
stochastic-process
mongoid5
mapquest
vertical-alignment
php-mongodb
vpython
risc
gridgain
html-entities
ng-class
openidm
r-commander
programming-pearls
codesniffer
tsc
stringbuilder
cedar-bdd
computed-properties
foreground
mate-desktop
syslog4j
normalisation
oryx
apache2-module
angular-promise
webservices-client
javapackager
gitk
redquerybuilder
exchange-server-2007
pdcurses
euro
data-representation
stderr
autopep8
kss
report-builder2.0
agent-based-modeling
nspopupbutton
android-relativelayout
jsmpp
pthreads-win32
logo-lang
myrrix
pechkin
ia-32
maven-webstart-plugin
wpd
exi
qmainwindow
pageload
ftpwebrequest
algol
feincms
quit
django-admin-tools
joomla1.7
datejs
soapexception
method-call
auto-compile
object-tag
quazip
cinder
onunload
carbon-emacs
pixel-bender
data-formats
projectgen
high-load

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile