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

Enabling encryption in .NET sockets
Event fired when any child inside a form changes (is painted)?
Capture Screen But Not Current Form In C#?
Response.Redirect to next preceding sibling with umbraco.NodeFactory GetNodeByXpath from .net Usercontrol
C# Using directive - is there an overhead? [duplicate]
Which button pressed in flowlayoutpanel?
How to get a large amount of data in wcf without setting max buffer size
How can I make a C# UI remove Panel Controls using a button listener (basically)?
Exception in HttpResponseMessage for async POST method in .NET4.5
toggle button visibility not working
Mocking RouteData to test HtmlHelper RouteLink
How to write a generic ISort interface?
Comparing Sum Methods in C#
Pass Linq Expression to a function
nHibernate stored procedure call
Invalid authorization specification and Invalid connection string attribute

Categories

HOME
azure-active-directory
leaflet
oracle-sqldeveloper
ibm
singleton
bitbucket
sdk
liquidsoap
meson-build
pip
sahi
fine-uploader
logstash-configuration
bookmarklet
simd
alert
loader
legend-properties
autologin
scotty
beaker-notebook
infinite-loop
onclicklistener
devexpress-mvc
advertising
uipath
ps
gsuite
aws-certificate-manager
continuous-fourier
mex
boosting
federated
paper-trail-gem
edirectory
concrete5
deferred
imdb
scene7
dropdownbox
mkdir
aweber
border-layout
stochastic-process
console.readline
area
jquery-ui-slider
test-kitchen
django-cors-headers
reqif
togglebutton
hierarchical-clustering
automapper-4
jscoverage
openpgp.js
nservicebus6
node.js-client
esprima
consolidation
jspx
virtualenvwrapper
vitamio
angular-i18n
sqlxml
methodology
wordpress-plugin
jersey-test-framework
nslocalizedstring
google-finance-api
jquery-draggable
opendolphin
gnu-sort
updating
android-togglebutton
identifying
tess4j
eaaccessory
pagecontrol
xml-simple
cakephp-2.6
vectordrawable
tidesdk
chrome-mobile
alpha-beta-pruning
iphone-6
os.walk
conditional-comments
react-os
disparity-mapping
dotcmis
mvcgrid
debuggervisualizer
xps
elixir-framework
nop
grape-api
cab
violation
angularjs-select2
playing-cards
mandelbrot
dynamic-expresso
qmainwindow
beep
django-1.4
advanceddatagrid
capitalization
windows-xp-embedded
jexcelapi
mysql-pconnect
data-formats
cross-cutting-concerns

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App