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

UDPClient only receives one datagram
How to perform “nslookup host server”
How to modify my App.exe.config keys at runtime?
Show years on combo
WCF Authentication NT Challenge response
Application's monitor/screen changed event?
Why is it recommended to check string length to determine emptiness?
Invoking a method by multiple threads concurrently and report progress of each thread
What's the best way to protect all actions from a Controller except one (Login)?
C# detect where user clicked on a image/Bitmap
Computer Telephony Integration Softphone Architectural Question
How to get range from excel binary data stored in db
Strange webserver exception after patching web farm
Problem in MaskedTextbox using for Persian date input
resizing my image using GetThumbImage method C#
Can you control any other parameter when using log4net?

Categories

HOME
airflow
google-cloud-pubsub
botframework
ide
virtual-machine
weblogic
snappy
apache-storm
nagios
azure-database-mysql
magento-1.9.2.1
where
assign
bitbucket
esxi
sugarcrm
browser-cache
uml-designer
flowtype
subprocess
openbsd
guidewire
camunda
luis
filehelpers
google-calendar-api3
url-parameters
datasource
formulas
inline-assembly
procedural-generation
chartist.js
continuous-fourier
traveling-salesman
android-6.0-marshmallow
multiple-inheritance
custom-fields
spring-data-gemfire
mplab
jcr
pymunk
android-databinding
scip
yelp
framebuffer
pygraphviz
aspose.pdf
ssdp
socketcluster
google-cloud-powershell
java-5
ionic2-select
ng-class
cloudconvert
gige-sdk
kendo-scheduler
dmalloc
cedar-bdd
easy68k
git-push
access-violation
x12
class-design
vitamio
nsoperationqueue
sqlxml
web-performance
wiql
ios8-share-extension
commercetools
producer-consumer
mojolicious
notice
updating
properties-file
winforms-interop
xml-simple
eula
valdr-bean-validation
genero
wingdb
touch-typing
shunting-yard
static-files
fiware-health
pysvn
javadb
fxmlloader
formbuilder
sat4j
banana-pi
hotlinking
yandex-api
enquire.js
nodeunit
code-complete
sygic
oc4j
angularjs-select2
usersettings
kademlia
latex-suite
http-compression
nsautoreleasepool
zepto
qt5.1
django-1.4
diazo
optimistic-concurrency
sqlbuddy
advanceddatagrid
stl-algorithm
datejs
cryptolicensing
lgpl
uccapi
projectgen
moores-law

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile