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

Binding combobox - WPF & C#
Suppress exception while querying documentDB
WPF treeview context menu
add ComboBox dynamically with Locations in UWP
In the result of the analysis of the SONARQUBE server does not show correctly the Total of lines of code and nor the errors of code
How do I refer to a control in a WPF nested ListView?
Not able to read an XML file in a directory?
ASPX Session State null exception on Postback
Selenium and Aurelia, how make test wait for the page to load and HTTP calls to complete
OpenQA.Selenium.ElementNotVisibleException' in WebDriver.dll while trying to click on the link
Add items to Listbox
How do use LParam in Pinvoke GlobalGetAtomName
Getting the Arizona Standard Time in .net
C# keydown event storing in char variables
Performance of for/while loop vs foreach loop on List<T>
UI not updating with NotifyPropetyChanged for datatable

Categories

HOME
kendo-ui
netty
virtual-machine
process
reference
mifare
spotfire
magento-1.9.2.1
redhawksdr
pandoc
query-string
xss
schema
qt4
activejdbc
resharper
android-notifications
orange
draw2d
gomobile
mattermost
concatenation
rvm
oracle-golden-gate
sha
gulp-jshint
angular2-changedetection
sqldependency
custom-fields
paper-trail-gem
openoffice-impress
undo
slim-lang
zimbra
dom4j
multi-user
file-conversion
aura-framework
firefox-developer-edition
smooth-streaming
piranha-cms
weld
runner
emacs24
jscoverage
hellosign
trusted-computing
catalyst
copy-constructor
android-tabs
racket-student-languages
papyrus
alfred
class-design
altova
avaudiorecorder
window.location
jmh
nd4j
calc
android-contentresolver
libgcrypt
redquerybuilder
first-order-logic
tooltwist
callfire
httpmodule
screen-lock
mri
google-experiments
crystal-reports-7
drawable
telerik-appbuilder
azure-caching
connections
facebook-java-api
nvcc
ie-developer-tools
forward-declaration
maven-webstart-plugin
string-length
reference-manual
quit
cryptarithmetic-puzzle
tasklist
wpml
big-endian
github-archive
optimistic-concurrency
wxperl
towerjs
scsf
windows-xp-embedded
noise-reduction
web-widget
file-storage
ihtmldocument2
opengl-to-opengles
user-preferences

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