Skip to content

Instantly share code, notes, and snippets.

@paulohenriquesn
Created February 16, 2018 16:08
Show Gist options
  • Save paulohenriquesn/6e3f572fbcc4fe2f627e2bab202061eb to your computer and use it in GitHub Desktop.
Save paulohenriquesn/6e3f572fbcc4fe2f627e2bab202061eb to your computer and use it in GitHub Desktop.
fibonacci.cs
RestartFibonacci:
{
List<int> arrayNumbers = new List<int>();
arrayNumbers.Add(0);
arrayNumbers.Add(1);
string fibonacci = String.Empty;
for (int i = 0; i < arrayNumbers.Count; i++)
{
fibonacci += arrayNumbers[i] + ",";
}
string[] splitFibonacci = fibonacci.Split(',');
int[] arrayToValues = new int[splitFibonacci.Length - 1];
for (int i = 0; i < splitFibonacci.Length; i++) { try { arrayToValues[i] = int.Parse(splitFibonacci[i]); } catch { } }
Console.WriteLine(string.Join(",", arrayToValues));
for (int b = 0; b < arrayToValues.Length; b++)
{
try
{
int value = arrayToValues[b] + arrayToValues[b + 1];
arrayNumbers.Add(value);
fibonacci = String.Empty;
goto RestartFibonacci;
}
catch { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment