# A couple of tests I got given

#### Solarion

##### Honorary Master
I have done both of them already and didn't do terribly great with these two. Was told I failed on two key points and that was that!

C#:
`````` public static void Main(string[] args)
{

FixMe();

List<int> seq = GenerateFibonacciSequence(5, 1);
Console.WriteLine(string.Join<int>(",", seq));

seq = GenerateFibonacciSequence(11, 7);
Console.WriteLine(string.Join<int>(",", seq));

seq = GenerateFibonacciSequence(15, 0);
Console.WriteLine(string.Join<int>(",", seq));
}
//Fix this method, it does not need to return anything, just needs to be compile and be programmatically correct
public static void FixMe()
{
/*
int [] ints = new int[10];
int total = 0;
for (int i = 0; i <= 10; i++)
{
ints[i] = i + 5;
total += ints[i];
}

double number5 = double.parse("5,0");

string 1newstring='NewString'
*/
}

/* QUESTION
* A method that returns a list of intergers which is the Fibonacci Sequence. (http://en.wikipedia.org/wiki/Fibonacci_number)
* Parameter @numberOfSequences denotes how many sequences is returned. DONE
* EG if numberOfSequences = 5, it should return just a list with 5 items. DONE
* Parameter @ignoreNumber is a number from 0-9 and removes any seqeuence containing that number, -1 denotes show all numbers in the sequence.
* EG if ignoreNumber = 1 the list returned is :2,3,5,8,34
* EG Fibonacci Sequences as follows:1,1,2,3,5,8,13,21,34
* Once this method is complete, add a paramater allowing the list to be return in reverse (EG 8,5,3,2,1,1) or normally (1,1,2,3,5,8)
*/

public static List<int> GenerateFibonacciSequence(int numberOfSequences, int ignoreNumber)
{
List<int> sequence = new List<int>();
return sequence;

}
}``````

#### Solarion

##### Honorary Master
These were my solutions. Flame away

C#:
``````        static void Main(string[] args)
{
FixMe();

List<int> seq = GenerateFibonacciSequence(5, 1);
Console.WriteLine(string.Join<int>(",", seq));

seq = GenerateFibonacciSequence(11, 7);
Console.WriteLine(string.Join<int>(",", seq));

seq = GenerateFibonacciSequence(15, 0);
Console.WriteLine(string.Join<int>(",", seq));

}

public static List<int> GenerateFibonacciSequence(int numberOfSequences, int ignoreNumber, bool reverseSequence = false)
{
List<int> sequence = new List<int>();

int prev = -1;
int next = 1;
for (int i = 0; i < numberOfSequences; i++)
{
int sum = prev + next;
prev = next;
next = sum;

if(sum != ignoreNumber)
}

if (reverseSequence)
sequence.Reverse();

return sequence;

}

public static void FixMe()
{

int[] ints = new int[10];
int total = 0;
for (int i = 0; i < ints.Length; i++)
{
ints[i] = i + 5;
total += ints[i];
}

double numberFive = double.Parse("5,0");
string oneNewString = "NewString";

}
}``````

#### |tera|

##### Master of Messengers
[not a programmer]
What happens if you execute it in your IDE? Doesn't it show the code that is wrong?

#### Solarion

##### Honorary Master
[not a programmer]
What happens if you execute it in your IDE? Doesn't it show the code that is wrong?
Yes especially the FixMe() method, lots of issues inside there. It compiles fine with my alterations however apparently it was still wrong.

This one here had and still has me a little stumped as to what they wanted exactly. This string literal is often encountered in XML documents and is an illegal character which is usually replaced by parenthesis ""

C#:
``string 1newstring='NewString'``

#### |tera|

##### Master of Messengers
Yes especially the FixMe() method, lots of issues inside there. It compiles fine with my alterations however apparently it was still wrong.

This one here had and still has me a little stumped as to what they wanted exactly. This string literal is often encountered in XML documents and is an illegal character which is usually replaced by parenthesis ""

C#:
``string 1newstring='NewString'``
Cool. The new string name you posted is '. Not ".

#### Solarion

##### Honorary Master
Cool. The new string name you posted is '. Not ".
The program won't even compile with those characters in there just says NOPE

#### |tera|

##### Master of Messengers
The program won't even compile with those characters in there just says NOPE
I started reading from their question. In their example they show the new string in these quotes: '
I don't know if it makes a difference though?
Hopefully I'm bumping this thread for someone that can help

#### Solarion

##### Honorary Master
I started reading from their question. In their example they show the new string in these quotes: '
I don't know if it makes a difference though?
Hopefully I'm bumping this thread for someone that can help
All I know is that single quote is for character; double quote is for string.

char c = 'x';
string s = "Hello World";

To encapsulate single quotes around a string just doesn't make sense.

I could strip this out:

string oldstring = "The quick dog 'jumped' over the lazy dog";

string newstring = oldstring.Replace("'", @"""");

Reads: The quick dog "jumped" over the lazy dog

But this:

string s = 'The quick dog 'jumped' over the lazy log'

I have no idea how to escape that to double quotes.

Last edited:

#### |tera|

##### Master of Messengers
Maybe something here can help?

#### Solarion

##### Honorary Master
Thanks tera!

Looks like it was supposed to be:

string newstring = @"'NewString'"

#### |tera|

##### Master of Messengers
Thanks tera!

Looks like it was supposed to be:

string newstring = @"'NewString'"
Sweet

#### _kabal_

##### Expert Member
Doubt that ParseDouble works as expected either. Should be 5.0 not 5,0

#### [)roi(]

##### Executive Member
Doubt that ParseDouble works as expected either. Should be 5.0 not 5,0
Depends on regional settings -- System.Globalization.NumberStyles

#### C4Cat

##### Executive Member
Thanks tera!

Looks like it was supposed to be:

string newstring = @"'NewString'"
Not sure why you think you need the @ symbol? There are no escape sequences in the string

#### [)roi(]

##### Executive Member
/* QUESTION
* A method that returns a list of intergers which is the Fibonacci Sequence. (http://en.wikipedia.org/wiki/Fibonacci_number)
* Parameter @numberOfSequences denotes how many sequences is returned. DONE
* EG if numberOfSequences = 5, it should return just a list with 5 items. DONE
* Parameter @ignoreNumber is a number from 0-9 and removes any seqeuence containing that number, -1 denotes show all numbers in the sequence.
* EG if ignoreNumber = 1 the list returned is :2,3,5,8,34
* EG Fibonacci Sequences as follows:1,1,2,3,5,8,13,21,34
* Once this method is complete, add a paramater allowing the list to be return in reverse (EG 8,5,3,2,1,1) or normally (1,1,2,3,5,8)
*/
If this was their requirement, then your code is incorrect re the `ignoreNumber` logic, and your sequence needs to start at 1 instead of 0 i.e. the combinatorial instead of the classical definition.
C#:
``````namespace Test {
public static class IntExtension {
public static bool Contains(this int @this, int d) => @this.ToString().ToCharArray().Select(x => x.ToString()).Contains(d.ToString());
}

class Program {
static IEnumerable<int> FibonacciIterator(int n) {
var (f, s) = (1, 1);
for (var i = 0; i < n; i++) {
yield return f;
(f, s) = (s, f + s);
}
}

static List<int> GenerateFibonacciSequence(int numberOfSequences, int ignoreNumber, bool reverse = false) {
var lazyResult = FibonacciIterator(numberOfSequences).Where(x => !x.Contains(ignoreNumber));
return reverse ? lazyResult.Reverse().ToList() : lazyResult.ToList();
}

static void Main(string[] args) {
List<int> seq = GenerateFibonacciSequence(5, 1);
Console.WriteLine(string.Join<int>(",", seq)); // 2,3,5

seq = GenerateFibonacciSequence(11, 7);
Console.WriteLine(string.Join<int>(",", seq)); // 1,1,2,3,5,8,13,21,34,55,89

seq = GenerateFibonacciSequence(15, 0); // 1,1,2,3,5,8,13,21,34,55,89,144,233,377
Console.WriteLine(string.Join<int>(",", seq));

// reverse example
seq = GenerateFibonacciSequence(15, 1, true); // 377,233,89,55,34,8,5,3,2
Console.WriteLine(string.Join<int>(",", seq));

}
}
}``````

Last edited:

#### animal531

##### Expert Member
FYI on the strings:
Use @ as an easy escape, for example "c:\\temp\\file.txt" can become @"c:\temp\file.txt"
Also handy is the newer \$ to build strings with, for example:
C#:
``````int a = 5;
string s = \$"A's value is {a}";``````